[PATCH 3 of 9] bookmarks: abort directly on invalid name

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


# HG changeset patch
# User Kevin Bullock <kbullock at ringworld.org>
# Date 1350511381 18000
# Node ID de8aa47d28efd29ecdeaeb03f8cc49dc15650fb9
# Parent  f1b6af2759a9790945b058faab1f43cb3efd7bd7
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.

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -10,11 +10,11 @@ from mercurial.node import hex
 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 @@ def write(repo):
     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 @@ def setcurrent(repo, mark):
 
     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:


More information about the Mercurial-devel mailing list