changeset 33738:70661eeb8ddb

commands: move checkformat to bookmarks module commands.bookmark has grown quite large with two closures already. Let's split this up (and in the process allow extensions to override the default behavior).
author Sean Farley <sean@farley.io>
date Sat, 10 Jun 2017 23:32:58 -0700
parents b5305a499dfc
children 4f0a7f604449
files mercurial/bookmarks.py mercurial/commands.py
diffstat 2 files changed, 15 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -19,6 +19,7 @@
     error,
     lock as lockmod,
     obsolete,
+    scmutil,
     txnutil,
     util,
 )
@@ -622,3 +623,15 @@
     else:
         # still an independent clause as it is lazier (and therefore faster)
         return old.descendant(new)
+
+def checkformat(repo, mark):
+    """return a valid version of a potential bookmark name
+
+    Raises an abort error if the bookmark name is not valid.
+    """
+    mark = mark.strip()
+    if not mark:
+        raise error.Abort(_("bookmark names cannot consist entirely of "
+                            "whitespace"))
+    scmutil.checknewlabel(repo, mark, 'bookmark')
+    return mark
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -957,14 +957,6 @@
     rename = opts.get('rename')
     inactive = opts.get('inactive')
 
-    def checkformat(mark):
-        mark = mark.strip()
-        if not mark:
-            raise error.Abort(_("bookmark names cannot consist entirely of "
-                               "whitespace"))
-        scmutil.checknewlabel(repo, mark, 'bookmark')
-        return mark
-
     def checkconflict(repo, mark, cur, force=False, target=None):
         if mark in marks and not force:
             if target:
@@ -1039,7 +1031,7 @@
                     raise error.Abort(_("new bookmark name required"))
                 elif len(names) > 1:
                     raise error.Abort(_("only one new bookmark name allowed"))
-                mark = checkformat(names[0])
+                mark = bookmarks.checkformat(repo, names[0])
                 if rename not in marks:
                     raise error.Abort(_("bookmark '%s' does not exist")
                                       % rename)
@@ -1052,7 +1044,7 @@
                 tr = repo.transaction('bookmark')
                 newact = None
                 for mark in names:
-                    mark = checkformat(mark)
+                    mark = bookmarks.checkformat(repo, mark)
                     if newact is None:
                         newact = mark
                     if inactive and mark == repo._activebookmark: