Patchwork [6,of,7] branchmap: simplify error handlind when writing rev branch cache

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 5, 2016, 1:59 p.m.
Message ID <32a16c54123fbedad4ea.1470405559@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/16118/
State Superseded
Headers show

Comments

Pierre-Yves David - Aug. 5, 2016, 1:59 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1470402053 -7200
#      Fri Aug 05 15:00:53 2016 +0200
# Node ID 32a16c54123fbedad4ea9579d6db8344753db976
# Parent  51046e1ff9b1d5817a95163a25ca3dc975db7e8f
# EXP-Topic vfsward
branchmap: simplify error handlind when writing rev branch cache

Now that we have a general try except, we can move the error handling from the
individual writes in it.
Code will be reindented in the next changeset to help this on readability.

Patch

diff -r 51046e1ff9b1 -r 32a16c54123f mercurial/branchmap.py
--- a/mercurial/branchmap.py	Fri Aug 05 14:57:16 2016 +0200
+++ b/mercurial/branchmap.py	Fri Aug 05 15:00:53 2016 +0200
@@ -471,10 +471,12 @@  class revbranchcache(object):
         """Save branch cache if it is dirty."""
         repo = self._repo
         wlock = None
+        step = ''
         try:
             if self._rbcnamescount < len(self._names):
+                step = ' names'
                 wlock = repo.wlock(wait=False)
-                try:
+                if True:
                     if self._rbcnamescount != 0:
                         f = repo.vfs.open(_rbcnames, 'ab')
                         if f.tell() == self._rbcsnameslen:
@@ -495,18 +497,15 @@  class revbranchcache(object):
                                       ))
                     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):
+                step = ''
                 wlock = repo.wlock(wait=False)
                 revs = min(len(repo.changelog),
                            len(self._rbcrevs) // _rbcrecsize)
-                try:
+                if True:
                     f = repo.vfs.open(_rbcrevs, 'ab')
                     if f.tell() != start:
                         repo.ui.debug("truncating %s to %s\n"
@@ -519,13 +518,10 @@  class revbranchcache(object):
                     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
-        except error.LockHeld as inst:
-            repo.ui.debug("couldn't write revision branch cache: %s\n" % inst)
+        except (IOError, OSError, error.Abort, error.LockHeld) as inst:
+            repo.ui.debug("couldn't write revision branch cache%s: %s\n"
+                          % (step, inst))
         finally:
             if wlock is not None:
                 wlock.release()