##// END OF EJS Templates
Merge last few matcher/locate fixes.
Alexis S. L. Carvalho -
r4309:d4f0405f merge default
parent child Browse files
Show More
@@ -1658,7 +1658,10 b' def locate(ui, repo, *pats, **opts):'
1658
1658
1659 ret = 1
1659 ret = 1
1660 for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node,
1660 for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node,
1661 badmatch=util.always,
1661 default='relglob'):
1662 default='relglob'):
1663 if src == 'b':
1664 continue
1662 if not node and repo.dirstate.state(abs) == '?':
1665 if not node and repo.dirstate.state(abs) == '?':
1663 continue
1666 continue
1664 if opts['fullpath']:
1667 if opts['fullpath']:
@@ -447,7 +447,7 b' def _matcher(canonroot, cwd, names, inc,'
447 if c in _globchars: return True
447 if c in _globchars: return True
448 return False
448 return False
449
449
450 def regex(kind, name):
450 def regex(kind, name, tail):
451 '''convert a pattern into a regular expression'''
451 '''convert a pattern into a regular expression'''
452 if not name:
452 if not name:
453 return ''
453 return ''
@@ -456,23 +456,23 b' def _matcher(canonroot, cwd, names, inc,'
456 elif kind == 'path':
456 elif kind == 'path':
457 return '^' + re.escape(name) + '(?:/|$)'
457 return '^' + re.escape(name) + '(?:/|$)'
458 elif kind == 'relglob':
458 elif kind == 'relglob':
459 return globre(name, '(?:|.*/)', '(?:/|$)')
459 return globre(name, '(?:|.*/)', tail)
460 elif kind == 'relpath':
460 elif kind == 'relpath':
461 return re.escape(name) + '(?:/|$)'
461 return re.escape(name) + '(?:/|$)'
462 elif kind == 'relre':
462 elif kind == 'relre':
463 if name.startswith('^'):
463 if name.startswith('^'):
464 return name
464 return name
465 return '.*' + name
465 return '.*' + name
466 return globre(name, '', '(?:/|$)')
466 return globre(name, '', tail)
467
467
468 def matchfn(pats):
468 def matchfn(pats, tail):
469 """build a matching function from a set of patterns"""
469 """build a matching function from a set of patterns"""
470 if not pats:
470 if not pats:
471 return
471 return
472 matches = []
472 matches = []
473 for k, p in pats:
473 for k, p in pats:
474 try:
474 try:
475 pat = '(?:%s)' % regex(k, p)
475 pat = '(?:%s)' % regex(k, p, tail)
476 matches.append(re.compile(pat).match)
476 matches.append(re.compile(pat).match)
477 except re.error:
477 except re.error:
478 if src: raise Abort("%s: invalid pattern (%s): %s" % (src, k, p))
478 if src: raise Abort("%s: invalid pattern (%s): %s" % (src, k, p))
@@ -520,15 +520,15 b' def _matcher(canonroot, cwd, names, inc,'
520
520
521 roots, pats, anypats = normalizepats(names, dflt_pat)
521 roots, pats, anypats = normalizepats(names, dflt_pat)
522
522
523 patmatch = matchfn(pats) or always
523 patmatch = matchfn(pats, '$') or always
524 incmatch = always
524 incmatch = always
525 if inc:
525 if inc:
526 dummy, inckinds, dummy = normalizepats(inc, 'glob')
526 dummy, inckinds, dummy = normalizepats(inc, 'glob')
527 incmatch = matchfn(inckinds)
527 incmatch = matchfn(inckinds, '(?:/|$)')
528 excmatch = lambda fn: False
528 excmatch = lambda fn: False
529 if exc:
529 if exc:
530 dummy, exckinds, dummy = normalizepats(exc, 'glob')
530 dummy, exckinds, dummy = normalizepats(exc, 'glob')
531 excmatch = matchfn(exckinds)
531 excmatch = matchfn(exckinds, '(?:/|$)')
532
532
533 if not names and inc and not exc:
533 if not names and inc and not exc:
534 # common case: hgignore patterns
534 # common case: hgignore patterns
@@ -19,6 +19,8 b' mkdir t'
19 echo 0 > t/x
19 echo 0 > t/x
20 echo 0 > t/b
20 echo 0 > t/b
21 echo 0 > t/e.h
21 echo 0 > t/e.h
22 mkdir dir.h
23 echo 0 > dir.h/foo
22 hg ci -A -m m -d "1000000 0"
24 hg ci -A -m m -d "1000000 0"
23 touch nottracked
25 touch nottracked
24 hglocate a && echo locate succeeded || echo locate failed
26 hglocate a && echo locate succeeded || echo locate failed
@@ -28,9 +30,11 b' hg rm a'
28 hg ci -m m -d "1000000 0"
30 hg ci -m m -d "1000000 0"
29 hglocate a
31 hglocate a
30 hglocate NONEXISTENT
32 hglocate NONEXISTENT
33 hglocate relpath:NONEXISTENT
31 hglocate
34 hglocate
32 hglocate -r 0 a
35 hglocate -r 0 a
33 hglocate -r 0 NONEXISTENT
36 hglocate -r 0 NONEXISTENT
37 hglocate -r 0 relpath:NONEXISTENT
34 hglocate -r 0
38 hglocate -r 0
35 echo % -I/-X with relative path should work
39 echo % -I/-X with relative path should work
36 cd t
40 cd t
@@ -39,14 +43,14 b' hglocate -I ../t'
39 # test issue294
43 # test issue294
40 cd ..
44 cd ..
41 rm -r t
45 rm -r t
42 hglocate t
46 hglocate 't/**'
43 mkdir otherdir
47 mkdir otherdir
44 cd otherdir
48 cd otherdir
45 hglocate b
49 hglocate b
46 hglocate '*.h'
50 hglocate '*.h'
47 hglocate path:t/x
51 hglocate path:t/x
48 hglocate 're:.*\.h'
52 hglocate 're:.*\.h$'
49 hglocate -r 0 b
53 hglocate -r 0 b
50 hglocate -r 0 '*.h'
54 hglocate -r 0 '*.h'
51 hglocate -r 0 path:t/x
55 hglocate -r 0 path:t/x
52 hglocate -r 0 're:.*\.h'
56 hglocate -r 0 're:.*\.h$'
@@ -1,5 +1,6 b''
1 adding a
1 adding a
2 adding b
2 adding b
3 adding dir.h/foo
3 adding t.h
4 adding t.h
4 adding t/b
5 adding t/b
5 adding t/e.h
6 adding t/e.h
@@ -14,6 +15,7 b' locate failed'
14 hg locate
15 hg locate
15 a
16 a
16 b
17 b
18 dir.h/foo
17 t.h
19 t.h
18 t/b
20 t/b
19 t/e.h
21 t/e.h
@@ -23,8 +25,11 b' hg locate a'
23
25
24 hg locate NONEXISTENT
26 hg locate NONEXISTENT
25
27
28 hg locate relpath:NONEXISTENT
29
26 hg locate
30 hg locate
27 b
31 b
32 dir.h/foo
28 t.h
33 t.h
29 t/b
34 t/b
30 t/e.h
35 t/e.h
@@ -35,9 +40,12 b' a'
35
40
36 hg locate -r 0 NONEXISTENT
41 hg locate -r 0 NONEXISTENT
37
42
43 hg locate -r 0 relpath:NONEXISTENT
44
38 hg locate -r 0
45 hg locate -r 0
39 a
46 a
40 b
47 b
48 dir.h/foo
41 t.h
49 t.h
42 t/b
50 t/b
43 t/e.h
51 t/e.h
@@ -46,6 +54,7 b' t/x'
46 % -I/-X with relative path should work
54 % -I/-X with relative path should work
47 hg locate
55 hg locate
48 b
56 b
57 dir.h/foo
49 t.h
58 t.h
50 t/b
59 t/b
51 t/e.h
60 t/e.h
@@ -56,7 +65,7 b' t/b'
56 t/e.h
65 t/e.h
57 t/x
66 t/x
58
67
59 hg locate t
68 hg locate t/**
60 t/b
69 t/b
61 t/e.h
70 t/e.h
62 t/x
71 t/x
@@ -72,7 +81,7 b' hg locate *.h'
72 hg locate path:t/x
81 hg locate path:t/x
73 ../t/x
82 ../t/x
74
83
75 hg locate re:.*\.h
84 hg locate re:.*\.h$
76 ../t.h
85 ../t.h
77 ../t/e.h
86 ../t/e.h
78
87
@@ -87,7 +96,7 b' hg locate -r 0 *.h'
87 hg locate -r 0 path:t/x
96 hg locate -r 0 path:t/x
88 ../t/x
97 ../t/x
89
98
90 hg locate -r 0 re:.*\.h
99 hg locate -r 0 re:.*\.h$
91 ../t.h
100 ../t.h
92 ../t/e.h
101 ../t/e.h
93
102
@@ -72,11 +72,13 b' debugwalk beans/.hg'
72 #debugwalk `pwd`/beans
72 #debugwalk `pwd`/beans
73 #debugwalk `pwd`/..
73 #debugwalk `pwd`/..
74 debugwalk glob:\*
74 debugwalk glob:\*
75 debugwalk 'glob:**e'
75 debugwalk 're:.*[kb]$'
76 debugwalk 're:.*[kb]$'
76 debugwalk path:beans/black
77 debugwalk path:beans/black
77 debugwalk path:beans//black
78 debugwalk path:beans//black
78 debugwalk relglob:Procyonidae
79 debugwalk relglob:Procyonidae
79 debugwalk relglob:Procyonidae/ fennel
80 debugwalk 'relglob:Procyonidae/**'
81 debugwalk 'relglob:Procyonidae/**' fennel
80 debugwalk beans 'glob:beans/*'
82 debugwalk beans 'glob:beans/*'
81 debugwalk 'glob:mamm**'
83 debugwalk 'glob:mamm**'
82 debugwalk 'glob:mamm**' fennel
84 debugwalk 'glob:mamm**' fennel
@@ -210,20 +210,14 b' hg debugwalk beans/.hg'
210 beans/.hg: No such file or directory
210 beans/.hg: No such file or directory
211
211
212 hg debugwalk glob:*
212 hg debugwalk glob:*
213 f beans/black beans/black
213 f fennel fennel
214 f beans/borlotti beans/borlotti
214 f fenugreek fenugreek
215 f beans/kidney beans/kidney
215 f fiddlehead fiddlehead
216 f beans/navy beans/navy
216 f glob:glob glob:glob
217 f beans/pinto beans/pinto
217
218 hg debugwalk glob:**e
218 f beans/turtle beans/turtle
219 f beans/turtle beans/turtle
219 f fennel fennel
220 f fenugreek fenugreek
221 f fiddlehead fiddlehead
222 f glob:glob glob:glob
223 f mammals/Procyonidae/cacomistle mammals/Procyonidae/cacomistle
220 f mammals/Procyonidae/cacomistle mammals/Procyonidae/cacomistle
224 f mammals/Procyonidae/coatimundi mammals/Procyonidae/coatimundi
225 f mammals/Procyonidae/raccoon mammals/Procyonidae/raccoon
226 f mammals/skunk mammals/skunk
227
221
228 hg debugwalk re:.*[kb]$
222 hg debugwalk re:.*[kb]$
229 f beans/black beans/black
223 f beans/black beans/black
@@ -238,11 +232,13 b' hg debugwalk path:beans//black'
238 f beans/black beans/black exact
232 f beans/black beans/black exact
239
233
240 hg debugwalk relglob:Procyonidae
234 hg debugwalk relglob:Procyonidae
235
236 hg debugwalk relglob:Procyonidae/**
241 f mammals/Procyonidae/cacomistle mammals/Procyonidae/cacomistle
237 f mammals/Procyonidae/cacomistle mammals/Procyonidae/cacomistle
242 f mammals/Procyonidae/coatimundi mammals/Procyonidae/coatimundi
238 f mammals/Procyonidae/coatimundi mammals/Procyonidae/coatimundi
243 f mammals/Procyonidae/raccoon mammals/Procyonidae/raccoon
239 f mammals/Procyonidae/raccoon mammals/Procyonidae/raccoon
244
240
245 hg debugwalk relglob:Procyonidae/ fennel
241 hg debugwalk relglob:Procyonidae/** fennel
246 f fennel fennel exact
242 f fennel fennel exact
247 f mammals/Procyonidae/cacomistle mammals/Procyonidae/cacomistle
243 f mammals/Procyonidae/cacomistle mammals/Procyonidae/cacomistle
248 f mammals/Procyonidae/coatimundi mammals/Procyonidae/coatimundi
244 f mammals/Procyonidae/coatimundi mammals/Procyonidae/coatimundi
General Comments 0
You need to be logged in to leave comments. Login now