[PATCH 6 of 8] bookmarks: rely on exception for malformed lines
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Thu Jun 8 15:44:22 EDT 2017
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at octobus.net>
# Date 1496859759 -3600
# Wed Jun 07 19:22:39 2017 +0100
# Node ID b90c61451056ee0f8106b248559d48a7fb81690b
# Parent b8ad79e8c9b8f6cde6a90df1ff2602238396b3f0
# EXP-Topic perf
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
# hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r b90c61451056
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 an 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)
diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -58,12 +58,8 @@ class bmstore(dict):
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 @@ class bmstore(dict):
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:
More information about the Mercurial-devel
mailing list