Patchwork [6,of,8] bookmarks: rely on exception for malformed lines

login
register
mail settings
Submitter Pierre-Yves David
Date June 8, 2017, 7:44 p.m.
Message ID <b90c61451056ee0f8106.1496951062@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/21260/
State Accepted
Headers show

Comments

Pierre-Yves David - June 8, 2017, 7:44 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@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)

Patch

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: