mirror of
https://github.com/facebook/sapling.git
synced 2024-10-08 07:49:11 +03:00
Merge walk fixes.
This commit is contained in:
commit
2f1759b049
@ -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
|
||||
|
53
tests/test-walk
Executable file
53
tests/test-walk
Executable file
@ -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
|
123
tests/test-walk.out
Normal file
123
tests/test-walk.out
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user