# HG changeset patch # User Kevin Bullock # Date 2012-10-17 22:03:01 # Node ID be1467342038466343a5cd60ae357576c4373c13 # Parent f88ca484c3e9187ed966542ddeeffde59008fee2 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: