Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/cmdutil.py @ 6579:0159b7a36184
walk: pass match object to cmdutil.walk
- introduce cmdutil.match
- change args to cmdutil.walk
- create match objects for walk calls
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 12 May 2008 11:37:07 -0500 |
parents | f242d3684f83 |
children | da2a20d2ba3d |
comparison
equal
deleted
inserted
replaced
6578:f242d3684f83 | 6579:0159b7a36184 |
---|---|
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, match | 11 import mdiff, bdiff, util, templater, templatefilters, patch, errno |
12 import match as _match | |
12 | 13 |
13 revrangesep = ':' | 14 revrangesep = ':' |
14 | 15 |
15 class UnknownCommand(Exception): | 16 class UnknownCommand(Exception): |
16 """Exception raised if command is not in the command table.""" | 17 """Exception raised if command is not in the command table.""" |
221 return pat | 222 return pat |
222 return open(make_filename(repo, pat, node, total, seqno, revwidth, | 223 return open(make_filename(repo, pat, node, total, seqno, revwidth, |
223 pathname), | 224 pathname), |
224 mode) | 225 mode) |
225 | 226 |
226 def matchpats(repo, pats=[], opts={}, globbed=False, default='relpath'): | 227 def match(repo, pats=[], opts={}, globbed=False, default='relpath'): |
227 if not globbed and default == 'relpath': | 228 if not globbed and default == 'relpath': |
228 pats = util.expand_glob(pats or []) | 229 pats = util.expand_glob(pats or []) |
229 m = match.match(repo.root, repo.getcwd(), pats, opts.get('include'), | 230 m = _match.match(repo.root, repo.getcwd(), pats, |
230 opts.get('exclude'), default) | 231 opts.get('include'), opts.get('exclude'), default) |
231 def badfn(f, msg): | 232 def badfn(f, msg): |
232 repo.ui.warn("%s: %s\n" % (m.rel(f), msg)) | 233 repo.ui.warn("%s: %s\n" % (m.rel(f), msg)) |
233 return False | 234 return False |
234 m.bad = badfn | 235 m.bad = badfn |
236 return m | |
237 | |
238 def matchpats(repo, pats=[], opts={}, globbed=False, default='relpath'): | |
239 m = match(repo, pats, opts, globbed, default) | |
235 return m.files(), m, m.anypats() | 240 return m.files(), m, m.anypats() |
236 | 241 |
237 def walk(repo, pats=[], opts={}, node=None, badmatch=None, globbed=False, | 242 def walk(repo, match, node=None): |
238 default='relpath'): | 243 for src, fn in repo.walk(node, match): |
239 dummy, m, dummy = matchpats(repo, pats, opts, globbed, default) | 244 yield src, fn, match.rel(fn), match.exact(fn) |
240 if badmatch: | |
241 m.bad = badmatch | |
242 for src, fn in repo.walk(node, m): | |
243 yield src, fn, m.rel(fn), m.exact(fn) | |
244 | 245 |
245 def findrenames(repo, added=None, removed=None, threshold=0.5): | 246 def findrenames(repo, added=None, removed=None, threshold=0.5): |
246 '''find renamed files -- yields (before, after, score) tuples''' | 247 '''find renamed files -- yields (before, after, score) tuples''' |
247 if added is None or removed is None: | 248 if added is None or removed is None: |
248 added, removed = repo.status()[1:3] | 249 added, removed = repo.status()[1:3] |
275 dry_run = opts.get('dry_run') | 276 dry_run = opts.get('dry_run') |
276 if similarity is None: | 277 if similarity is None: |
277 similarity = float(opts.get('similarity') or 0) | 278 similarity = float(opts.get('similarity') or 0) |
278 add, remove = [], [] | 279 add, remove = [], [] |
279 mapping = {} | 280 mapping = {} |
280 for src, abs, rel, exact in walk(repo, pats, opts): | 281 m = match(repo, pats, opts) |
282 for src, abs, rel, exact in walk(repo, m): | |
281 target = repo.wjoin(abs) | 283 target = repo.wjoin(abs) |
282 if src == 'f' and abs not in repo.dirstate: | 284 if src == 'f' and abs not in repo.dirstate: |
283 add.append(abs) | 285 add.append(abs) |
284 mapping[abs] = rel, exact | 286 mapping[abs] = rel, exact |
285 if repo.ui.verbose or not exact: | 287 if repo.ui.verbose or not exact: |
314 after = opts.get("after") | 316 after = opts.get("after") |
315 dryrun = opts.get("dry_run") | 317 dryrun = opts.get("dry_run") |
316 | 318 |
317 def walkpat(pat): | 319 def walkpat(pat): |
318 srcs = [] | 320 srcs = [] |
319 for tag, abs, rel, exact in walk(repo, [pat], opts, globbed=True): | 321 m = match(repo, [pat], opts, globbed=True) |
322 for tag, abs, rel, exact in walk(repo, m): | |
320 state = repo.dirstate[abs] | 323 state = repo.dirstate[abs] |
321 if state in '?r': | 324 if state in '?r': |
322 if exact and state == '?': | 325 if exact and state == '?': |
323 ui.warn(_('%s: not copying - file is not managed\n') % rel) | 326 ui.warn(_('%s: not copying - file is not managed\n') % rel) |
324 if exact and state == 'r': | 327 if exact and state == 'r': |