[PATCH 2 of 2] bookmarks: Add a warning for non empty malformated line
Idan Kamara
idankk86 at gmail.com
Tue Jul 5 06:06:57 CDT 2011
On Tue, Jul 5, 2011 at 12:51 PM, <pierre-yves.david at logilab.fr> wrote:
>
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david at logilab.fr>
> # Date 1309854027 -7200
> # Branch stable
> # Node ID bc187cbdf4efb51f7ee83df798aa679c9aff0d2d
> # Parent a59f9d94beba02c92c7c37b7c0d8034873fca580
> bookmarks: Add a warning for non empty malformated line.
>
> diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
> --- a/mercurial/bookmarks.py
> +++ b/mercurial/bookmarks.py
> @@ -26,10 +26,13 @@ def read(repo):
> bookmarks = {}
> try:
> for line in repo.opener('bookmarks'):
> line = line.strip()
> if ' ' not in line:
> + if line:
> + msg = _('malformated line in .hg/bookmarks: %r\n')
> + repo.ui.warn( msg % line)
> continue
> sha, refspec = line.strip().split(' ', 1)
How about something like this instead:
count = 0
for line in repo.opener('bookmarks'):
count += 1
line = line.strip()
if not line:
continue
try:
sha, refspec = line.split(' ', 1)
except ValueError:
repo.ui.warn(_("bookmarks, line %d, cannot parse bookmark entry %r") %
(count, line))
Might as well also check 'sha' for correctness using node.bin().
> refspec = encoding.tolocal(refspec)
> try:
> bookmarks[refspec] = repo.changelog.lookup(sha)
> diff --git a/tests/test-bookmarks.t b/tests/test-bookmarks.t
> --- a/tests/test-bookmarks.t
> +++ b/tests/test-bookmarks.t
> @@ -348,5 +348,13 @@ test wrongly formated bookmark
> $ hg bookmarks
> X2 1:925d80f479bb
> Y 2:db815d6d32e6
> * Z 3:125c9a1d6df6
> x y 2:db815d6d32e6
> + $ echo "Ican'thasformatedlines" >> .hg/bookmarks
> + $ hg bookmarks
> + malformated line in .hg/bookmarks: "Ican'thasformatedlines"
> + X2 1:925d80f479bb
> + Y 2:db815d6d32e6
> + * Z 3:125c9a1d6df6
> + x y 2:db815d6d32e6
> +
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20110705/bfa0642d/attachment.htm>
More information about the Mercurial-devel
mailing list