[PATCH 5 of 5] branchcache: make _rbcrevslen handling more safe

Mads Kiilerich mads at kiilerich.com
Wed Jan 14 17:24:40 CST 2015


# HG changeset patch
# User Mads Kiilerich <madski at unity3d.com>
# Date 1421194526 -3600
#      Wed Jan 14 01:15:26 2015 +0100
# Node ID ef517322b99724fac4c9f89ebbfef39d032b5fa3
# Parent  563e3b1a9c9f5efc7d07b1ae60cc45f700176989
branchcache: make _rbcrevslen handling more safe

self._rbcrevslen is used to keep track of the number of good records on disk.
It should thus not be updated before the records actually have been written to
disk.

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -431,8 +431,7 @@ class revbranchcache(object):
 
         start = self._rbcrevslen * _rbcrecsize
         if start != len(self._rbcrevs):
-            self._rbcrevslen = min(len(repo.changelog),
-                                   len(self._rbcrevs) // _rbcrecsize)
+            revs = min(len(repo.changelog), len(self._rbcrevs) // _rbcrecsize)
             try:
                 f = repo.vfs.open(_rbcrevs, 'ab')
                 # The position after open(x, 'a') is implementation defined-
@@ -442,10 +441,11 @@ class revbranchcache(object):
                     repo.ui.debug("truncating %s to %s\n" % (_rbcrevs, start))
                     f.seek(start)
                     f.truncate()
-                end = self._rbcrevslen * _rbcrecsize
+                end = revs * _rbcrecsize
                 f.write(self._rbcrevs[start:end])
                 f.close()
             except (IOError, OSError, util.Abort), inst:
                 repo.ui.debug("couldn't write revision branch cache: %s\n" %
                               inst)
                 return
+            self._rbcrevslen = revs


More information about the Mercurial-devel mailing list