Patchwork [2,of,3] branchmap: close cache file properly

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 17, 2018, 1:57 a.m.
Message ID <dd1614906a20ea7e189e.1534471055@mimosa>
Download mbox | patch
Permalink /patch/33811/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 17, 2018, 1:57 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1534469139 -32400
#      Fri Aug 17 10:25:39 2018 +0900
# Node ID dd1614906a20ea7e189e0461d9d86beec0a52197
# Parent  b892df0766e164fca47d3b04cbc9b774db097eb4
branchmap: close cache file properly

Follows up 2a4bfbb52111.

Patch

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -38,6 +38,7 @@  def _filename(repo):
     return filename
 
 def read(repo):
+    f = None
     try:
         f = repo.cachevfs(_filename(repo))
         cachekey = next(f).rstrip('\n').split(" ", 2)
@@ -79,6 +80,11 @@  def read(repo):
             msg += ': %s\n'
             repo.ui.debug(msg % pycompat.bytestr(inst))
         partial = None
+
+    finally:
+        if f:
+            f.close()
+
     return partial
 
 ### Nearest subset relation