mercurial/localrepo.py
changeset 4181 ac9e891f2c0f
parent 4166 c0271aba6abe
parent 4168 bbfe5a3fc80c
child 4182 ba51a8225a60
--- a/mercurial/localrepo.py	Thu Mar 08 20:08:24 2007 -0300
+++ b/mercurial/localrepo.py	Fri Mar 09 20:08:13 2007 +0100
@@ -15,6 +15,7 @@
 class localrepository(repo.repository):
     capabilities = ('lookup', 'changegroupsubset')
     supported = ('revlogv1', 'store')
+    branchcache_features = ('unnamed',)
 
     def __del__(self):
         self.transhandle = None
@@ -397,7 +398,23 @@
             f = self.opener("branches.cache")
             lines = f.read().split('\n')
             f.close()
-            last, lrev = lines.pop(0).rstrip().split(" ", 1)
+            features = lines.pop(0).strip()
+            if not features.startswith('features: '):
+                raise ValueError(_('branch cache: no features specified'))
+            features = features.split(' ', 1)[1].split()
+            missing_features = []
+            for feature in self.branchcache_features:
+                try:
+                    features.remove(feature)
+                except ValueError, inst:
+                    missing_features.append(feature)
+            if missing_features:
+                raise ValueError(_('branch cache: missing features: %s')
+                                 % ', '.join(missing_features))
+            if features:
+                raise ValueError(_('branch cache: unknown features: %s')
+                                 % ', '.join(features))
+            last, lrev = lines.pop(0).split(" ", 1)
             last, lrev = bin(last), int(lrev)
             if not (lrev < self.changelog.count() and
                     self.changelog.node(lrev) == last): # sanity check
@@ -405,8 +422,8 @@
                 raise ValueError('Invalid branch cache: unknown tip')
             for l in lines:
                 if not l: continue
-                node, label = l.rstrip().split(" ", 1)
-                partial[label] = bin(node)
+                node, label = l.split(" ", 1)
+                partial[label.strip()] = bin(node)
         except (KeyboardInterrupt, util.SignalInterrupt):
             raise
         except Exception, inst:
@@ -418,6 +435,7 @@
     def _writebranchcache(self, branches, tip, tiprev):
         try:
             f = self.opener("branches.cache", "w")
+            f.write(" features: %s\n" % ' '.join(self.branchcache_features))
             f.write("%s %s\n" % (hex(tip), tiprev))
             for label, node in branches.iteritems():
                 f.write("%s %s\n" % (hex(node), label))
@@ -428,8 +446,7 @@
         for r in xrange(start, end):
             c = self.changectx(r)
             b = c.branch()
-            if b:
-                partial[b] = c.node()
+            partial[b] = c.node()
 
     def lookup(self, key):
         if key == '.':