[PATCH 5 of 9] scmutil: add function to validate new branch, tag, and bookmark names

Kevin Bullock kbullock+mercurial at ringworld.org
Wed Oct 17 22:31:45 CDT 2012


# HG changeset patch
# User Kevin Bullock <kbullock at ringworld.org>
# Date 1350509686 18000
# Node ID 614653e8d2896effe42c94c196f2de9a1b333a5f
# Parent  2a50542fd0a2626b1e7bdab5b35d32220f4bbb7f
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.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5636,8 +5636,7 @@ def tag(ui, repo, name1, *names, **opts)
         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'))
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -27,6 +27,10 @@ def nochangesfound(ui, repo, excluded=No
     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:


More information about the Mercurial-devel mailing list