Ignore all errors while parsing the branch cache.
authorAlexis S. L. Carvalho <alexis@cecm.usp.br>
Sat, 02 Dec 2006 03:38:55 -0200
changeset 3761 9433bdcaa9ae
parent 3760 aeafd80c1e78
child 3762 b9d3e12da485
Ignore all errors while parsing the branch cache.
mercurial/localrepo.py
tests/test-newbranch
tests/test-newbranch.out
--- a/mercurial/localrepo.py	Sat Dec 02 03:16:17 2006 -0200
+++ b/mercurial/localrepo.py	Sat Dec 02 03:38:55 2006 -0200
@@ -327,16 +327,20 @@
             f.close()
             last, lrev = lines.pop(0).rstrip().split(" ", 1)
             last, lrev = bin(last), int(lrev)
-            if (lrev < self.changelog.count() and
-                self.changelog.node(lrev) == last): # sanity check
-                for l in lines:
-                    if not l: continue
-                    node, label = l.rstrip().split(" ", 1)
-                    partial[label] = bin(node)
-            else: # invalidate the cache
-                last, lrev = nullid, nullrev
-        except IOError:
-            last, lrev = nullid, nullrev
+            if not (lrev < self.changelog.count() and
+                    self.changelog.node(lrev) == last): # sanity check
+                # invalidate the cache
+                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)
+        except (KeyboardInterrupt, util.SignalInterrupt):
+            raise
+        except Exception, inst:
+            if self.ui.debugflag:
+                self.ui.warn(str(inst), '\n')
+            partial, last, lrev = {}, nullid, nullrev
         return partial, last, lrev
 
     def _writebranchcache(self, branches, tip, tiprev):
--- a/tests/test-newbranch	Sat Dec 02 03:16:17 2006 -0200
+++ b/tests/test-newbranch	Sat Dec 02 03:38:55 2006 -0200
@@ -30,4 +30,11 @@
 
 echo % test for invalid branch cache
 hg rollback
+cp .hg/branches.cache .hg/bc-invalid
 hg log -r foo
+cp .hg/bc-invalid .hg/branches.cache
+hg --debug log -r foo
+rm .hg/branches.cache
+echo corrupted > .hg/branches.cache
+hg log -qr foo
+cat .hg/branches.cache
--- a/tests/test-newbranch.out	Sat Dec 02 03:16:17 2006 -0200
+++ b/tests/test-newbranch.out	Sat Dec 02 03:38:55 2006 -0200
@@ -56,3 +56,22 @@
 date:        Mon Jan 12 13:46:40 1970 +0000
 summary:     modify a branch
 
+Invalid branch cache: unknown tip
+changeset:   4:4909a3732169c0c20011c4f4b8fdff4e3d89b23f
+branch:      foo
+tag:         tip
+parent:      1:b699b1cec9c2966b3700de4fef0dc123cd754c31
+parent:      -1:0000000000000000000000000000000000000000
+manifest:    4:d01b250baaa05909152f7ae07d7a649deea0df9a
+user:        test
+date:        Mon Jan 12 13:46:40 1970 +0000
+files:       a
+extra:       branch=foo
+description:
+modify a branch
+
+
+4:4909a3732169
+4909a3732169c0c20011c4f4b8fdff4e3d89b23f 4
+4909a3732169c0c20011c4f4b8fdff4e3d89b23f foo
+67ec16bde7f1575d523313b9bca000f6a6f12dca bar