# HG changeset patch # User Alexis S. L. Carvalho # Date 1175671325 10800 # Node ID 6cecaec07cc9a47757a939ac3dc7d6875d648a01 # Parent ef1f1a4b2efb70ae4f1fa37274f1626772575ece Revert changeset ef1f1a4b2efb; add another test for glob: patterns With that changeset, it's impossible to use a glob: pattern to match e.g. all files ending in .py - glob:**.py would also match all files in a directory called dir.py. diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -427,7 +427,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 '' @@ -443,16 +443,16 @@ def _matcher(canonroot, cwd, names, inc, 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)) @@ -500,15 +500,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-walk b/tests/test-walk --- a/tests/test-walk +++ b/tests/test-walk @@ -72,6 +72,7 @@ debugwalk beans/.hg #debugwalk `pwd`/beans #debugwalk `pwd`/.. debugwalk glob:\* +debugwalk 'glob:**e' debugwalk 're:.*[kb]$' debugwalk path:beans/black debugwalk path:beans//black 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