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)
--- a/mercurial/bookmarks.py Wed Jun 07 22:26:43 2017 +0100
+++ b/mercurial/bookmarks.py Wed Jun 07 19:22:39 2017 +0100
@@ -58,12 +58,8 @@
line = line.strip()
if not line:
continue
- if ' ' not in line:
- repo.ui.warn(_('malformed line in .hg/bookmarks: %r\n')
- % line)
- continue
- sha, refspec = line.split(' ', 1)
try:
+ sha, refspec = line.split(' ', 1)
node = tonode(sha)
if node in nm:
refspec = encoding.tolocal(refspec)
@@ -71,6 +67,7 @@
except (TypeError, ValueError):
# - bin(...) can raise TypeError
# - node in nm can raise ValueError for non-20-bytes entry
+ # - split(...) can raise ValueError for string without ' '
repo.ui.warn(_('malformed line in .hg/bookmarks: %r\n')
% line)
except IOError as inst: