[PATCH 1 of 2 V2] label: enforce the lack of leading or trailing white space

Boris Feld boris.feld at octobus.net
Mon Feb 12 17:00:51 UTC 2018


# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1518448171 -3600
#      Mon Feb 12 16:09:31 2018 +0100
# Node ID f02fd7ca256d044c4a51c3f3fc0ecaf95d23e03d
# Parent  80e5210df25c330bd2a4e8f12385422545cb69bf
# EXP-Topic noname
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r f02fd7ca256d
label: enforce the lack of leading or trailing white space

In practice, all commands create label are currently striping external white
space. Let us enforce this logic at a lower level before starting to rely on
it elsewhere.

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -267,6 +267,8 @@ def checknewlabel(repo, lbl, kind):
         raise error.Abort(_("cannot use an integer as a name"))
     except ValueError:
         pass
+    if lbl.strip() != lbl:
+        raise error.Abort(_("leading or trailing whitespace in name %r") % lbl)
 
 def checkfilename(f):
     '''Check that the filename f is an acceptable filename for a tracked file'''


More information about the Mercurial-devel mailing list