##// END OF EJS Templates
util._matcher: unify pattern normalization...
Alexis S. L. Carvalho -
r4192:9814d600 default
parent child Browse files
Show More
@@ -437,7 +437,7 b' def _matcher(canonroot, cwd, names, inc,'
437 elif kind == 'relglob':
437 elif kind == 'relglob':
438 return head + globre(name, '(?:|.*/)', '(?:/|$)')
438 return head + globre(name, '(?:|.*/)', '(?:/|$)')
439 elif kind == 'relpath':
439 elif kind == 'relpath':
440 return head + re.escape(name) + tail
440 return head + re.escape(name) + '(?:/|$)'
441 elif kind == 'relre':
441 elif kind == 'relre':
442 if name.startswith('^'):
442 if name.startswith('^'):
443 return name
443 return name
@@ -473,43 +473,45 b' def _matcher(canonroot, cwd, names, inc,'
473 root.append(p)
473 root.append(p)
474 return '/'.join(root) or '.'
474 return '/'.join(root) or '.'
475
475
476 pats = []
476 def normalizepats(names, default):
477 files = []
477 pats = []
478 roots = []
478 files = []
479 for kind, name in [patkind(p, dflt_pat) for p in names]:
479 roots = []
480 if kind in ('glob', 'relpath'):
480 anypats = False
481 name = canonpath(canonroot, cwd, name)
481 for kind, name in [patkind(p, default) for p in names]:
482 elif kind in ('relglob', 'path'):
482 if kind in ('glob', 'relpath'):
483 name = normpath(name)
483 name = canonpath(canonroot, cwd, name)
484 if kind in ('glob', 're', 'relglob'):
484 elif kind in ('relglob', 'path'):
485 pats.append((kind, name))
485 name = normpath(name)
486 if kind == 'glob':
486 if kind in ('glob', 're', 'relglob', 'relre'):
487 root = globprefix(name)
487 pats.append((kind, name))
488 roots.append(root)
488 anypats = True
489 elif kind in ('relpath', 'path'):
489 if kind == 'glob':
490 files.append((kind, name))
490 root = globprefix(name)
491 roots.append(name)
491 roots.append(root)
492 elif kind == 'relglob':
492 elif kind in ('relpath', 'path'):
493 roots.append('.')
493 files.append((kind, name))
494 roots.append(name)
495 elif kind == 'relglob':
496 roots.append('.')
497 return roots, pats + files, anypats
498
499 roots, pats, anypats = normalizepats(names, dflt_pat)
494
500
495 patmatch = matchfn(pats, '$') or always
501 patmatch = matchfn(pats, '$') or always
496 filematch = matchfn(files, '(?:/|$)') or always
497 incmatch = always
502 incmatch = always
498 if inc:
503 if inc:
499 inckinds = [patkind(canonpath(canonroot, cwd, i)) for i in inc]
504 dummy, inckinds, dummy = normalizepats(inc, 'glob')
500 incmatch = matchfn(inckinds, '(?:/|$)')
505 incmatch = matchfn(inckinds, '(?:/|$)')
501 excmatch = lambda fn: False
506 excmatch = lambda fn: False
502 if exc:
507 if exc:
503 exckinds = [patkind(canonpath(canonroot, cwd, x)) for x in exc]
508 dummy, exckinds, dummy = normalizepats(exc, 'glob')
504 excmatch = matchfn(exckinds, '(?:/|$)')
509 excmatch = matchfn(exckinds, '(?:/|$)')
505
510
506 return (roots,
511 return (roots,
507 lambda fn: (incmatch(fn) and not excmatch(fn) and
512 lambda fn: (incmatch(fn) and not excmatch(fn) and
508 (fn.endswith('/') or
513 (fn.endswith('/') or patmatch(fn))),
509 (not pats and not files) or
514 (inc or exc or anypats) and True)
510 (pats and patmatch(fn)) or
511 (files and filematch(fn)))),
512 (inc or exc or pats) and True)
513
515
514 def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None):
516 def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None):
515 '''enhanced shell command execution.
517 '''enhanced shell command execution.
@@ -35,6 +35,16 b' hg commit -m "commit #0" -d "1000000 0"'
35 debugwalk
35 debugwalk
36 debugwalk -I.
36 debugwalk -I.
37 chdir mammals
37 chdir mammals
38 debugwalk
39 debugwalk -X ../beans
40 debugwalk -I '*k'
41 debugwalk -I 'glob:*k'
42 debugwalk -I 'relglob:*k'
43 debugwalk -I 'relglob:*k' .
44 debugwalk -I 're:.*k$'
45 debugwalk -I 'relre:.*k$'
46 debugwalk -I 'path:beans'
47 debugwalk -I 'relpath:../beans'
38 debugwalk .
48 debugwalk .
39 debugwalk -I.
49 debugwalk -I.
40 debugwalk Procyonidae
50 debugwalk Procyonidae
@@ -46,6 +46,72 b' f mammals/skunk mamma'
46
46
47 cd mammals
47 cd mammals
48
48
49 hg debugwalk
50 f beans/black ../beans/black
51 f beans/borlotti ../beans/borlotti
52 f beans/kidney ../beans/kidney
53 f beans/navy ../beans/navy
54 f beans/pinto ../beans/pinto
55 f beans/turtle ../beans/turtle
56 f fennel ../fennel
57 f fenugreek ../fenugreek
58 f fiddlehead ../fiddlehead
59 f glob:glob ../glob:glob
60 f mammals/Procyonidae/cacomistle Procyonidae/cacomistle
61 f mammals/Procyonidae/coatimundi Procyonidae/coatimundi
62 f mammals/Procyonidae/raccoon Procyonidae/raccoon
63 f mammals/skunk skunk
64
65 hg debugwalk -X ../beans
66 f fennel ../fennel
67 f fenugreek ../fenugreek
68 f fiddlehead ../fiddlehead
69 f glob:glob ../glob:glob
70 f mammals/Procyonidae/cacomistle Procyonidae/cacomistle
71 f mammals/Procyonidae/coatimundi Procyonidae/coatimundi
72 f mammals/Procyonidae/raccoon Procyonidae/raccoon
73 f mammals/skunk skunk
74
75 hg debugwalk -I *k
76 m mammals/skunk skunk
77
78 hg debugwalk -I glob:*k
79 m mammals/skunk skunk
80
81 hg debugwalk -I relglob:*k
82 f fenugreek ../fenugreek
83 m beans/black ../beans/black
84 m mammals/skunk skunk
85
86 hg debugwalk -I relglob:*k .
87 f mammals/skunk skunk
88
89 hg debugwalk -I re:.*k$
90 f fenugreek ../fenugreek
91 m beans/black ../beans/black
92 m mammals/skunk skunk
93
94 hg debugwalk -I relre:.*k$
95 f fenugreek ../fenugreek
96 m beans/black ../beans/black
97 m mammals/skunk skunk
98
99 hg debugwalk -I path:beans
100 f beans/black ../beans/black
101 f beans/borlotti ../beans/borlotti
102 f beans/kidney ../beans/kidney
103 f beans/navy ../beans/navy
104 f beans/pinto ../beans/pinto
105 f beans/turtle ../beans/turtle
106
107 hg debugwalk -I relpath:../beans
108 f beans/black ../beans/black
109 f beans/borlotti ../beans/borlotti
110 f beans/kidney ../beans/kidney
111 f beans/navy ../beans/navy
112 f beans/pinto ../beans/pinto
113 f beans/turtle ../beans/turtle
114
49 hg debugwalk .
115 hg debugwalk .
50 f mammals/Procyonidae/cacomistle Procyonidae/cacomistle
116 f mammals/Procyonidae/cacomistle Procyonidae/cacomistle
51 f mammals/Procyonidae/coatimundi Procyonidae/coatimundi
117 f mammals/Procyonidae/coatimundi Procyonidae/coatimundi
General Comments 0
You need to be logged in to leave comments. Login now