[PATCH] bookmarks: don't allow name to contain whitespaces only

Nicolas Dumazet nicdumz at gmail.com
Wed Jul 28 21:53:09 CDT 2010


On Sat, 24 Jul 2010 11:23:47 +0300
Idan K <idankk86 at gmail.com> wrote:

> Found this by accident when I created a bookmark with an empty name, e.g. hg
> bookmark ''. It created a new entry in the .hg/bookmarks file with the
> changeset id but the bookmark name was left blank which messed things up (it
> shadowed the other bookmarks).
> 
> 
> # HG changeset patch
> # User Idan Kamara <idankk86 at gmail.com>
> # Date 1279959621 -10800
> # Node ID c948a6a04b2adb7cc7a85b084aeb3fec37b39a10
> # Parent  1f7f8bc45240f4d036c33561d569f7d324ca5ed1
> bookmarks: don't allow name to contain whitespaces only
> 
> diff -r 1f7f8bc45240 -r c948a6a04b2a hgext/bookmarks.py
> --- a/hgext/bookmarks.py        Sat Jul 24 00:15:29 2010 +0200
> +++ b/hgext/bookmarks.py        Sat Jul 24 11:20:21 2010 +0300
> @@ -136,6 +136,8 @@
>         if "\n" in mark:
>             raise util.Abort(_("bookmark name cannot contain newlines"))
>         mark = mark.strip()
> +        if not mark:
> +            raise util.Abort(_("bookmark name cannot contain whitespaces
> only"))


Your mail client wraps long line. That's unconvenient when sending patches :)

Applied to stable, with a different message:
 " bookmark names cannot consist entirely of whitespace"
so it matches the tag error message we just introduced.

Thanks,
-Nicolas

>         if mark in marks and not force:
>             raise util.Abort(_("a bookmark of the same name already
> exists"))
>         if ((mark in repo.branchtags() or mark == repo.dirstate.branch())
> diff -r 1f7f8bc45240 -r c948a6a04b2a tests/test-bookmarks
> --- a/tests/test-bookmarks      Sat Jul 24 00:15:29 2010 +0200
> +++ b/tests/test-bookmarks      Sat Jul 24 11:20:21 2010 +0300
> @@ -100,4 +100,7 @@
>  echo % revision but no bookmark name
>  hg bookmark -r .
> 
> +echo % bookmark name with whitespace only
> +hg bookmark ' '
> +
>  true
> diff -r 1f7f8bc45240 -r c948a6a04b2a tests/test-bookmarks.out
> --- a/tests/test-bookmarks.out  Sat Jul 24 00:15:29 2010 +0200
> +++ b/tests/test-bookmarks.out  Sat Jul 24 11:20:21 2010 +0300
> @@ -74,3 +74,5 @@
>  * x  y                      2:0316ce92851d
>  % revision but no bookmark name
>  abort: bookmark name required
> +% bookmark name with whitespace only
> +abort: bookmark name cannot contain whitespaces only


-- 
Nicolas Dumazet — NicDumZ


More information about the Mercurial-devel mailing list