[PATCH 1 of 2] bookmarks: more robust parsing of bookmarks file

Idan Kamara idankk86 at gmail.com
Tue Jul 5 10:25:39 UTC 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 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)

The extra strip() here is harmless, but not needed.

>             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
> _______________________________________________
> 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://lists.mercurial-scm.org/pipermail/mercurial-devel/attachments/20110705/ac535c1f/attachment.html>


More information about the Mercurial-devel mailing list