From 3891eab8ea3ff42ac89a4edb6154a9d1be465c7a Mon Sep 17 00:00:00 2001 From: Bryan O'Sullivan Date: Fri, 12 Aug 2005 16:09:17 -0800 Subject: [PATCH 1/2] Fix up handling of regexp paths. --- mercurial/util.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/mercurial/util.py b/mercurial/util.py index 1af51e5a23..1c96c031d8 100644 --- a/mercurial/util.py +++ b/mercurial/util.py @@ -95,25 +95,26 @@ def canonpath(repo, cwd, myname): def matcher(repo, cwd, names, inc, exc, head = ''): def patkind(name): - for prefix in 're:', 'glob:', 'path:': + for prefix in 're:', 'glob:', 'path:', 'relpath:': if name.startswith(prefix): return name.split(':', 1) for c in name: if c in _globchars: return 'glob', name return 'relpath', name - def regex(name, tail): + def regex(kind, name, tail): '''convert a pattern into a regular expression''' - kind, name = patkind(name) if kind == 're': return name elif kind == 'path': - return '^' + re.escape(name) + '$' + return '^' + re.escape(name) + '(?:/|$)' + elif kind == 'relpath': + return head + re.escape(name) + tail return head + globre(name, '', tail) def matchfn(pats, tail): """build a matching function from a set of patterns""" if pats: - pat = '(?:%s)' % '|'.join([regex(p, tail) for p in pats]) + pat = '(?:%s)' % '|'.join([regex(k, p, tail) for (k, p) in pats]) return re.compile(pat).match def globprefix(pat): @@ -132,19 +133,19 @@ def matcher(repo, cwd, names, inc, exc, head = ''): name = canonpath(repo, cwd, name) if name == '': kind, name = 'glob', '**' - if kind in ('glob', 're'): - pats.append(name) + if kind in ('glob', 'path', 're'): + pats.append((kind, name)) if kind == 'glob': root = globprefix(name) if root: roots.append(root) elif kind == 'relpath': - files.append(name) + files.append((kind, name)) roots.append(name) patmatch = matchfn(pats, '$') or always filematch = matchfn(files, '(?:/|$)') or always - incmatch = matchfn(inc, '(?:/|$)') or always - excmatch = matchfn(exc, '(?:/|$)') or (lambda fn: False) + incmatch = matchfn(map(patkind, inc), '(?:/|$)') or always + excmatch = matchfn(map(patkind, exc), '(?:/|$)') or (lambda fn: False) return roots, lambda fn: (incmatch(fn) and not excmatch(fn) and (fn.endswith('/') or From 2178d73055a2fe2f0eb93e43f9adde8b36b19342 Mon Sep 17 00:00:00 2001 From: Bryan O'Sullivan Date: Fri, 12 Aug 2005 16:10:09 -0800 Subject: [PATCH 2/2] Add unit tests for walk code. --- tests/test-walk | 53 +++++++++++++++++++ tests/test-walk.out | 123 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 176 insertions(+) create mode 100755 tests/test-walk create mode 100644 tests/test-walk.out diff --git a/tests/test-walk b/tests/test-walk new file mode 100755 index 0000000000..2cf4746fe5 --- /dev/null +++ b/tests/test-walk @@ -0,0 +1,53 @@ +#!/bin/sh + +mkdir t +cd t +hg init +mkdir -p beans +for b in kidney navy turtle borlotti black pinto; do + echo $b > beans/$b +done +mkdir -p mammals/Procyonidae +for m in cacomistle coatimundi raccoon; do + echo $m > mammals/Procyonidae/$m +done +echo skunk > mammals/skunk +echo fennel > fennel +echo fenugreek > fenugreek +echo fiddlehead > fiddlehead +echo glob:glob > glob:glob +hg addremove +hg commit -m "commit #0" -d "0 0" +hg debugwalk +cd mammals +hg debugwalk +hg debugwalk Procyonidae +cd Procyonidae +hg debugwalk +hg debugwalk .. +cd .. +hg debugwalk ../beans +hg debugwalk +cd .. +hg debugwalk -Ibeans +hg debugwalk 'mammals/../beans/b*' +hg debugwalk '-X*/Procyonidae' mammals +hg debugwalk path:mammals +hg debugwalk .. +hg debugwalk beans/../.. +hg debugwalk `pwd`/beans +hg debugwalk `pwd`/.. +hg debugwalk glob:\* +hg debugwalk 're:.*[kb]$' +hg debugwalk path:beans/black +hg debugwalk beans 'beans/*' +hg debugwalk 'j*' +hg debugwalk NOEXIST +mkfifo fifo +hg debugwalk fifo +rm fenugreek +hg debugwalk fenugreek +hg rm fenugreek +hg debugwalk fenugreek +touch new +hg debugwalk new diff --git a/tests/test-walk.out b/tests/test-walk.out new file mode 100644 index 0000000000..87226bd890 --- /dev/null +++ b/tests/test-walk.out @@ -0,0 +1,123 @@ ++ hg init ++ hg addremove +adding fennel +adding fenugreek +adding fiddlehead +adding glob:glob +adding beans/black +adding beans/borlotti +adding beans/kidney +adding beans/navy +adding beans/pinto +adding beans/turtle +adding mammals/skunk +adding mammals/Procyonidae/cacomistle +adding mammals/Procyonidae/coatimundi +adding mammals/Procyonidae/raccoon ++ hg commit -m commit #0 -d 0 0 ++ hg debugwalk +f fennel fennel +f fenugreek fenugreek +f fiddlehead fiddlehead +f glob:glob glob: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 beans/turtle beans/turtle +f mammals/skunk mammals/skunk +f mammals/Procyonidae/cacomistle mammals/Procyonidae/cacomistle +f mammals/Procyonidae/coatimundi mammals/Procyonidae/coatimundi +f mammals/Procyonidae/raccoon mammals/Procyonidae/raccoon ++ hg debugwalk +f mammals/skunk skunk +f mammals/Procyonidae/cacomistle Procyonidae/cacomistle +f mammals/Procyonidae/coatimundi Procyonidae/coatimundi +f mammals/Procyonidae/raccoon Procyonidae/raccoon ++ hg debugwalk Procyonidae +f mammals/Procyonidae/cacomistle Procyonidae/cacomistle +f mammals/Procyonidae/coatimundi Procyonidae/coatimundi +f mammals/Procyonidae/raccoon Procyonidae/raccoon ++ hg debugwalk +f mammals/Procyonidae/cacomistle cacomistle +f mammals/Procyonidae/coatimundi coatimundi +f mammals/Procyonidae/raccoon raccoon ++ hg debugwalk .. +f mammals/skunk ../skunk +f mammals/Procyonidae/cacomistle cacomistle +f mammals/Procyonidae/coatimundi coatimundi +f mammals/Procyonidae/raccoon raccoon ++ hg debugwalk ../beans +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 beans/turtle ../beans/turtle ++ hg debugwalk +f mammals/skunk skunk +f mammals/Procyonidae/cacomistle Procyonidae/cacomistle +f mammals/Procyonidae/coatimundi Procyonidae/coatimundi +f mammals/Procyonidae/raccoon Procyonidae/raccoon ++ hg debugwalk -Ibeans +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 beans/turtle beans/turtle ++ hg debugwalk mammals/../beans/b* +f beans/black beans/black +f beans/borlotti beans/borlotti ++ hg debugwalk -X*/Procyonidae mammals +f mammals/skunk mammals/skunk ++ hg debugwalk path:mammals +f mammals/skunk mammals/skunk +f mammals/Procyonidae/cacomistle mammals/Procyonidae/cacomistle +f mammals/Procyonidae/coatimundi mammals/Procyonidae/coatimundi +f mammals/Procyonidae/raccoon mammals/Procyonidae/raccoon ++ hg debugwalk .. +abort: .. not under repository root ++ hg debugwalk beans/../.. +abort: beans/../.. not under repository root ++ hg debugwalk /tmp/hgtests.15784.14760.4713.20670/test-walk/t/beans +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 beans/turtle beans/turtle ++ hg debugwalk /tmp/hgtests.15784.14760.4713.20670/test-walk/t/.. +abort: /tmp/hgtests.15784.14760.4713.20670/test-walk/t/.. not under repository root ++ hg debugwalk glob:* +f fennel fennel +f fenugreek fenugreek +f fiddlehead fiddlehead +f glob:glob glob:glob ++ hg debugwalk re:.*[kb]$ +f fenugreek fenugreek +f glob:glob glob:glob +f beans/black beans/black +f mammals/skunk mammals/skunk ++ hg debugwalk path:beans/black +f beans/black beans/black ++ hg debugwalk beans beans/* +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 beans/turtle beans/turtle ++ hg debugwalk j* ++ hg debugwalk NOEXIST +NOEXIST: No such file or directory ++ hg debugwalk fifo +fifo: unsupported file type (type is fifo) ++ hg debugwalk fenugreek +m fenugreek fenugreek ++ hg rm fenugreek ++ hg debugwalk fenugreek +m fenugreek fenugreek ++ hg debugwalk new +f new new