changeset 21886:b9e8fdc35daf

subrepo: ensure "lock.release()" execution at the end of "_cachestorehash()" Before this patch, "lock.release()" for "self._repo" in "_cachestorehash()" 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 "_cachestorehash()" by moving it into "finally" clause.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Fri, 20 Jun 2014 00:21:19 +0900
parents fe9db58b0b2d
children 9aaffb22d7d7
files mercurial/subrepo.py
diffstat 1 files changed, 10 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/subrepo.py	Fri Jun 20 00:21:19 2014 +0900
+++ b/mercurial/subrepo.py	Fri Jun 20 00:21:19 2014 +0900
@@ -586,14 +586,16 @@
         '''
         cachefile = self._getstorehashcachepath(remotepath)
         lock = self._repo.lock()
-        storehash = list(self._calcstorehash(remotepath))
-        cachedir = os.path.dirname(cachefile)
-        if not os.path.exists(cachedir):
-            util.makedirs(cachedir, notindexed=True)
-        fd = open(cachefile, 'w')
-        fd.writelines(storehash)
-        fd.close()
-        lock.release()
+        try:
+            storehash = list(self._calcstorehash(remotepath))
+            cachedir = os.path.dirname(cachefile)
+            if not os.path.exists(cachedir):
+                util.makedirs(cachedir, notindexed=True)
+            fd = open(cachefile, 'w')
+            fd.writelines(storehash)
+            fd.close()
+        finally:
+            lock.release()
 
     @annotatesubrepoerror
     def _initrepo(self, parentrepo, source, create):