Patchwork [2,of,2] bookmark: make sure we close the bookmark file after reading

login
register
mail settings
Submitter Pierre-Yves David
Date June 10, 2017, 1:32 a.m.
Message ID <2f362e8ce5716e178dec.1497058350@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/21314/
State Accepted
Headers show

Comments

Pierre-Yves David - June 10, 2017, 1:32 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1497056362 -3600
#      Sat Jun 10 01:59:22 2017 +0100
# Node ID 2f362e8ce5716e178dec0479b89c0cc3491d444e
# Parent  10c0e1f7d48bfa560879bbdbc6ceedc266e1b38b
# EXP-Topic bookmark
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r 2f362e8ce571
bookmark: make sure we close the bookmark file after reading

We previously lacked an explicit close of the bookmark file.

Patch

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -56,25 +56,25 @@  class bmstore(dict):
         tonode = bin # force local lookup
         setitem = dict.__setitem__
         try:
-            bkfile = _getbkfile(repo)
-            for line in bkfile:
-                line = line.strip()
-                if not line:
-                    continue
-                try:
-                    sha, refspec = line.split(' ', 1)
-                    node = tonode(sha)
-                    if node in nm:
-                        refspec = encoding.tolocal(refspec)
-                        setitem(self, refspec, node)
-                except (TypeError, ValueError):
-                    # TypeError:
-                    # - bin(...)
-                    # ValueError:
-                    # - node in nm, for non-20-bytes entry
-                    # - split(...), for string without ' '
-                    repo.ui.warn(_('malformed line in .hg/bookmarks: %r\n')
-                                 % line)
+            with _getbkfile(repo) as bkfile:
+                for line in bkfile:
+                    line = line.strip()
+                    if not line:
+                        continue
+                    try:
+                        sha, refspec = line.split(' ', 1)
+                        node = tonode(sha)
+                        if node in nm:
+                            refspec = encoding.tolocal(refspec)
+                            setitem(self, refspec, node)
+                    except (TypeError, ValueError):
+                        # TypeError:
+                        # - bin(...)
+                        # ValueError:
+                        # - node in nm, for non-20-bytes entry
+                        # - split(...), for string without ' '
+                        repo.ui.warn(_('malformed line in .hg/bookmarks: %r\n')
+                                     % line)
         except IOError as inst:
             if inst.errno != errno.ENOENT:
                 raise