# HG changeset patch # User Alexis S. L. Carvalho # Date 1175671328 10800 # Node ID d4f0405fadacf90155d3b70775ea2e2ce2afc3e5 # Parent d69bdc1091b85814f75dd2af80d442cf00a369bc# Parent a5cde03cd01964983bc97324d3fff0a25e7fe46d Merge last few matcher/locate fixes. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1658,7 +1658,10 @@ def locate(ui, repo, *pats, **opts): ret = 1 for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node, + badmatch=util.always, default='relglob'): + if src == 'b': + continue if not node and repo.dirstate.state(abs) == '?': continue if opts['fullpath']: diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -447,7 +447,7 @@ def _matcher(canonroot, cwd, names, inc, if c in _globchars: return True return False - def regex(kind, name): + def regex(kind, name, tail): '''convert a pattern into a regular expression''' if not name: return '' @@ -456,23 +456,23 @@ def _matcher(canonroot, cwd, names, inc, elif kind == 'path': return '^' + re.escape(name) + '(?:/|$)' elif kind == 'relglob': - return globre(name, '(?:|.*/)', '(?:/|$)') + return globre(name, '(?:|.*/)', tail) elif kind == 'relpath': return re.escape(name) + '(?:/|$)' elif kind == 'relre': if name.startswith('^'): return name return '.*' + name - return globre(name, '', '(?:/|$)') + return globre(name, '', tail) - def matchfn(pats): + def matchfn(pats, tail): """build a matching function from a set of patterns""" if not pats: return matches = [] for k, p in pats: try: - pat = '(?:%s)' % regex(k, p) + pat = '(?:%s)' % regex(k, p, tail) matches.append(re.compile(pat).match) except re.error: if src: raise Abort("%s: invalid pattern (%s): %s" % (src, k, p)) @@ -520,15 +520,15 @@ def _matcher(canonroot, cwd, names, inc, roots, pats, anypats = normalizepats(names, dflt_pat) - patmatch = matchfn(pats) or always + patmatch = matchfn(pats, '$') or always incmatch = always if inc: dummy, inckinds, dummy = normalizepats(inc, 'glob') - incmatch = matchfn(inckinds) + incmatch = matchfn(inckinds, '(?:/|$)') excmatch = lambda fn: False if exc: dummy, exckinds, dummy = normalizepats(exc, 'glob') - excmatch = matchfn(exckinds) + excmatch = matchfn(exckinds, '(?:/|$)') if not names and inc and not exc: # common case: hgignore patterns diff --git a/tests/test-locate b/tests/test-locate --- a/tests/test-locate +++ b/tests/test-locate @@ -19,6 +19,8 @@ mkdir t echo 0 > t/x echo 0 > t/b echo 0 > t/e.h +mkdir dir.h +echo 0 > dir.h/foo hg ci -A -m m -d "1000000 0" touch nottracked hglocate a && echo locate succeeded || echo locate failed @@ -28,9 +30,11 @@ hg rm a hg ci -m m -d "1000000 0" hglocate a hglocate NONEXISTENT +hglocate relpath:NONEXISTENT hglocate hglocate -r 0 a hglocate -r 0 NONEXISTENT +hglocate -r 0 relpath:NONEXISTENT hglocate -r 0 echo % -I/-X with relative path should work cd t @@ -39,14 +43,14 @@ hglocate -I ../t # test issue294 cd .. rm -r t -hglocate t +hglocate 't/**' mkdir otherdir cd otherdir hglocate b hglocate '*.h' hglocate path:t/x -hglocate 're:.*\.h' +hglocate 're:.*\.h$' hglocate -r 0 b hglocate -r 0 '*.h' hglocate -r 0 path:t/x -hglocate -r 0 're:.*\.h' +hglocate -r 0 're:.*\.h$' diff --git a/tests/test-locate.out b/tests/test-locate.out --- a/tests/test-locate.out +++ b/tests/test-locate.out @@ -1,5 +1,6 @@ adding a adding b +adding dir.h/foo adding t.h adding t/b adding t/e.h @@ -14,6 +15,7 @@ locate failed hg locate a b +dir.h/foo t.h t/b t/e.h @@ -23,8 +25,11 @@ hg locate a hg locate NONEXISTENT +hg locate relpath:NONEXISTENT + hg locate b +dir.h/foo t.h t/b t/e.h @@ -35,9 +40,12 @@ a hg locate -r 0 NONEXISTENT +hg locate -r 0 relpath:NONEXISTENT + hg locate -r 0 a b +dir.h/foo t.h t/b t/e.h @@ -46,6 +54,7 @@ t/x % -I/-X with relative path should work hg locate b +dir.h/foo t.h t/b t/e.h @@ -56,7 +65,7 @@ t/b t/e.h t/x -hg locate t +hg locate t/** t/b t/e.h t/x @@ -72,7 +81,7 @@ hg locate *.h hg locate path:t/x ../t/x -hg locate re:.*\.h +hg locate re:.*\.h$ ../t.h ../t/e.h @@ -87,7 +96,7 @@ hg locate -r 0 *.h hg locate -r 0 path:t/x ../t/x -hg locate -r 0 re:.*\.h +hg locate -r 0 re:.*\.h$ ../t.h ../t/e.h diff --git a/tests/test-walk b/tests/test-walk --- a/tests/test-walk +++ b/tests/test-walk @@ -72,11 +72,13 @@ debugwalk beans/.hg #debugwalk `pwd`/beans #debugwalk `pwd`/.. debugwalk glob:\* +debugwalk 'glob:**e' debugwalk 're:.*[kb]$' debugwalk path:beans/black debugwalk path:beans//black debugwalk relglob:Procyonidae -debugwalk relglob:Procyonidae/ fennel +debugwalk 'relglob:Procyonidae/**' +debugwalk 'relglob:Procyonidae/**' fennel debugwalk beans 'glob:beans/*' debugwalk 'glob:mamm**' debugwalk 'glob:mamm**' fennel diff --git a/tests/test-walk.out b/tests/test-walk.out --- a/tests/test-walk.out +++ b/tests/test-walk.out @@ -210,20 +210,14 @@ hg debugwalk beans/.hg beans/.hg: No such file or directory hg debugwalk glob:* -f beans/black beans/black -f beans/borlotti beans/borlotti -f beans/kidney beans/kidney -f beans/navy beans/navy -f beans/pinto beans/pinto +f fennel fennel +f fenugreek fenugreek +f fiddlehead fiddlehead +f glob:glob glob:glob + +hg debugwalk glob:**e f beans/turtle beans/turtle -f fennel fennel -f fenugreek fenugreek -f fiddlehead fiddlehead -f glob:glob glob:glob f mammals/Procyonidae/cacomistle mammals/Procyonidae/cacomistle -f mammals/Procyonidae/coatimundi mammals/Procyonidae/coatimundi -f mammals/Procyonidae/raccoon mammals/Procyonidae/raccoon -f mammals/skunk mammals/skunk hg debugwalk re:.*[kb]$ f beans/black beans/black @@ -238,11 +232,13 @@ hg debugwalk path:beans//black f beans/black beans/black exact hg debugwalk relglob:Procyonidae + +hg debugwalk relglob:Procyonidae/** f mammals/Procyonidae/cacomistle mammals/Procyonidae/cacomistle f mammals/Procyonidae/coatimundi mammals/Procyonidae/coatimundi f mammals/Procyonidae/raccoon mammals/Procyonidae/raccoon -hg debugwalk relglob:Procyonidae/ fennel +hg debugwalk relglob:Procyonidae/** fennel f fennel fennel exact f mammals/Procyonidae/cacomistle mammals/Procyonidae/cacomistle f mammals/Procyonidae/coatimundi mammals/Procyonidae/coatimundi