comparison mercurial/bookmarks.py @ 32736:173f1bdc322d

bookmarks: rely on exception for malformed lines Since we already have an exception context open, for other thing, we can simplify the code a bit and rely on exception handling for invalid lines. Speed is not the main motivation for this changes. However as I'm in the middle of benchmarking things we can see a small positive impact. Before: ! wall 0.009358 comb 0.000000 user 0.000000 sys 0.000000 (best of 303) After: ! wall 0.009173 comb 0.010000 user 0.010000 sys 0.000000 (best of 310)
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 07 Jun 2017 19:22:39 +0100
parents d7522f983f37
children d6924192c0d5
comparison
equal deleted inserted replaced
32735:d7522f983f37 32736:173f1bdc322d
56 bkfile = _getbkfile(repo) 56 bkfile = _getbkfile(repo)
57 for line in bkfile: 57 for line in bkfile:
58 line = line.strip() 58 line = line.strip()
59 if not line: 59 if not line:
60 continue 60 continue
61 if ' ' not in line:
62 repo.ui.warn(_('malformed line in .hg/bookmarks: %r\n')
63 % line)
64 continue
65 sha, refspec = line.split(' ', 1)
66 try: 61 try:
62 sha, refspec = line.split(' ', 1)
67 node = tonode(sha) 63 node = tonode(sha)
68 if node in nm: 64 if node in nm:
69 refspec = encoding.tolocal(refspec) 65 refspec = encoding.tolocal(refspec)
70 self[refspec] = node 66 self[refspec] = node
71 except (TypeError, ValueError): 67 except (TypeError, ValueError):
72 # - bin(...) can raise TypeError 68 # - bin(...) can raise TypeError
73 # - node in nm can raise ValueError for non-20-bytes entry 69 # - node in nm can raise ValueError for non-20-bytes entry
70 # - split(...) can raise ValueError for string without ' '
74 repo.ui.warn(_('malformed line in .hg/bookmarks: %r\n') 71 repo.ui.warn(_('malformed line in .hg/bookmarks: %r\n')
75 % line) 72 % line)
76 except IOError as inst: 73 except IOError as inst:
77 if inst.errno != errno.ENOENT: 74 if inst.errno != errno.ENOENT:
78 raise 75 raise