[PATCH 3 of 5 v6] branchmap: use branchcache for updating branch map

Mads Kiilerich mads at kiilerich.com
Sat Oct 18 13:43:35 CDT 2014


# HG changeset patch
# User Mads Kiilerich <madski at unity3d.com>
# Date 1413657731 -7200
#      Sat Oct 18 20:42:11 2014 +0200
# Node ID 0ea7f28d7f1a2625d9729f482cbc62e30e4c5626
# Parent  dd89e376f28eaad38c3c5e18bc0daff3c416a0be
branchmap: use branchcache for updating branch map

The branch cache is saved immediately after computing the branchmap. That might
increase the likelyhood that other process will pick it up and find what they
need.

FWIW, this use will also make sure branchcache "always" is fully updated. The
few cases where the branchcache is out of sync could fall back to not use the
cache.

It might thus be less relevant to save the cache when the repo objects is
closed. The cache could perhaps also be saved when the branchmap is written.

perfbranchmap base on mozilla-central:
Before:
! wall 6.503575 comb 6.500000 user 6.470000 sys 0.030000 (best of 3)
After:
! wall 0.986499 comb 0.990000 user 0.990000 sys 0.000000 (best of 10)

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -234,12 +234,14 @@ class branchcache(dict):
         cl = repo.changelog
         # collect new branch entries
         newbranches = {}
-        getbranchinfo = cl.branchinfo
+        repo.revbranchcache.load()
+        getbranchinfo = repo.revbranchcache.branchinfo
         for r in revgen:
             branch, closesbranch = getbranchinfo(r)
             newbranches.setdefault(branch, []).append(r)
             if closesbranch:
                 self._closednodes.add(cl.node(r))
+        repo.revbranchcache.save()
 
         # fetch current topological heads to speed up filtering
         topoheads = set(cl.headrevs())
diff --git a/mercurial/statichttprepo.py b/mercurial/statichttprepo.py
--- a/mercurial/statichttprepo.py
+++ b/mercurial/statichttprepo.py
@@ -91,6 +91,8 @@ class statichttppeer(localrepo.localpeer
         return False
 
 class _fakerevbranchcache(object):
+    def __init__(self, repo):
+        self.branchinfo = repo.changelog.branchinfo
     def load(self):
         pass
     def save(self):
diff --git a/tests/test-branches.t b/tests/test-branches.t
--- a/tests/test-branches.t
+++ b/tests/test-branches.t
@@ -536,10 +536,10 @@ recovery from other corruption - extra t
   7
   $ "$TESTDIR/md5sum.py" .hg/cache/branchnames
   b90894765458b0298f0c822fb5193c1e  .hg/cache/branchnames
-lazy update after commit
+immediate update after commit, because branchmap update
   $ hg tag tag
   $ "$TESTDIR/md5sum.py" .hg/cache/branchnames
-  b90894765458b0298f0c822fb5193c1e  .hg/cache/branchnames
+  807c628e9f3f9040cc1da7124c4cb2d8  .hg/cache/branchnames
   $ hg debugrevspec 'branch("re:a ")'
   7
   $ "$TESTDIR/md5sum.py" .hg/cache/branchnames
diff --git a/tests/test-clone.t b/tests/test-clone.t
--- a/tests/test-clone.t
+++ b/tests/test-clone.t
@@ -31,6 +31,7 @@ Trigger branchcache creation:
   default                       10:a7949464abda
   $ ls .hg/cache
   branch2-served
+  branchnames
 
 Default operation:
 
diff --git a/tests/test-fncache.t b/tests/test-fncache.t
--- a/tests/test-fncache.t
+++ b/tests/test-fncache.t
@@ -71,6 +71,7 @@ Non store repo:
   .hg/00manifest.i
   .hg/cache
   .hg/cache/branch2-served
+  .hg/cache/branchnames
   .hg/data
   .hg/data/tst.d.hg
   .hg/data/tst.d.hg/foo.i
@@ -99,6 +100,7 @@ Non fncache repo:
   .hg/00changelog.i
   .hg/cache
   .hg/cache/branch2-served
+  .hg/cache/branchnames
   .hg/dirstate
   .hg/last-message.txt
   .hg/requires
diff --git a/tests/test-hardlinks.t b/tests/test-hardlinks.t
--- a/tests/test-hardlinks.t
+++ b/tests/test-hardlinks.t
@@ -196,6 +196,7 @@ r4 has hardlinks in the working dir (not
   2 r4/.hg/00changelog.i
   2 r4/.hg/branch
   2 r4/.hg/cache/branch2-served
+  2 r4/.hg/cache/branchnames
   2 r4/.hg/dirstate
   2 r4/.hg/hgrc
   2 r4/.hg/last-message.txt
@@ -226,6 +227,7 @@ Update back to revision 11 in r4 should 
   2 r4/.hg/00changelog.i
   1 r4/.hg/branch
   2 r4/.hg/cache/branch2-served
+  2 r4/.hg/cache/branchnames
   1 r4/.hg/dirstate
   2 r4/.hg/hgrc
   2 r4/.hg/last-message.txt
diff --git a/tests/test-inherit-mode.t b/tests/test-inherit-mode.t
--- a/tests/test-inherit-mode.t
+++ b/tests/test-inherit-mode.t
@@ -66,6 +66,7 @@ new directories are setgid
   00600 ./.hg/00changelog.i
   00770 ./.hg/cache/
   00660 ./.hg/cache/branch2-served
+  00660 ./.hg/cache/branchnames
   00660 ./.hg/dirstate
   00660 ./.hg/last-message.txt
   00600 ./.hg/requires
@@ -111,6 +112,7 @@ group can still write everything
   00660 ../push/.hg/00changelog.i
   00770 ../push/.hg/cache/
   00660 ../push/.hg/cache/branch2-base
+  00660 ../push/.hg/cache/branchnames
   00660 ../push/.hg/requires
   00770 ../push/.hg/store/
   00660 ../push/.hg/store/00changelog.i


More information about the Mercurial-devel mailing list