Make post_emerge() exit early if it detects that the vdb state hasn't changed. v2.2_rc14
authorZac Medico <zmedico@gentoo.org>
Tue, 11 Nov 2008 19:59:49 +0000 (19:59 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 11 Nov 2008 19:59:49 +0000 (19:59 -0000)
This works by comparing a hash of the COUNTER values for all packages in the
vdb.

svn path=/main/trunk/; revision=11859

pym/_emerge/__init__.py
pym/portage/__init__.py
pym/portage/dbapi/vartree.py

index c5084ac7b663756f506e6506726839e434e59c68..14a63a49254cb4c3acb02b384b78f2aa50459802 100644 (file)
@@ -11236,6 +11236,12 @@ def post_emerge(root_config, myopts, mtimedb, retval):
 
        _flush_elog_mod_echo()
 
+       counter_hash = settings.get("PORTAGE_COUNTER_HASH")
+       if counter_hash is not None and \
+               counter_hash == vardbapi._counter_hash():
+               # If vdb state has not changed then there's nothing else to do.
+               sys.exit(retval)
+
        vdb_path = os.path.join(target_root, portage.VDB_PATH)
        portage.util.ensure_dirs(vdb_path)
        vdb_lock = None
@@ -13830,6 +13836,9 @@ def emerge_main():
                mysettings =  trees[myroot]["vartree"].settings
                mysettings.unlock()
                adjust_config(myopts, mysettings)
+               mysettings["PORTAGE_COUNTER_HASH"] = \
+                       trees[myroot]["vartree"].dbapi._counter_hash()
+               mysettings.backup_changes("PORTAGE_COUNTER_HASH")
                mysettings.lock()
                del myroot, mysettings
 
index 485a2d426ba9dc69a94c114697908444e3146c24..8c8c99ebc19725a9c5aa47d5360e2a173bb60134 100644 (file)
@@ -1002,6 +1002,7 @@ class config(object):
                "GENTOO_MIRRORS", "NOCONFMEM", "O",
                "PORTAGE_BACKGROUND",
                "PORTAGE_BINHOST_CHUNKSIZE", "PORTAGE_CALLER",
+               "PORTAGE_COUNTER_HASH",
                "PORTAGE_ECLASS_WARNING_ENABLE", "PORTAGE_ELOG_CLASSES",
                "PORTAGE_ELOG_MAILFROM", "PORTAGE_ELOG_MAILSUBJECT",
                "PORTAGE_ELOG_MAILURI", "PORTAGE_ELOG_SYSTEM",
index 1d5c8fe262d649d536583dba7f4432eca6d715d8..c3628491dd616dbe1f0e3c7f03de4e21c20bf577 100644 (file)
@@ -773,6 +773,21 @@ class vardbapi(dbapi):
                        level=logging.ERROR, noiselevel=-1)
                return 0
 
+       def _counter_hash(self):
+               try:
+                       from hashlib import md5 as new_hash
+               except ImportError:
+                       from md5 import new as new_hash
+               h = new_hash()
+               aux_keys = ["COUNTER"]
+               for cpv in self.cpv_all():
+                       try:
+                               counter, = self.aux_get(cpv, aux_keys)
+                       except KeyError:
+                               continue
+                       h.update(counter)
+               return h.hexdigest()
+
        def cpv_inject(self, mycpv):
                "injects a real package into our on-disk database; assumes mycpv is valid and doesn't already exist"
                os.makedirs(self.getpath(mycpv))
@@ -916,6 +931,7 @@ class vardbapi(dbapi):
                                        self.invalidentry(self.getpath(subpath))
                                        continue
                                returnme.append(subpath)
+               returnme.sort()
                return returnme
 
        def cp_all(self, use_cache=1):