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

Idan K idankk86 at gmail.com
Sat Jul 24 03:23:47 CDT 2010


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"))
        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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20100724/a62c7112/attachment.htm>


More information about the Mercurial-devel mailing list