[PATCH 2 of 2] branchmap: Log event when branchcache is updated

Gregory Szorc gregory.szorc at gmail.com
Sat Mar 22 19:21:40 CDT 2014


# HG changeset patch
# User Gregory Szorc <gps at mozilla.com>
# Date 1395533677 25200
#      Sat Mar 22 17:14:37 2014 -0700
# Node ID f7a3e8fe9777541850d5efa41162eb2498576bf5
# Parent  4041f83efd1de680c82b65c776f85b642a59754a
branchmap: Log event when branchcache is updated

The blackblox log will now contain log events when the branch caches are
updated.

Since the various branch caches update with a recursive call to
updatecache(), the reported timings may not be completely accurate.

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -3,16 +3,17 @@
 # Copyright 2005-2007 Matt Mackall <mpm at selenic.com>
 #
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
 from node import bin, hex, nullid, nullrev
 import encoding
 import util
+import time
 
 def _filename(repo):
     """name of a branchcache file for a given repo or repoview"""
     filename = "cache/branch2"
     if repo.filtername:
         filename = '%s-%s' % (filename, repo.filtername)
     return filename
 
@@ -70,16 +71,17 @@ def read(repo):
 # This create and ordering used for branchmap purpose.
 # the ordering may be partial
 subsettable = {None: 'visible',
                'visible': 'served',
                'served': 'immutable',
                'immutable': 'base'}
 
 def updatecache(repo):
+    starttime = time.time()
     cl = repo.changelog
     filtername = repo.filtername
     partial = repo._branchcaches.get(filtername)
 
     revs = []
     if partial is None or not partial.validfor(repo):
         partial = read(repo)
         if partial is None:
@@ -92,16 +94,18 @@ def updatecache(repo):
                 extrarevs = subset.changelog.filteredrevs - cl.filteredrevs
                 revs.extend(r for  r in extrarevs if r <= partial.tiprev)
     revs.extend(cl.revs(start=partial.tiprev + 1))
     if revs:
         partial.update(repo, revs)
         partial.write(repo)
     assert partial.validfor(repo), filtername
     repo._branchcaches[repo.filtername] = partial
+    duration = time.time() - starttime
+    repo.ui.log('cache', 'Updated %s branch cache in %0.2f seconds\n')
 
 class branchcache(dict):
     """A dict like object that hold branches heads cache.
 
     This cache is used to avoid costly computations to determine all the
     branch heads of a repo.
 
     The cache is serialized on disk in the following format:


More information about the Mercurial-devel mailing list