From patchwork Thu Jun 19 15:43:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2, of, 7, STABLE] subrepo: ensure "lock.release()" execution at the end of "_cachestorehash()" From: Katsunori FUJIWARA X-Patchwork-Id: 5018 Message-Id: To: mercurial-devel@selenic.com Date: Fri, 20 Jun 2014 00:43:17 +0900 # HG changeset patch # User FUJIWARA Katsunori # Date 1403191279 -32400 # Fri Jun 20 00:21:19 2014 +0900 # Branch stable # Node ID f1af69e11e972b1be65ca7d5e62126c00713a10b # Parent 15bc43d3360a4826cab2c3b93e6bf2cfafbcf070 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. diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py --- a/mercurial/subrepo.py +++ b/mercurial/subrepo.py @@ -582,14 +582,16 @@ class hgsubrepo(abstractsubrepo): ''' 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):