layout.conf: allow a repository to state the cache is authorative
authorBrian Harring <ferringb@chromium.org>
Fri, 30 Sep 2011 09:37:04 +0000 (02:37 -0700)
committerZac Medico <zmedico@gentoo.org>
Fri, 30 Sep 2011 17:32:34 +0000 (10:32 -0700)
By authorative, this means "the cache is accurate; skip validation".  While
a useful hint for a slight speedup in validation, the true gain is for
repositories that are distributed in a fashion that doesn't preserve mtime;
git primarily.  Setting authorative-cache = true results in portage
skipping mtime validation checks for the bundled cache, allowing
for git vcs based repos to distribute a cache.

BUG=chromium-os:21049
TEST=dump a cache into metadata/cache, touch it to now, set layout.conf
     to authorative-cache=true, verify it doesn't generate cache entries
     for that repo.

Change-Id: I92423e679bc171d2411a18d6d3ac22e8ef457753

pym/portage/cache/template.py
pym/portage/dbapi/porttree.py
pym/portage/repository/config.py

index f84d8f4b93d8aecc1041838c549e5102f2db51b9..4cb27bff98a33ca2cf53dee12593c0b7007a4f6e 100644 (file)
@@ -30,6 +30,7 @@ class database(object):
                self.readonly = readonly
                self.sync_rate = 0
                self.updates = 0
+               self.is_authorative = False
        
        def __getitem__(self, cpv):
                """set a cpv to values
index e679f000c4d6a4fd17bde970a98180a799ea581b..ab38247271042a0a7386e1167de9498a7b0c7b0f 100644 (file)
@@ -215,10 +215,12 @@ class portdbapi(dbapi):
                                if x in self._pregen_auxdb:
                                        continue
                                if os.path.isdir(os.path.join(x, "metadata", "cache")):
-                                       self._pregen_auxdb[x] = self.metadbmodule(
+                                       conf = self.repositories.get_repo_for_location(x)
+                                       cache = self._pregen_auxdb[x] = self.metadbmodule(
                                                x, "metadata/cache", filtered_auxdbkeys, readonly=True)
+                                       cache.is_authorative = conf.cache_is_authorative
                                        try:
-                                               self._pregen_auxdb[x].ec = self._repo_info[x].eclass_db
+                                               cache.ec = self._repo_info[x].eclass_db
                                        except AttributeError:
                                                pass
                # Selectively cache metadata in order to optimize dep matching.
@@ -441,10 +443,11 @@ class portdbapi(dbapi):
                                eapi = metadata.get('EAPI', '').strip()
                                if not eapi:
                                        eapi = '0'
-                               if not (eapi[:1] == '-' and eapi_is_supported(eapi[1:])) and \
-                                       emtime == metadata['_mtime_'] and \
-                                       eclass_db.is_eclass_data_valid(metadata['_eclasses_']):
-                                       doregen = False
+                               if not (eapi[:1] == '-' and eapi_is_supported(eapi[1:])):
+                                       if auxdb.is_authorative or ( \
+                                               emtime == metadata['_mtime_'] and \
+                                               eclass_db.is_eclass_data_valid(metadata['_eclasses_'])):
+                                               doregen = False
 
                        if not doregen:
                                break
index 3cb550152d1f0551a1aa2ba8728b967f5787dd46..6924450134c6f59e7002648a69f88ac9dac27be3 100644 (file)
@@ -43,7 +43,7 @@ class RepoConfig(object):
 
        __slots__ = ['aliases', 'eclass_overrides', 'eclass_locations', 'location', 'user_location', 'masters', 'main_repo',
                'missing_repo_name', 'name', 'priority', 'sync', 'format', 'sign_manifest', 'thin_manifest',
-               'allow_missing_manifest', 'create_manifest', 'disable_manifest']
+               'allow_missing_manifest', 'create_manifest', 'disable_manifest', 'cache_is_authorative']
 
        def __init__(self, name, repo_opts):
                """Build a RepoConfig with options in repo_opts
@@ -117,6 +117,7 @@ class RepoConfig(object):
                self.allow_missing_manifest = False
                self.create_manifest = True
                self.disable_manifest = False
+               self.cache_is_authorative = False
 
        def load_manifest(self, *args, **kwds):
                kwds['thin'] = self.thin_manifest
@@ -357,6 +358,7 @@ class RepoConfigLoader(object):
                        repo.allow_missing_manifest = manifest_policy != 'strict'
                        repo.create_manifest = manifest_policy != 'false'
                        repo.disable_manifest = manifest_policy == 'false'
+                       repo.cache_is_authorative = layout_data.get('authorative-cache', 'false').lower() == 'true'
 
                #Take aliases into account.
                new_prepos = {}