Mercurial > public > mercurial-scm > hg
comparison mercurial/cmdutil.py @ 6576:69f3e9ac7c56
walk: introduce match objects
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 12 May 2008 11:37:07 -0500 |
parents | e08e0367ba15 |
children | 569761919450 |
comparison
equal
deleted
inserted
replaced
6575:e08e0367ba15 | 6576:69f3e9ac7c56 |
---|---|
6 # of the GNU General Public License, incorporated herein by reference. | 6 # of the GNU General Public License, incorporated herein by reference. |
7 | 7 |
8 from node import hex, nullid, nullrev, short | 8 from node import hex, nullid, nullrev, short |
9 from i18n import _ | 9 from i18n import _ |
10 import os, sys, bisect, stat | 10 import os, sys, bisect, stat |
11 import mdiff, bdiff, util, templater, templatefilters, patch, errno | 11 import mdiff, bdiff, util, templater, templatefilters, patch, errno, match |
12 | 12 |
13 revrangesep = ':' | 13 revrangesep = ':' |
14 | 14 |
15 class UnknownCommand(Exception): | 15 class UnknownCommand(Exception): |
16 """Exception raised if command is not in the command table.""" | 16 """Exception raised if command is not in the command table.""" |
222 return open(make_filename(repo, pat, node, total, seqno, revwidth, | 222 return open(make_filename(repo, pat, node, total, seqno, revwidth, |
223 pathname), | 223 pathname), |
224 mode) | 224 mode) |
225 | 225 |
226 def matchpats(repo, pats=[], opts={}, globbed=False, default='relpath'): | 226 def matchpats(repo, pats=[], opts={}, globbed=False, default='relpath'): |
227 pats = pats or [] | |
228 if not globbed and default == 'relpath': | 227 if not globbed and default == 'relpath': |
229 pats = util.expand_glob(pats or []) | 228 pats = util.expand_glob(pats or []) |
230 return util.matcher(repo.root, repo.getcwd(), pats, opts.get('include'), | 229 m = match.match(repo.root, repo.getcwd(), pats, opts.get('include'), |
231 opts.get('exclude'), None, default) | 230 opts.get('exclude'), default) |
231 return m.files(), m, m.anypats() | |
232 | 232 |
233 def walk(repo, pats=[], opts={}, node=None, badmatch=None, globbed=False, | 233 def walk(repo, pats=[], opts={}, node=None, badmatch=None, globbed=False, |
234 default='relpath'): | 234 default='relpath'): |
235 files, matchfn, anypats = matchpats(repo, pats, opts, globbed=globbed, | 235 dummy, m, dummy = matchpats(repo, pats, opts, globbed, default) |
236 default=default) | 236 for src, fn in repo.walk(node=node, files=m.files(), match=m, |
237 exact = dict.fromkeys(files) | |
238 cwd = repo.getcwd() | |
239 for src, fn in repo.walk(node=node, files=files, match=matchfn, | |
240 badmatch=badmatch): | 237 badmatch=badmatch): |
241 yield src, fn, repo.pathto(fn, cwd), fn in exact | 238 yield src, fn, m.rel(fn), m.exact(fn) |
242 | 239 |
243 def findrenames(repo, added=None, removed=None, threshold=0.5): | 240 def findrenames(repo, added=None, removed=None, threshold=0.5): |
244 '''find renamed files -- yields (before, after, score) tuples''' | 241 '''find renamed files -- yields (before, after, score) tuples''' |
245 if added is None or removed is None: | 242 if added is None or removed is None: |
246 added, removed = repo.status()[1:3] | 243 added, removed = repo.status()[1:3] |