changeset 3761:9433bdcaa9ae

Ignore all errors while parsing the branch cache.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Sat, 02 Dec 2006 03:38:55 -0200
parents aeafd80c1e78
children b9d3e12da485
files mercurial/localrepo.py tests/test-newbranch tests/test-newbranch.out
diffstat 3 files changed, 40 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -327,16 +327,20 @@ class localrepository(repo.repository):
             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
+++ b/tests/test-newbranch
@@ -30,4 +30,11 @@ hg branches -q
 
 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
+++ b/tests/test-newbranch.out
@@ -56,3 +56,22 @@ user:        test
 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