changeset 32794:6f775d10e83b

bookmarks: make sure we close the bookmark file after reading We previously lacked an explicit close of the bookmark file.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sat, 10 Jun 2017 01:59:22 +0100
parents 47ca96f9cfca
children f78d210f599d
files mercurial/bookmarks.py
diffstat 1 files changed, 19 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bookmarks.py	Sat Jun 10 01:55:01 2017 +0100
+++ b/mercurial/bookmarks.py	Sat Jun 10 01:59:22 2017 +0100
@@ -56,25 +56,25 @@
         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