D4524: narrowspec: validate patterns when loading and saving spec file
indygreg (Gregory Szorc)
phabricator at mercurial-scm.org
Tue Sep 11 18:52:36 UTC 2018
indygreg created this revision.
Herald added a reviewer: durin42.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
Patterns should be normalized and validated before being passed into
narrowspec.save(). Let's assert that by checking immediately before
writing the narrow spec file. And let's assert that patterns loaded
from the spec file also conform.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D4524
AFFECTED FILES
mercurial/narrowspec.py
tests/test-narrow-patterns.t
CHANGE DETAILS
diff --git a/tests/test-narrow-patterns.t b/tests/test-narrow-patterns.t
--- a/tests/test-narrow-patterns.t
+++ b/tests/test-narrow-patterns.t
@@ -437,3 +437,29 @@
$ hg tracked --addexclude set:ignored
abort: narrow pattern must begin with the following prefixes: path:, rootfilesin:; got set:ignored
[255]
+
+ $ cat .hg/store/narrowspec
+ [include]
+ path:dir1
+ path:dir1/dirA
+ [exclude]
+
+ $ cat > .hg/store/narrowspec << EOF
+ > [include]
+ > glob:**
+ > EOF
+
+ $ hg tracked
+ abort: narrow pattern must begin with the following prefixes: path:, rootfilesin:; got glob:**
+ [255]
+
+ $ cat > .hg/store/narrowspec << EOF
+ > [include]
+ > path:.
+ > [exclude]
+ > set:ignored
+ > EOF
+
+ $ hg tracked
+ abort: narrow pattern must begin with the following prefixes: path:, rootfilesin:; got set:ignored
+ [255]
diff --git a/mercurial/narrowspec.py b/mercurial/narrowspec.py
--- a/mercurial/narrowspec.py
+++ b/mercurial/narrowspec.py
@@ -165,9 +165,15 @@
if profiles:
raise error.Abort(_("including other spec files using '%include' is not"
" suported in narrowspec"))
+
+ validatepatterns(includepats)
+ validatepatterns(excludepats)
+
return includepats, excludepats
def save(repo, includepats, excludepats):
+ validatepatterns(includepats)
+ validatepatterns(excludepats)
spec = format(includepats, excludepats)
repo.svfs.write(FILENAME, spec)
To: indygreg, durin42, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list