comparison mercurial/bookmarks.py @ 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 70661eeb8ddb
comparison
equal deleted inserted replaced
32793:47ca96f9cfca 32794:6f775d10e83b
54 self._aclean = True 54 self._aclean = True
55 nm = repo.changelog.nodemap 55 nm = repo.changelog.nodemap
56 tonode = bin # force local lookup 56 tonode = bin # force local lookup
57 setitem = dict.__setitem__ 57 setitem = dict.__setitem__
58 try: 58 try:
59 bkfile = _getbkfile(repo) 59 with _getbkfile(repo) as bkfile:
60 for line in bkfile: 60 for line in bkfile:
61 line = line.strip() 61 line = line.strip()
62 if not line: 62 if not line:
63 continue 63 continue
64 try: 64 try:
65 sha, refspec = line.split(' ', 1) 65 sha, refspec = line.split(' ', 1)
66 node = tonode(sha) 66 node = tonode(sha)
67 if node in nm: 67 if node in nm:
68 refspec = encoding.tolocal(refspec) 68 refspec = encoding.tolocal(refspec)
69 setitem(self, refspec, node) 69 setitem(self, refspec, node)
70 except (TypeError, ValueError): 70 except (TypeError, ValueError):
71 # TypeError: 71 # TypeError:
72 # - bin(...) 72 # - bin(...)
73 # ValueError: 73 # ValueError:
74 # - node in nm, for non-20-bytes entry 74 # - node in nm, for non-20-bytes entry
75 # - split(...), for string without ' ' 75 # - split(...), for string without ' '
76 repo.ui.warn(_('malformed line in .hg/bookmarks: %r\n') 76 repo.ui.warn(_('malformed line in .hg/bookmarks: %r\n')
77 % line) 77 % line)
78 except IOError as inst: 78 except IOError as inst:
79 if inst.errno != errno.ENOENT: 79 if inst.errno != errno.ENOENT:
80 raise 80 raise
81 self._active = _readactive(repo, self) 81 self._active = _readactive(repo, self)
82 82