Show More
@@ -39,40 +39,16 b' def relpath(repo, args):' | |||
|
39 | 39 | for x in args] |
|
40 | 40 | return args |
|
41 | 41 | |
|
42 |
def matchpats( |
|
|
43 | if not pats and not emptyok: | |
|
44 | raise Abort('at least one file name or pattern required') | |
|
45 | head = '' | |
|
46 | if opts.get('rootless'): head = '(?:.*/|)' | |
|
47 | def reify(name, tail): | |
|
48 | if name.startswith('re:'): | |
|
49 | return name[3:] | |
|
50 | elif name.startswith('glob:'): | |
|
51 | return head + util.globre(name[5:], '', tail) | |
|
52 | elif name.startswith('path:'): | |
|
53 | return '^' + re.escape(name[5:]) + '$' | |
|
54 | return head + util.globre(name, '', tail) | |
|
55 | cwdsep = cwd + os.sep | |
|
56 | def under(fn): | |
|
57 | if not cwd or fn.startswith(cwdsep): return True | |
|
58 | def matchfn(pats, tail, ifempty = util.always): | |
|
59 | if not pats: return ifempty | |
|
60 | pat = '(?:%s)' % '|'.join([reify(p, tail) for p in pats]) | |
|
61 | if cwd: pat = re.escape(cwd + os.sep) + pat | |
|
62 | ui.debug('regexp: %s\n' % pat) | |
|
63 | return re.compile(pat).match | |
|
64 | patmatch = matchfn(pats, '$') | |
|
65 | incmatch = matchfn(opts.get('include'), '(?:/|$)', under) | |
|
66 | excmatch = matchfn(opts.get('exclude'), '(?:/|$)', util.never) | |
|
67 | return lambda fn: (incmatch(fn) and not excmatch(fn) and | |
|
68 | (fn.endswith('/') or patmatch(fn))) | |
|
42 | def matchpats(cwd, pats = [], opts = {}, head = ''): | |
|
43 | return util.matcher(cwd, pats, opts.get('include'), | |
|
44 | opts.get('exclude'), head) | |
|
69 | 45 | |
|
70 |
def walk(repo, pats, opts, |
|
|
46 | def walk(repo, pats, opts, head = ''): | |
|
71 | 47 | cwd = repo.getcwd() |
|
48 | c = 0 | |
|
72 | 49 | if cwd: c = len(cwd) + 1 |
|
73 |
for src, fn in repo.walk(match = matchpats( |
|
|
74 |
|
|
|
75 | else: yield src, fn, fn | |
|
50 | for src, fn in repo.walk(match = matchpats(cwd, pats, opts, head)): | |
|
51 | yield src, fn, fn[c:] | |
|
76 | 52 | |
|
77 | 53 | revrangesep = ':' |
|
78 | 54 | |
@@ -709,10 +685,10 b' def init(ui, source=None):' | |||
|
709 | 685 | |
|
710 | 686 | def locate(ui, repo, *pats, **opts): |
|
711 | 687 | """locate files matching specific patterns""" |
|
688 | end = '\n' | |
|
712 | 689 | if opts['print0']: end = '\0' |
|
713 | else: end = '\n' | |
|
714 | opts['rootless'] = True | |
|
715 | for src, abs, rel in walk(repo, pats, opts): | |
|
690 | ||
|
691 | for src, abs, rel in walk(repo, pats, opts, '(?:.*/|)'): | |
|
716 | 692 | if repo.dirstate.state(abs) == '?': continue |
|
717 | 693 | if opts['fullpath']: |
|
718 | 694 | ui.write(os.path.join(repo.root, abs), end) |
@@ -998,8 +974,7 b' def status(ui, repo, *pats, **opts):' | |||
|
998 | 974 | R = removed |
|
999 | 975 | ? = not tracked''' |
|
1000 | 976 | |
|
1001 |
(c, a, d, u) = repo.changes(match = matchpats( |
|
|
1002 | pats, opts)) | |
|
977 | (c, a, d, u) = repo.changes(match = matchpats(repo.getcwd(), pats, opts)) | |
|
1003 | 978 | (c, a, d, u) = map(lambda x: relfilter(repo, x), (c, a, d, u)) |
|
1004 | 979 | |
|
1005 | 980 | for f in c: |
@@ -79,6 +79,37 b" def globre(pat, head = '^', tail = '$'):" | |||
|
79 | 79 | res += re.escape(c) |
|
80 | 80 | return head + res + tail |
|
81 | 81 | |
|
82 | def matcher(cwd, pats, inc, exc, head = ''): | |
|
83 | def regex(name, tail): | |
|
84 | '''convert a pattern into a regular expression''' | |
|
85 | if name.startswith('re:'): | |
|
86 | return name[3:] | |
|
87 | elif name.startswith('path:'): | |
|
88 | return '^' + re.escape(name[5:]) + '$' | |
|
89 | elif name.startswith('glob:'): | |
|
90 | return head + globre(name[5:], '', tail) | |
|
91 | return head + globre(name, '', tail) | |
|
92 | ||
|
93 | def under(fn): | |
|
94 | """check if fn is under our cwd""" | |
|
95 | return not cwd or fn.startswith(cwdsep) | |
|
96 | ||
|
97 | def matchfn(pats, tail): | |
|
98 | """build a matching function from a set of patterns""" | |
|
99 | if pats: | |
|
100 | pat = '(?:%s)' % '|'.join([regex(p, tail) for p in pats]) | |
|
101 | if cwd: | |
|
102 | pat = re.escape(cwd + os.sep) + pat | |
|
103 | return re.compile(pat).match | |
|
104 | ||
|
105 | cwdsep = cwd + os.sep | |
|
106 | patmatch = matchfn(pats, '$') or (lambda fn: True) | |
|
107 | incmatch = matchfn(inc, '(?:/|$)') or under | |
|
108 | excmatch = matchfn(exc, '(?:/|$)') or (lambda fn: False) | |
|
109 | ||
|
110 | return lambda fn: (incmatch(fn) and not excmatch(fn) and | |
|
111 | (fn.endswith('/') or patmatch(fn))) | |
|
112 | ||
|
82 | 113 | def system(cmd, errprefix=None): |
|
83 | 114 | """execute a shell command that must succeed""" |
|
84 | 115 | rc = os.system(cmd) |
General Comments 0
You need to be logged in to leave comments.
Login now