[PATCH 4 of 9] branchmap: read and write key part related to filtered revision

Pierre-Yves David pierre-yves.david at ens-lyon.org
Wed Dec 26 14:33:00 CST 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1356187406 -3600
# Node ID ed03a82360c2b90195a2d4dacca205e5a705a1f2
# Parent  4b098d0339f9e8b1805c4f6ef1d8bcf59f5a6349
branchmap: read and write key part related to filtered revision

Now that we have a third part for the cache key we need to write and read it on
disk. It is only written when there is filtered revision. This keep the format
compatible with older version.

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -16,13 +16,17 @@ def read(repo):
         f.close()
     except (IOError, OSError):
         return branchcache()
 
     try:
-        last, lrev = lines.pop(0).split(" ", 1)
+        cachekey = lines.pop(0).split(" ", 2)
+        last, lrev = cachekey[:2]
         last, lrev = bin(last), int(lrev)
-        partial = branchcache(tipnode=last, tiprev=lrev)
+        filtered = None
+        if len(cachekey) > 2:
+            filtered = bin(cachekey[2])
+        partial = branchcache(tipnode=last, tiprev=lrev, filtered=filtered)
         if not partial.validfor(repo):
             # invalidate the cache
             raise ValueError('(tip differs)')
         for l in lines:
             if not l:
@@ -110,11 +114,14 @@ class branchcache(dict):
 
 
     def write(self, repo):
         try:
             f = repo.opener("cache/branchheads", "w", atomictemp=True)
-            f.write("%s %s\n" % (hex(self.tipnode), self.tiprev))
+            cachekey = [hex(self.tipnode), str(self.tiprev)]
+            if self.filtered is not None:
+                cachekey.append(hex(self.filtered))
+            f.write(" ".join(cachekey) + '\n')
             for label, nodes in self.iteritems():
                 for node in nodes:
                     f.write("%s %s\n" % (hex(node), encoding.fromlocal(label)))
             f.close()
         except (IOError, OSError):


More information about the Mercurial-devel mailing list