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.
--- 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: