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

login
register
mail settings
Submitter Boris Feld
Date Feb. 12, 2018, 5 p.m.
Message ID <f02fd7ca256d044c4a51.1518454851@FB>
Download mbox | patch
Permalink /patch/27671/
State Accepted
Headers show

Comments

Boris Feld - Feb. 12, 2018, 5 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@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.
Yuya Nishihara - Feb. 13, 2018, 11:48 a.m.
On Mon, 12 Feb 2018 18:00:51 +0100, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld@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

Queued this, thanks.

Patch

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'''