Patchwork [5,of,5] branchcache: make _rbcrevslen handling more safe

login
register
mail settings
Submitter Mads Kiilerich
Date Jan. 14, 2015, 11:24 p.m.
Message ID <ef517322b99724fac4c9.1421277880@localhost.localdomain>
Download mbox | patch
Permalink /patch/7460/
State Accepted
Commit 669106fc5bb1de671f59e432bbc59ca4ccc0e5bc
Headers show

Comments

Mads Kiilerich - Jan. 14, 2015, 11:24 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@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.
Matt Mackall - Jan. 15, 2015, 12:43 a.m.
On Thu, 2015-01-15 at 00:24 +0100, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <madski@unity3d.com>
> # Date 1421194526 -3600
> #      Wed Jan 14 01:15:26 2015 +0100
> # Node ID ef517322b99724fac4c9f89ebbfef39d032b5fa3
> # Parent  563e3b1a9c9f5efc7d07b1ae60cc45f700176989
> branchcache: make _rbcrevslen handling more safe

These are queued for default, thanks. But note that patch 2 is going to
need some fixups for non-Unix permissions.

Patch

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