aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-11-30 23:46:33 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-11-30 23:46:33 +0000
commit4f647bca851ca6e306ee420706d8b29a1712a79b (patch)
tree24a982f7767943e1fc6ac7ef0d4fd668cb8142d5
parentd2efb088f0952c21b9570be5f3356de044a2c3e7 (diff)
downloadpaludis-4f647bca851ca6e306ee420706d8b29a1712a79b.tar.gz
paludis-4f647bca851ca6e306ee420706d8b29a1712a79b.tar.xz
Add names cache to Portage repositories
-rw-r--r--paludis/repositories/portage/make_ebuild_repository.cc10
-rw-r--r--paludis/repositories/portage/portage_repository.cc122
-rw-r--r--paludis/repositories/portage/portage_repository.hh4
-rw-r--r--paludis/repositories/portage/portage_repository_params.sr1
-rw-r--r--paludis/repositories/vdb/vdb_repository.cc12
-rw-r--r--paludis/util/iterator.hh4
6 files changed, 145 insertions, 8 deletions
diff --git a/paludis/repositories/portage/make_ebuild_repository.cc b/paludis/repositories/portage/make_ebuild_repository.cc
index efae0e1..5a9f4ab 100644
--- a/paludis/repositories/portage/make_ebuild_repository.cc
+++ b/paludis/repositories/portage/make_ebuild_repository.cc
@@ -102,6 +102,15 @@ paludis::make_ebuild_repository(
if (m->end() == m->find("write_cache") || ((write_cache = m->find("write_cache")->second)).empty())
write_cache = "/var/empty";
+ std::string names_cache;
+ if (m->end() == m->find("names_cache") || ((names_cache = m->find("names_cache")->second)).empty())
+ {
+ Log::get_instance()->message(ll_warning, lc_no_context, "The names_cache key is not set in '"
+ + repo_file + "'. You should read http://paludis.berlios.de/CacheFiles.html and select an "
+ "appropriate value.");
+ names_cache = "/var/empty";
+ }
+
std::string sync;
if (m->end() != m->find("sync"))
sync = m->find("sync")->second;
@@ -126,6 +135,7 @@ paludis::make_ebuild_repository(
.profiles(profiles)
.cache(cache)
.write_cache(write_cache)
+ .names_cache(names_cache)
.eclassdirs(eclassdirs)
.distdir(distdir)
.pkgdir(FSEntry("/var/empty"))
diff --git a/paludis/repositories/portage/portage_repository.cc b/paludis/repositories/portage/portage_repository.cc
index ff438d4..87df970 100644
--- a/paludis/repositories/portage/portage_repository.cc
+++ b/paludis/repositories/portage/portage_repository.cc
@@ -93,6 +93,9 @@ namespace paludis
/// Map for virtuals.
typedef MakeHashedMap<QualifiedPackageName, PackageDepAtom::ConstPointer>::Type VirtualsMap;
+ /// Map for name caches.
+ typedef MakeHashedMultiMap<PackageNamePart, CategoryNamePart>::Type NameCacheMap;
+
/**
* Implementation data for a PortageRepository.
*
@@ -173,6 +176,15 @@ namespace paludis
/// Have we loaded our virtuals?
bool has_our_virtuals;
+ /// Name cache map
+ mutable NameCacheMap name_cache_map;
+
+ /// Have we loaded our name cache map?
+ mutable bool has_name_cache_map;
+
+ /// Can we use our name cache map?
+ mutable bool can_use_name_cache_map;
+
PortageRepository * const repo;
};
@@ -190,6 +202,8 @@ namespace paludis
entries_ptr(PortageRepositoryEntriesMaker::get_instance()->find_maker(
params.entry_format)(params.environment, r, p)),
has_our_virtuals(false),
+ has_name_cache_map(false),
+ can_use_name_cache_map(true),
repo(r)
{
}
@@ -255,6 +269,7 @@ PortageRepository::PortageRepository(const PortageRepositoryParams & p) :
_imp->params.eclassdirs->end(), " "));
config_info->add_kv("cache", stringify(_imp->params.cache));
config_info->add_kv("write_cache", stringify(_imp->params.write_cache));
+ config_info->add_kv("names_cache", stringify(_imp->params.names_cache));
config_info->add_kv("distdir", stringify(_imp->params.distdir));
config_info->add_kv("pkgdir", stringify(_imp->params.pkgdir));
config_info->add_kv("securitydir", stringify(_imp->params.securitydir));
@@ -1006,3 +1021,110 @@ PortageRepository::do_use_expand_value(const UseFlagName & u) const
throw InternalError(PALUDIS_HERE, "Not a use expand name: '" + stringify(u) + "'");
}
+void
+PortageRepository::regenerate_cache() const
+{
+ if (_imp->params.names_cache == FSEntry("/var/empty"))
+ return;
+
+ Context context("When generating Portage repository names cache at '"
+ + stringify(_imp->params.names_cache) + "':");
+
+ FSEntry(_imp->params.names_cache).unlink();
+ _imp->params.names_cache.dirname().mkdir();
+
+ std::ofstream f(stringify(_imp->params.names_cache).c_str());
+ if (! f)
+ {
+ Log::get_instance()->message(ll_warning, lc_context, "Cannot write to '"
+ + stringify(_imp->params.names_cache) + "'");
+ return;
+ }
+
+ f << "paludis-1" << std::endl;
+
+ NameCacheMap m;
+
+ CategoryNamePartCollection::ConstPointer cats(category_names());
+ for (CategoryNamePartCollection::Iterator c(cats->begin()), c_end(cats->end()) ;
+ c != c_end ; ++c)
+ {
+ QualifiedPackageNameCollection::ConstPointer pkgs(package_names(*c));
+ for (QualifiedPackageNameCollection::Iterator p(pkgs->begin()), p_end(pkgs->end()) ;
+ p != p_end ; ++p)
+ m.insert(std::make_pair(p->package, *c));
+ }
+
+ PackageNamePart old_p("not-a-package");
+ for (NameCacheMap::const_iterator e(m.begin()), e_end(m.end()) ;
+ e != e_end ; ++e)
+ {
+ if (e->first != old_p)
+ {
+ f << std::endl << e->first;
+ old_p = e->first;
+ }
+
+ f << " " << e->second;
+ }
+ f << std::endl;
+}
+
+CategoryNamePartCollection::ConstPointer
+PortageRepository::do_category_names_containing_package(const PackageNamePart & p) const
+{
+ if (_imp->params.names_cache == FSEntry("/var/empty") || ! _imp->can_use_name_cache_map)
+ return Repository::do_category_names_containing_package(p);
+
+ if (! _imp->has_name_cache_map)
+ {
+ Context context("When finding category names containing a package using '" +
+ stringify(_imp->params.names_cache) + "':");
+
+ if (! _imp->params.names_cache.is_regular_file())
+ {
+ Log::get_instance()->message(ll_warning, lc_no_context, "Provides cache at '"
+ + stringify(_imp->params.names_cache) + "' is not a regular file.");
+ _imp->can_use_name_cache_map = false;
+ return Repository::do_category_names_containing_package(p);
+ }
+
+ std::ifstream names_cache(stringify(_imp->params.names_cache).c_str());
+
+ std::string version;
+ std::getline(names_cache, version);
+
+ if (version != "paludis-1")
+ {
+ Log::get_instance()->message(ll_warning, lc_no_context, "Can't use names cache at '"
+ + stringify(_imp->params.names_cache) + "' because format '" + version + "' is not 'paludis-1'");
+ return Repository::do_category_names_containing_package(p);
+ }
+
+ std::string line;
+ while (std::getline(names_cache, line))
+ {
+ if (line.empty())
+ continue;
+
+ std::vector<std::string> tokens;
+ WhitespaceTokeniser::get_instance()->tokenise(line, std::back_inserter(tokens));
+ if (tokens.size() < 2)
+ continue;
+
+ for (std::vector<std::string>::const_iterator i(next(tokens.begin())), i_end(tokens.end()) ;
+ i != i_end ; ++i)
+ _imp->name_cache_map.insert(std::make_pair(PackageNamePart(tokens.at(0)),
+ CategoryNamePart(*i)));
+ }
+ _imp->has_name_cache_map = true;
+ }
+
+ CategoryNamePartCollection::Pointer result(new CategoryNamePartCollection::Concrete);
+ std::pair<NameCacheMap::const_iterator, NameCacheMap::const_iterator> r(
+ _imp->name_cache_map.equal_range(p));
+ std::copy(r.first, r.second, transform_inserter(result->inserter(),
+ SelectSecond<PackageNamePart, CategoryNamePart>()));
+ return result;
+}
+
diff --git a/paludis/repositories/portage/portage_repository.hh b/paludis/repositories/portage/portage_repository.hh
index e10234e..470e545 100644
--- a/paludis/repositories/portage/portage_repository.hh
+++ b/paludis/repositories/portage/portage_repository.hh
@@ -77,6 +77,9 @@ namespace paludis
virtual CategoryNamePartCollection::ConstPointer do_category_names() const;
+ CategoryNamePartCollection::ConstPointer do_category_names_containing_package(
+ const PackageNamePart & p) const;
+
virtual QualifiedPackageNameCollection::ConstPointer do_package_names(
const CategoryNamePart &) const;
@@ -139,6 +142,7 @@ namespace paludis
~PortageRepository();
virtual void invalidate() const;
+ virtual void regenerate_cache() const;
virtual void update_news() const;
diff --git a/paludis/repositories/portage/portage_repository_params.sr b/paludis/repositories/portage/portage_repository_params.sr
index 75ca948..993c4ea 100644
--- a/paludis/repositories/portage/portage_repository_params.sr
+++ b/paludis/repositories/portage/portage_repository_params.sr
@@ -10,6 +10,7 @@ make_class_PortageRepositoryParams()
key profiles FSEntryCollection::ConstPointer
key cache FSEntry
key write_cache FSEntry
+ key names_cache FSEntry
key distdir FSEntry
key pkgdir FSEntry
key eclassdirs FSEntryCollection::ConstPointer
diff --git a/paludis/repositories/vdb/vdb_repository.cc b/paludis/repositories/vdb/vdb_repository.cc
index 21a029d..7b647c6 100644
--- a/paludis/repositories/vdb/vdb_repository.cc
+++ b/paludis/repositories/vdb/vdb_repository.cc
@@ -472,6 +472,7 @@ VDBRepository::VDBRepository(const VDBRepositoryParams & p) :
config_info->add_kv("root", stringify(_imp->root));
config_info->add_kv("format", "vdb");
config_info->add_kv("world", stringify(_imp->world_file));
+ config_info->add_kv("world", stringify(_imp->provides_cache));
config_info->add_kv("buildroot", stringify(_imp->buildroot));
_info->add_section(config_info);
@@ -1192,12 +1193,10 @@ VDBRepository::load_provided_using_cache() const
return false;
}
- LineConfigFile provides_cache(_imp->provides_cache);
- LineConfigFile::Iterator line(provides_cache.begin()), line_end(provides_cache.end());
+ std::ifstream provides_cache(stringify(_imp->provides_cache).c_str());
std::string version;
- if (line != line_end)
- version = *line++;
+ std::getline(provides_cache, version);
if (version != "paludis-1")
{
@@ -1206,10 +1205,11 @@ VDBRepository::load_provided_using_cache() const
return false;
}
- while (line != line_end)
+ std::string line;
+ while (std::getline(provides_cache, line))
{
std::vector<std::string> tokens;
- WhitespaceTokeniser::get_instance()->tokenise(*line++, std::back_inserter(tokens));
+ WhitespaceTokeniser::get_instance()->tokenise(line, std::back_inserter(tokens));
if (tokens.size() < 3)
continue;
diff --git a/paludis/util/iterator.hh b/paludis/util/iterator.hh
index 1a20383..7d11ed6 100644
--- a/paludis/util/iterator.hh
+++ b/paludis/util/iterator.hh
@@ -404,10 +404,10 @@ namespace paludis
*/
template <typename A_, typename B_>
struct SelectSecond :
- std::unary_function<A_, std::pair<A_, B_> >
+ std::unary_function<B_, std::pair<A_, B_> >
{
/// Carry out the selection.
- A_ operator() (const std::pair<A_, B_> & p) const
+ B_ operator() (const std::pair<A_, B_> & p) const
{
return p.second;
}