# HG changeset patch # User FUJIWARA Katsunori # Date 2014-06-19 15:21:19 # Node ID 9aaffb22d7d7e59d5079368536011a17bc2804de # Parent b9e8fdc35daf103fa56d2fc6ff7c70e6d07abfdd subrepo: ensure "close()" execution at the end of "_calcfilehash()" Before this patch, "close()" for the file object opened in "_calcfilehash()" may not be executed, if unexpected exception is raised, because it isn't executed in "finally" clause. This patch ensures "close()" execution at the end of "_calcfilehash()" by moving it into "finally" clause. diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py --- a/mercurial/subrepo.py +++ b/mercurial/subrepo.py @@ -35,8 +35,10 @@ def _calcfilehash(filename): data = '' if os.path.exists(filename): fd = open(filename, 'rb') - data = fd.read() - fd.close() + try: + data = fd.read() + finally: + fd.close() return util.sha1(data).hexdigest() class SubrepoAbort(error.Abort):