[PATCH 1 of 3] cache: remove branch revision file before rewriting the branch name file

Mads Kiilerich mads at kiilerich.com
Sun Mar 13 01:13:29 UTC 2016


# HG changeset patch
# User Mads Kiilerich <madski at unity3d.com>
# Date 1457831181 -3600
#      Sun Mar 13 02:06:21 2016 +0100
# Node ID c4e1d65a90e115650d0de52a403e9fcb2170d410
# Parent  70c2f8a982766b512e9d7f41f2d93fdb92f5481f
cache: remove branch revision file before rewriting the branch name file

New branch names are usually appended to the branch name file. If that fails or
the file has been modified by another process, it is rewritten. That left a
small opportunity that there could be references to non-existent entries in the
file while it was rewritten.

To avoid that, remove the revision branch cache file with the references to the
branch name file before rewriting the branch name file. Worst case, when
interrupted at the wrong time, the cache will be lost and rebuilt next time.

It is unknown if this fixes a real problem that ever happened.

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -461,6 +461,8 @@ class revbranchcache(object):
                         self._rbcnamescount = 0
                         self._rbcrevslen = 0
                 if self._rbcnamescount == 0:
+                    # before rewriting names, make sure references are removed
+                    repo.vfs.unlinkpath(_rbcrevs, ignoremissing=True)
                     f = repo.vfs.open(_rbcnames, 'wb')
                 f.write('\0'.join(encoding.fromlocal(b)
                                   for b in self._names[self._rbcnamescount:]))


More information about the Mercurial-devel mailing list