diff mercurial/bookmarks.py @ 32973: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 6f775d10e83b
children 4f0a7f604449
line wrap: on
line diff
--- a/mercurial/bookmarks.py	Tue Jun 20 14:35:53 2017 -0700
+++ b/mercurial/bookmarks.py	Sat Jun 10 23:32:58 2017 -0700
@@ -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