bookmarks: abort directly on invalid name
authorKevin Bullock <kbullock@ringworld.org>
Wed, 17 Oct 2012 17:03:01 -0500
changeset 17815 be1467342038
parent 17814 f88ca484c3e9
child 17816 19388ba75a06
bookmarks: abort directly on invalid name This consolidates the abort message for a bookmark name containing invalid characters into one place, and renames the valid() method to checkvalid() to reflect the fact that it's no longer a predicate.
mercurial/bookmarks.py
--- a/mercurial/bookmarks.py	Wed Oct 17 16:23:42 2012 -0500
+++ b/mercurial/bookmarks.py	Wed Oct 17 17:03:01 2012 -0500
@@ -10,11 +10,11 @@
 from mercurial import encoding, error, util, obsolete, phases
 import errno, os
 
-def valid(mark):
+def checkvalid(mark):
     for c in (':', '\0', '\n', '\r'):
         if c in mark:
-            return False
-    return True
+            raise util.Abort(_("bookmark '%s' contains illegal "
+                "character" % mark))
 
 def read(repo):
     '''Parse .hg/bookmarks file and return a dictionary
@@ -80,9 +80,7 @@
     if repo._bookmarkcurrent not in refs:
         setcurrent(repo, None)
     for mark in refs.keys():
-        if not valid(mark):
-            raise util.Abort(_("bookmark '%s' contains illegal "
-                "character" % mark))
+        checkvalid(mark)
 
     wlock = repo.wlock()
     try:
@@ -113,9 +111,7 @@
 
     if mark not in repo._bookmarks:
         mark = ''
-    if not valid(mark):
-        raise util.Abort(_("bookmark '%s' contains illegal "
-            "character" % mark))
+    checkvalid(mark)
 
     wlock = repo.wlock()
     try: