[PATCH 8 of 8 v2] bookmarks: forbid \0 \r \n : in bookmark names

David Soria Parra dsp at php.net
Tue Feb 1 16:22:00 CST 2011


# HG changeset patch
# User David Soria Parra <dsp at php.net>
# Date 1296598900 -3600
# Node ID 31da1f610530f53887ecc5218e60eb6e037fb67b
# Parent  e8802d295d69338971e15ca823eff899e4a425b0
bookmarks: forbid \0 \r \n : in bookmark names

We restrict : to 1. make it easer to convert bookmarks to git branches,
2. use : later for a syntax to push a local bookmark to a remote bookmark
of a different name.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -15,6 +15,7 @@
 import merge as mergemod
 import tags as tagsmod
 import url as urlmod
+import re
 from lock import release
 import weakref, errno, os, time, inspect
 propertycache = util.propertycache
@@ -612,6 +613,12 @@
 
         wlock = self.wlock()
         try:
+            r = re.compile('(:|\0|\n|\r)')
+            for ref in refs.keys():
+                if r.search(ref):
+                    raise util.Abort(_("bookmark '%s' contains illegal "
+                        "character" % ref))
+
             file = self.opener('bookmarks', 'w', atomictemp=True)
             for ref, node in refs.iteritems():
                 file.write("%s %s\n" % (hex(node), encoding.fromlocal(ref)))
diff --git a/tests/test-bookmarks.t b/tests/test-bookmarks.t
--- a/tests/test-bookmarks.t
+++ b/tests/test-bookmarks.t
@@ -208,3 +208,9 @@
   $ hg bookmark ' '
   abort: bookmark names cannot consist entirely of whitespace
   [255]
+
+invalid bookmark
+
+  $ hg bookmark 'foo:bar'
+  abort: bookmark 'foo:bar' contains illegal character
+  [255]


More information about the Mercurial-devel mailing list