Patchwork [10,of,10] subrepo: ensure "lock.release()" execution at the end of "storeclean()"

login
register
mail settings
Submitter Katsunori FUJIWARA
Date May 28, 2014, 3 p.m.
Message ID <08b42b10494666a1c587.1401289222@juju>
Download mbox | patch
Permalink /patch/4891/
State Superseded
Commit fe9db58b0b2d1f0c36ba197c880150ad55ab9a19
Headers show

Comments

Katsunori FUJIWARA - May 28, 2014, 3 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1401288802 -32400
#      Wed May 28 23:53:22 2014 +0900
# Node ID 08b42b10494666a1c58767feaea102a92e49db85
# Parent  c55208e571d22bc350a9c12193403f7f2e730db5
subrepo: ensure "lock.release()" execution at the end of "storeclean()"

Before this patch, "lock.release()" for "self._repo" in "storeclean()"
of "hgsubrepo" may not be executed, if unexpected exception is raised,
because it isn't executed in "finally" clause.

This patch ensures "lock.release()" execution at the end of
"storeclean()" by moving it into "finally" clause.

This patch chooses moving almost all lines in "storeclean()" into
"_storeclean()" instead of indenting them for "try/finally" clauses,
to keep diff simple for review-ability.
Pierre-Yves David - June 6, 2014, 1:15 a.m.
On 05/28/2014 08:00 AM, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1401288802 -32400
> #      Wed May 28 23:53:22 2014 +0900
> # Node ID 08b42b10494666a1c58767feaea102a92e49db85
> # Parent  c55208e571d22bc350a9c12193403f7f2e730db5
> subrepo: ensure "lock.release()" execution at the end of "storeclean()"

The series looks fine in general. But we need a couple of patches fixed 
before I can queue it.

Patch

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -517,8 +517,14 @@  class hgsubrepo(abstractsubrepo):
         self._initrepo(r, state[0], create)
 
     def storeclean(self, path):
+        lock = self._repo.lock()
+        try:
+            return self._storeclean(path)
+        finally:
+            lock.release()
+
+    def _storeclean(self, path):
         clean = True
-        lock = self._repo.lock()
         itercache = self._calcstorehash(path)
         try:
             for filehash in self._readstorehashcache(path):
@@ -535,7 +541,6 @@  class hgsubrepo(abstractsubrepo):
                 clean = False
             except StopIteration:
                 pass
-        lock.release()
         return clean
 
     def _calcstorehash(self, remotepath):