scmutil: add function to validate new branch, tag, and bookmark names
authorKevin Bullock <kbullock@ringworld.org>
Wed, 17 Oct 2012 16:34:46 -0500
changeset 17817 b17be267b59c
parent 17816 19388ba75a06
child 17818 5023027240a1
scmutil: add function to validate new branch, tag, and bookmark names For now the new function only checks to make sure the new label name isn't a reserved name ('tip', '.', or 'null'). Eventually more of the checks will be unified between the different types of labels. The `tag` command is trivially updated to use it. Updating branches and bookmarks to use it is slightly more invasive and thus reserved for later patches.
mercurial/commands.py
mercurial/scmutil.py
--- a/mercurial/commands.py	Wed Oct 17 16:32:43 2012 -0500
+++ b/mercurial/commands.py	Wed Oct 17 16:34:46 2012 -0500
@@ -5640,8 +5640,7 @@
         if len(names) != len(set(names)):
             raise util.Abort(_('tag names must be unique'))
         for n in names:
-            if n in ['tip', '.', 'null']:
-                raise util.Abort(_("the name '%s' is reserved") % n)
+            scmutil.checknewlabel(repo, n)
             if not n:
                 raise util.Abort(_('tag names cannot consist entirely of '
                                    'whitespace'))
--- a/mercurial/scmutil.py	Wed Oct 17 16:32:43 2012 -0500
+++ b/mercurial/scmutil.py	Wed Oct 17 16:34:46 2012 -0500
@@ -27,6 +27,10 @@
     else:
         ui.status(_("no changes found\n"))
 
+def checknewlabel(repo, lbl):
+    if lbl in ['tip', '.', 'null']:
+        raise util.Abort(_("the name '%s' is reserved") % lbl)
+
 def checkfilename(f):
     '''Check that the filename f is an acceptable filename for a tracked file'''
     if '\r' in f or '\n' in f: