[PATCH 1 of 2] bookmarks: more robust parsing of bookmarks file
pierre-yves.david at logilab.fr
pierre-yves.david at logilab.fr
Tue Jul 5 04:51:45 CDT 2011
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1309853634 -7200
# Branch stable
# Node ID a59f9d94beba02c92c7c37b7c0d8034873fca580
# Parent de9eb6b1da4fc522b1cab16d86ca166204c24f25
bookmarks: more robust parsing of bookmarks file.
diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -24,10 +24,13 @@ def read(repo):
Read the file and return a (name=>nodeid) dictionary
'''
bookmarks = {}
try:
for line in repo.opener('bookmarks'):
+ line = line.strip()
+ if ' ' not in line:
+ continue
sha, refspec = line.strip().split(' ', 1)
refspec = encoding.tolocal(refspec)
try:
bookmarks[refspec] = repo.changelog.lookup(sha)
except error.RepoLookupError:
diff --git a/tests/test-bookmarks.t b/tests/test-bookmarks.t
--- a/tests/test-bookmarks.t
+++ b/tests/test-bookmarks.t
@@ -340,5 +340,13 @@ create bundle with two heads
X2 1:925d80f479bb
Y 2:db815d6d32e6
* Z 3:125c9a1d6df6
x y 2:db815d6d32e6
+test wrongly formated bookmark
+
+ $ echo '' >> .hg/bookmarks
+ $ hg bookmarks
+ X2 1:925d80f479bb
+ Y 2:db815d6d32e6
+ * Z 3:125c9a1d6df6
+ x y 2:db815d6d32e6
More information about the Mercurial-devel
mailing list