<p dir="ltr">Could you please add issue5058</p>
<div class="gmail_quot<blockquote class=" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"># HG changeset patch<br>
# User Mads Kiilerich <<a href="mailto:madski@unity3d.com">madski@unity3d.com</a>><br>
# Date 1457831183 -3600<br>
# Sun Mar 13 02:06:23 2016 +0100<br>
# Node ID 7f85c3393e4594a886b535f0679d1abca37f4604<br>
# Parent b8a5abd4a18ee070b922d03e5c14d63df504b78a<br>
cache: rebuild branch cache from scratch when inconsistencies are detected<br>
<br>
This should recover automatically from some corruptions that for unknown<br>
reasons are seen in the wild.<br>
<br>
diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py<br>
--- a/mercurial/branchmap.py<br>
+++ b/mercurial/branchmap.py<br>
@@ -383,6 +383,15 @@ class revbranchcache(object):<br>
self._rbcnamescount = len(self._names) # number of good names on disk<br>
self._namesreverse = dict((b, r) for r, b in enumerate(self._names))<br>
<br>
+ def _clear(self):<br>
+ self._rbcsnameslen = 0<br>
+ del self._names[:]<br>
+ self._rbcnamescount = 0<br>
+ self._namesreverse.clear()<br>
+ self._rbcrevslen = len(self._repo.changelog)<br>
+ self._rbcrevs = array('c')<br>
+ self._rbcrevs.fromstring('\0' * (self._rbcrevslen * _rbcrecsize))<br>
+<br>
def branchinfo(self, rev):<br>
"""Return branch name and close flag for rev, using and updating<br>
persistent cache."""<br>
@@ -408,7 +417,11 @@ class revbranchcache(object):<br>
if cachenode == '\0\0\0\0':<br>
pass<br>
elif cachenode == reponode:<br>
- return self._names[branchidx], close<br>
+ if branchidx < self._rbcnamescount:<br>
+ return self._names[branchidx], close<br>
+ # referenced branch doesn't exist - rebuild is expensive but needed<br>
+ self._repo.ui.debug("rebuilding corrupted revision branch cache\n")<br>
+ self._clear()<br>
else:<br>
# rev/node map has changed, invalidate the cache from here up<br>
truncate = rbcrevidx + _rbcrecsize<br>
diff --git a/tests/test-branches.t b/tests/test-branches.t<br>
--- a/tests/test-branches.t<br>
+++ b/tests/test-branches.t<br>
@@ -629,4 +629,25 @@ situation where the cache is out of sync<br>
$ f --size .hg/cache/rbc-revs*<br>
.hg/cache/rbc-revs-v1: size=112<br>
<br>
+cache is rebuilt when corruption is detected<br>
+ $ echo > .hg/cache/rbc-names-v1<br>
+ $ hg log -r '5:&branch(.)' -T '{rev} ' --debug<br>
+ rebuilding corrupted revision branch cache<br>
+ 8 9 10 11 12 13 truncating cache/rbc-revs-v1 to 40<br>
+ $ f --size --hexdump .hg/cache/rbc-*<br>
+ .hg/cache/rbc-names-v1: size=79<br>
+ 0000: 62 00 61 00 63 00 61 20 62 72 61 6e 63 68 20 6e |b.a.c.a branch n|<br>
+ 0010: 61 6d 65 20 6d 75 63 68 20 6c 6f 6e 67 65 72 20 |ame much longer |<br>
+ 0020: 74 68 61 6e 20 74 68 65 20 64 65 66 61 75 6c 74 |than the default|<br>
+ 0030: 20 6a 75 73 74 69 66 69 63 61 74 69 6f 6e 20 75 | justification u|<br>
+ 0040: 73 65 64 20 62 79 20 62 72 61 6e 63 68 65 73 |sed by branches|<br>
+ .hg/cache/rbc-revs-v1: size=112<br>
+ 0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|<br>
+ 0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|<br>
+ 0020: 00 00 00 00 00 00 00 00 d8 cb c6 1d 00 00 00 01 |................|<br>
+ 0030: 58 97 36 a2 00 00 00 02 10 ff 58 95 00 00 00 03 |X.6.......X.....|<br>
+ 0040: ee bb 94 44 00 00 00 00 5f 40 61 bb 00 00 00 00 |...D...._@a.....|<br>
+ 0050: bf be 84 1b 00 00 00 00 d3 f1 63 45 80 00 00 00 |..........cE....|<br>
+ 0060: e3 d4 9c 05 80 00 00 00 e2 3b 55 05 00 00 00 00 |.........;U.....|<br>
+<br>
$ cd ..<br>
_______________________________________________<br>
Mercurial-devel mailing list<br>
<a href="mailto:Mercurial-devel@mercurial-scm.org">Mercurial-devel@mercurial-scm.org</a><br>
<a href="https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel" rel="noreferrer" target="_blank">https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel</a><br>
</div>