Show More
@@ -20,6 +20,15 b' from . import (' | |||
|
20 | 20 | |
|
21 | 21 | FILENAME = 'narrowspec' |
|
22 | 22 | |
|
23 | # Pattern prefixes that are allowed in narrow patterns. This list MUST | |
|
24 | # only contain patterns that are fast and safe to evaluate. Keep in mind | |
|
25 | # that patterns are supplied by clients and executed on remote servers | |
|
26 | # as part of wire protocol commands. | |
|
27 | VALID_PREFIXES = ( | |
|
28 | b'path:', | |
|
29 | b'rootfilesin:', | |
|
30 | ) | |
|
31 | ||
|
23 | 32 | def parseserverpatterns(text): |
|
24 | 33 | """Parses the narrowspec format that's returned by the server.""" |
|
25 | 34 | includepats = set() |
@@ -82,8 +91,42 b' def normalizepattern(pattern, defaultkin' | |||
|
82 | 91 | return '%s:%s' % normalizesplitpattern(kind, pat) |
|
83 | 92 | |
|
84 | 93 | def parsepatterns(pats): |
|
85 |
"""Parses a |
|
|
86 | return set(normalizepattern(p) for p in pats) | |
|
94 | """Parses an iterable of patterns into a typed pattern set. | |
|
95 | ||
|
96 | Patterns are assumed to be ``path:`` if no prefix is present. | |
|
97 | For safety and performance reasons, only some prefixes are allowed. | |
|
98 | See ``validatepatterns()``. | |
|
99 | ||
|
100 | This function should be used on patterns that come from the user to | |
|
101 | normalize and validate them to the internal data structure used for | |
|
102 | representing patterns. | |
|
103 | """ | |
|
104 | res = {normalizepattern(orig) for orig in pats} | |
|
105 | validatepatterns(res) | |
|
106 | return res | |
|
107 | ||
|
108 | def validatepatterns(pats): | |
|
109 | """Validate that patterns are in the expected data structure and format. | |
|
110 | ||
|
111 | And that is a set of normalized patterns beginning with ``path:`` or | |
|
112 | ``rootfilesin:``. | |
|
113 | ||
|
114 | This function should be used to validate internal data structures | |
|
115 | and patterns that are loaded from sources that use the internal, | |
|
116 | prefixed pattern representation (but can't necessarily be fully trusted). | |
|
117 | """ | |
|
118 | if not isinstance(pats, set): | |
|
119 | raise error.ProgrammingError('narrow patterns should be a set; ' | |
|
120 | 'got %r' % pats) | |
|
121 | ||
|
122 | for pat in pats: | |
|
123 | if not pat.startswith(VALID_PREFIXES): | |
|
124 | # Use a Mercurial exception because this can happen due to user | |
|
125 | # bugs (e.g. manually updating spec file). | |
|
126 | raise error.Abort(_('invalid prefix on narrow pattern: %s') % pat, | |
|
127 | hint=_('narrow patterns must begin with one of ' | |
|
128 | 'the following: %s') % | |
|
129 | ', '.join(VALID_PREFIXES)) | |
|
87 | 130 | |
|
88 | 131 | def format(includes, excludes): |
|
89 | 132 | output = '[include]\n' |
@@ -16,6 +16,20 b'' | |||
|
16 | 16 | $ for x in `$TESTDIR/seq.py 20`; do echo $x > "t$x"; hg add "t$x"; hg commit -m "Commit test $x"; done |
|
17 | 17 | $ cd ../../.. |
|
18 | 18 | |
|
19 | Only path: and rootfilesin: pattern prefixes are allowed | |
|
20 | ||
|
21 | $ hg clone --narrow ssh://user@dummy/master badnarrow --noupdate --include 'glob:**' | |
|
22 | requesting all changes | |
|
23 | abort: invalid prefix on narrow pattern: glob:** | |
|
24 | (narrow patterns must begin with one of the following: path:, rootfilesin:) | |
|
25 | [255] | |
|
26 | ||
|
27 | $ hg clone --narrow ssh://user@dummy/master badnarrow --noupdate --exclude 'set:ignored' | |
|
28 | requesting all changes | |
|
29 | abort: invalid prefix on narrow pattern: set:ignored | |
|
30 | (narrow patterns must begin with one of the following: path:, rootfilesin:) | |
|
31 | [255] | |
|
32 | ||
|
19 | 33 | narrow clone a file, f10 |
|
20 | 34 | |
|
21 | 35 | $ hg clone --narrow ssh://user@dummy/master narrow --noupdate --include "dir/src/f10" |
@@ -254,3 +268,17 b' Testing the --narrowspec flag to clone' | |||
|
254 | 268 | I path:dir/tests |
|
255 | 269 | I path:file:dir/src/f12 |
|
256 | 270 | $ cd .. |
|
271 | ||
|
272 | Narrow spec with invalid patterns is rejected | |
|
273 | ||
|
274 | $ cat > narrowspecs <<EOF | |
|
275 | > [include] | |
|
276 | > glob:** | |
|
277 | > EOF | |
|
278 | ||
|
279 | $ hg clone ssh://user@dummy/master badspecfile --narrowspec narrowspecs | |
|
280 | reading narrowspec from '$TESTTMP/narrowspecs' | |
|
281 | requesting all changes | |
|
282 | abort: invalid prefix on narrow pattern: glob:** | |
|
283 | (narrow patterns must begin with one of the following: path:, rootfilesin:) | |
|
284 | [255] |
@@ -427,3 +427,15 b' clone a narrow portion of the master, su' | |||
|
427 | 427 | | |
|
428 | 428 | o 0 2a4f0c3b67da... root |
|
429 | 429 | |
|
430 | ||
|
431 | Illegal patterns are rejected | |
|
432 | ||
|
433 | $ hg tracked --addinclude glob:** | |
|
434 | abort: invalid prefix on narrow pattern: glob:** | |
|
435 | (narrow patterns must begin with one of the following: path:, rootfilesin:) | |
|
436 | [255] | |
|
437 | ||
|
438 | $ hg tracked --addexclude set:ignored | |
|
439 | abort: invalid prefix on narrow pattern: set:ignored | |
|
440 | (narrow patterns must begin with one of the following: path:, rootfilesin:) | |
|
441 | [255] |
General Comments 0
You need to be logged in to leave comments.
Login now