Patchwork [1,of,4,V3] branchmap: preparatory indent of indent the branch rev writing code

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 7, 2016, 2:24 p.m.
Message ID <66809c98397f5b1dd69a.1470579892@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/16177/
State Accepted
Headers show

Comments

Pierre-Yves David - Aug. 7, 2016, 2:24 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1470401686 -7200
#      Fri Aug 05 14:54:46 2016 +0200
# Node ID 66809c98397f5b1dd69a5c3f0c98e44f6594f78f
# Parent  4372af40397f57be5819da17e1cbb4a51ff6eb4e
# EXP-Topic vfsward
branchmap: preparatory indent of indent the branch rev writing code

The rev branch cache is written without a lock, we are going to fix this but we
indent the code beforehand to make the next changeset clearer.
Yuya Nishihara - Aug. 8, 2016, 12:57 p.m.
On Sun, 07 Aug 2016 16:24:52 +0200, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
> # Date 1470401686 -7200
> #      Fri Aug 05 14:54:46 2016 +0200
> # Node ID 66809c98397f5b1dd69a5c3f0c98e44f6594f78f
> # Parent  4372af40397f57be5819da17e1cbb4a51ff6eb4e
> # EXP-Topic vfsward
> branchmap: preparatory indent of indent the branch rev writing code

and queued the series, thanks.

Patch

diff -r 4372af40397f -r 66809c98397f mercurial/branchmap.py
--- a/mercurial/branchmap.py	Fri Aug 05 15:48:09 2016 +0200
+++ b/mercurial/branchmap.py	Fri Aug 05 14:54:46 2016 +0200
@@ -470,48 +470,54 @@  class revbranchcache(object):
     def write(self, tr=None):
         """Save branch cache if it is dirty."""
         repo = self._repo
-        if self._rbcnamescount < len(self._names):
-            try:
-                if self._rbcnamescount != 0:
-                    f = repo.vfs.open(_rbcnames, 'ab')
-                    if f.tell() == self._rbcsnameslen:
-                        f.write('\0')
-                    else:
-                        f.close()
-                        repo.ui.debug("%s changed - rewriting it\n" % _rbcnames)
-                        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:]))
-                self._rbcsnameslen = f.tell()
-                f.close()
-            except (IOError, OSError, error.Abort) as inst:
-                repo.ui.debug("couldn't write revision branch cache names: "
-                              "%s\n" % inst)
-                return
-            self._rbcnamescount = len(self._names)
+        if True:
+            if self._rbcnamescount < len(self._names):
+                try:
+                    if self._rbcnamescount != 0:
+                        f = repo.vfs.open(_rbcnames, 'ab')
+                        if f.tell() == self._rbcsnameslen:
+                            f.write('\0')
+                        else:
+                            f.close()
+                            repo.ui.debug("%s changed - rewriting it\n"
+                                          % _rbcnames)
+                            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:]
+                                      ))
+                    self._rbcsnameslen = f.tell()
+                    f.close()
+                except (IOError, OSError, error.Abort) as inst:
+                    repo.ui.debug("couldn't write revision branch cache names: "
+                                  "%s\n" % inst)
+                    return
+                self._rbcnamescount = len(self._names)
 
-        start = self._rbcrevslen * _rbcrecsize
-        if start != len(self._rbcrevs):
-            revs = min(len(repo.changelog), len(self._rbcrevs) // _rbcrecsize)
-            try:
-                f = repo.vfs.open(_rbcrevs, 'ab')
-                if f.tell() != start:
-                    repo.ui.debug("truncating %s to %s\n" % (_rbcrevs, start))
-                    f.seek(start)
+            start = self._rbcrevslen * _rbcrecsize
+            if start != len(self._rbcrevs):
+                revs = min(len(repo.changelog),
+                           len(self._rbcrevs) // _rbcrecsize)
+                try:
+                    f = repo.vfs.open(_rbcrevs, 'ab')
                     if f.tell() != start:
-                        start = 0
+                        repo.ui.debug("truncating %s to %s\n"
+                                      % (_rbcrevs, start))
                         f.seek(start)
-                    f.truncate()
-                end = revs * _rbcrecsize
-                f.write(self._rbcrevs[start:end])
-                f.close()
-            except (IOError, OSError, error.Abort) as inst:
-                repo.ui.debug("couldn't write revision branch cache: %s\n" %
-                              inst)
-                return
-            self._rbcrevslen = revs
+                        if f.tell() != start:
+                            start = 0
+                            f.seek(start)
+                        f.truncate()
+                    end = revs * _rbcrecsize
+                    f.write(self._rbcrevs[start:end])
+                    f.close()
+                except (IOError, OSError, error.Abort) as inst:
+                    repo.ui.debug("couldn't write revision branch cache: %s\n" %
+                                  inst)
+                    return
+                self._rbcrevslen = revs