aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-09-21 17:39:18 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-09-21 17:39:18 +0000
commitcdf6d749ed3d1aea5085d32b04450233f36986ba (patch)
treeb08a1412f9104e789cf6f7f29d26e5d29f5dc81f
parent045aa2034ad606b1850716c7cc25d85b3e6d3cae (diff)
downloadpaludis-cdf6d749ed3d1aea5085d32b04450233f36986ba.tar.gz
paludis-cdf6d749ed3d1aea5085d32b04450233f36986ba.tar.xz
Don't create multiple identical ::virtuals entries
-rw-r--r--paludis/repositories/virtuals/virtuals_repository.cc28
-rw-r--r--paludis/repositories/virtuals/virtuals_repository_TEST.cc37
2 files changed, 59 insertions, 6 deletions
diff --git a/paludis/repositories/virtuals/virtuals_repository.cc b/paludis/repositories/virtuals/virtuals_repository.cc
index 96a70de..b41e579 100644
--- a/paludis/repositories/virtuals/virtuals_repository.cc
+++ b/paludis/repositories/virtuals/virtuals_repository.cc
@@ -76,23 +76,37 @@ namespace paludis
namespace
{
- struct NamesCategoryComparator
+ struct NamesNameComparator
{
bool
operator() (const std::pair<QualifiedPackageName, tr1::shared_ptr<const PackageDepSpec> > & a,
const std::pair<QualifiedPackageName, tr1::shared_ptr<const PackageDepSpec> > & b) const
{
- return a.first.category < b.first.category;
+ return a.first < b.first;
}
};
- struct NamesNameComparator
+ struct NamesSortComparator
{
bool
operator() (const std::pair<QualifiedPackageName, tr1::shared_ptr<const PackageDepSpec> > & a,
const std::pair<QualifiedPackageName, tr1::shared_ptr<const PackageDepSpec> > & b) const
{
- return a.first < b.first;
+ if (a.first < b.first)
+ return true;
+ if (a.first > b.first)
+ return false;
+ return stringify(*a.second) < stringify(*b.second);
+ }
+ };
+
+ struct NamesUniqueComparator
+ {
+ bool
+ operator() (const std::pair<QualifiedPackageName, tr1::shared_ptr<const PackageDepSpec> > & a,
+ const std::pair<QualifiedPackageName, tr1::shared_ptr<const PackageDepSpec> > & b) const
+ {
+ return a.first == b.first && stringify(*a.second) == stringify(*b.second);
}
};
}
@@ -156,7 +170,8 @@ VirtualsRepository::need_names() const
tr1::shared_ptr<QualifiedPackageName>(new QualifiedPackageName(p->provided_by->name()))))));
}
- std::sort(_imp->names.begin(), _imp->names.end(), NamesNameComparator());
+ std::sort(_imp->names.begin(), _imp->names.end(), NamesSortComparator());
+ _imp->names.erase(std::unique(_imp->names.begin(), _imp->names.end(), NamesUniqueComparator()), _imp->names.end());
std::vector<std::pair<QualifiedPackageName, tr1::shared_ptr<const PackageDepSpec> > > new_names;
@@ -184,7 +199,8 @@ VirtualsRepository::need_names() const
}
std::copy(new_names.begin(), new_names.end(), std::back_inserter(_imp->names));
- std::sort(_imp->names.begin(), _imp->names.end(), NamesNameComparator());
+ std::sort(_imp->names.begin(), _imp->names.end(), NamesSortComparator());
+ _imp->names.erase(std::unique(_imp->names.begin(), _imp->names.end(), NamesUniqueComparator()), _imp->names.end());
_imp->has_names = true;
}
diff --git a/paludis/repositories/virtuals/virtuals_repository_TEST.cc b/paludis/repositories/virtuals/virtuals_repository_TEST.cc
index 3d3b1c3..d04c793 100644
--- a/paludis/repositories/virtuals/virtuals_repository_TEST.cc
+++ b/paludis/repositories/virtuals/virtuals_repository_TEST.cc
@@ -69,5 +69,42 @@ namespace test_cases
"cat/pkg-1:0::repo | cat/pkg-2:0::repo | virtual/pkg-2::virtuals (virtual for cat/pkg-2:0::repo)");
}
} test_virtuals_repository;
+
+ struct VirtualsRepositoryDuplicatesTest : TestCase
+ {
+ VirtualsRepositoryDuplicatesTest() : TestCase("virtuals repository duplicates") { }
+
+ void run()
+ {
+ TestEnvironment env;
+ tr1::shared_ptr<VirtualsRepository> virtuals(new VirtualsRepository(&env));
+ tr1::shared_ptr<FakeRepository> repo1(new FakeRepository(&env, RepositoryName("repo1")));
+ tr1::shared_ptr<FakeRepository> repo2(new FakeRepository(&env, RepositoryName("repo2")));
+ tr1::shared_ptr<FakeInstalledRepository> installed(new FakeInstalledRepository(&env, RepositoryName("installed")));
+
+ env.package_database()->add_repository(2, virtuals);
+ env.package_database()->add_repository(3, repo1);
+ env.package_database()->add_repository(4, repo2);
+ env.package_database()->add_repository(5, installed);
+
+ repo1->add_version("cat", "pkg", "1")->provide_key()->set_from_string("virtual/pkg");
+ repo1->add_version("cat", "pkg", "2")->provide_key()->set_from_string("virtual/pkg");
+ repo1->add_virtual_package(QualifiedPackageName("virtual/pkg"), make_shared_ptr(new PackageDepSpec(">=cat/pkg-2", pds_pm_permissive)));
+ repo1->add_virtual_package(QualifiedPackageName("virtual/foo"), make_shared_ptr(new PackageDepSpec(">=cat/pkg-2", pds_pm_permissive)));
+
+ repo2->add_virtual_package(QualifiedPackageName("virtual/pkg"), make_shared_ptr(new PackageDepSpec(">=cat/pkg-2", pds_pm_permissive)));
+ repo2->add_virtual_package(QualifiedPackageName("virtual/foo"), make_shared_ptr(new PackageDepSpec("<=cat/pkg-1", pds_pm_permissive)));
+
+ TEST_CHECK(virtuals->has_category_named(CategoryNamePart("virtual")));
+ TEST_CHECK(virtuals->has_package_named(QualifiedPackageName("virtual/pkg")));
+
+ tr1::shared_ptr<const PackageIDSequence> r(env.package_database()->query(query::All(), qo_order_by_version));
+ TEST_CHECK_STRINGIFY_EQUAL(join(indirect_iterator(r->begin()), indirect_iterator(r->end()), " | "),
+ "cat/pkg-1:0::repo1 | cat/pkg-2:0::repo1 | "
+ "virtual/foo-1::virtuals (virtual for cat/pkg-1:0::repo1) | "
+ "virtual/foo-2::virtuals (virtual for cat/pkg-2:0::repo1) | "
+ "virtual/pkg-2::virtuals (virtual for cat/pkg-2:0::repo1)");
+ }
+ } test_virtuals_repository_duplicates;
}