changeset 32756: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
files mercurial/bookmarks.py
diffstat 1 files changed, 2 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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: