Show More
@@ -8,7 +8,8 b'' | |||||
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 | |
|
12 | import match as _match | |||
12 |
|
13 | |||
13 | revrangesep = ':' |
|
14 | revrangesep = ':' | |
14 |
|
15 | |||
@@ -223,24 +224,24 b' def make_file(repo, pat, node=None,' | |||||
223 | pathname), |
|
224 | pathname), | |
224 | mode) |
|
225 | mode) | |
225 |
|
226 | |||
226 |
def match |
|
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, |
|
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''' | |
@@ -277,7 +278,8 b' def addremove(repo, pats=[], opts={}, dr' | |||||
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) | |
@@ -316,7 +318,8 b' def copy(ui, repo, pats, opts, rename=Fa' | |||||
316 |
|
318 | |||
317 | def walkpat(pat): |
|
319 | def walkpat(pat): | |
318 | srcs = [] |
|
320 | srcs = [] | |
319 |
|
|
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 == '?': |
@@ -31,8 +31,9 b' def add(ui, repo, *pats, **opts):' | |||||
31 | rejected = None |
|
31 | rejected = None | |
32 | exacts = {} |
|
32 | exacts = {} | |
33 | names = [] |
|
33 | names = [] | |
34 |
|
|
34 | m = cmdutil.match(repo, pats, opts) | |
35 | badmatch=lambda x,y: True): |
|
35 | m.bad = lambda x,y: True | |
|
36 | for src, abs, rel, exact in cmdutil.walk(repo, m): | |||
36 | if exact: |
|
37 | if exact: | |
37 | if ui.verbose: |
|
38 | if ui.verbose: | |
38 | ui.status(_('adding %s\n') % rel) |
|
39 | ui.status(_('adding %s\n') % rel) | |
@@ -108,8 +109,8 b' def annotate(ui, repo, *pats, **opts):' | |||||
108 |
|
109 | |||
109 | ctx = repo.changectx(opts['rev']) |
|
110 | ctx = repo.changectx(opts['rev']) | |
110 |
|
111 | |||
111 |
|
|
112 | m = cmdutil.match(repo, pats, opts) | |
112 | node=ctx.node()): |
|
113 | for src, abs, rel, exact in cmdutil.walk(repo, m, ctx.node()): | |
113 | fctx = ctx.filectx(abs) |
|
114 | fctx = ctx.filectx(abs) | |
114 | if not opts['text'] and util.binary(fctx.data()): |
|
115 | if not opts['text'] and util.binary(fctx.data()): | |
115 | ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) |
|
116 | ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) | |
@@ -160,7 +161,7 b' def archive(ui, repo, dest, **opts):' | |||||
160 | dest = cmdutil.make_filename(repo, dest, node) |
|
161 | dest = cmdutil.make_filename(repo, dest, node) | |
161 | if os.path.realpath(dest) == repo.root: |
|
162 | if os.path.realpath(dest) == repo.root: | |
162 | raise util.Abort(_('repository root cannot be destination')) |
|
163 | raise util.Abort(_('repository root cannot be destination')) | |
163 |
|
|
164 | matchfn = cmdutil.match(repo, [], opts) | |
164 | kind = opts.get('type') or 'files' |
|
165 | kind = opts.get('type') or 'files' | |
165 | prefix = opts['prefix'] |
|
166 | prefix = opts['prefix'] | |
166 | if dest == '-': |
|
167 | if dest == '-': | |
@@ -487,8 +488,8 b' def cat(ui, repo, file1, *pats, **opts):' | |||||
487 | """ |
|
488 | """ | |
488 | ctx = repo.changectx(opts['rev']) |
|
489 | ctx = repo.changectx(opts['rev']) | |
489 | err = 1 |
|
490 | err = 1 | |
490 |
|
|
491 | m = cmdutil.match(repo, (file1,) + pats, opts) | |
491 | ctx.node()): |
|
492 | for src, abs, rel, exact in cmdutil.walk(repo, m, ctx.node()): | |
492 | fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs) |
|
493 | fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs) | |
493 | data = ctx.filectx(abs).data() |
|
494 | data = ctx.filectx(abs).data() | |
494 | if opts.get('decode'): |
|
495 | if opts.get('decode'): | |
@@ -913,18 +914,19 b' def debugrename(ui, repo, file1, *pats, ' | |||||
913 | """dump rename information""" |
|
914 | """dump rename information""" | |
914 |
|
915 | |||
915 | ctx = repo.changectx(opts.get('rev', 'tip')) |
|
916 | ctx = repo.changectx(opts.get('rev', 'tip')) | |
916 |
|
|
917 | m = cmdutil.match(repo, (file1,) + pats, opts) | |
917 | ctx.node()): |
|
918 | for src, abs, rel, exact in cmdutil.walk(repo, m, ctx.node()): | |
918 | fctx = ctx.filectx(abs) |
|
919 | fctx = ctx.filectx(abs) | |
919 |
|
|
920 | o = fctx.filelog().renamed(fctx.filenode()) | |
920 |
if |
|
921 | if o: | |
921 |
ui.write(_("%s renamed from %s:%s\n") % (rel, |
|
922 | ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1]))) | |
922 | else: |
|
923 | else: | |
923 | ui.write(_("%s not renamed\n") % rel) |
|
924 | ui.write(_("%s not renamed\n") % rel) | |
924 |
|
925 | |||
925 | def debugwalk(ui, repo, *pats, **opts): |
|
926 | def debugwalk(ui, repo, *pats, **opts): | |
926 | """show how files match on given patterns""" |
|
927 | """show how files match on given patterns""" | |
927 |
|
|
928 | m = cmdutil.match(repo, pats, opts) | |
|
929 | items = list(cmdutil.walk(repo, m)) | |||
928 | if not items: |
|
930 | if not items: | |
929 | return |
|
931 | return | |
930 | fmt = '%%s %%-%ds %%-%ds %%s' % ( |
|
932 | fmt = '%%s %%-%ds %%-%ds %%s' % ( | |
@@ -1695,9 +1697,9 b' def locate(ui, repo, *pats, **opts):' | |||||
1695 | node = None |
|
1697 | node = None | |
1696 |
|
1698 | |||
1697 | ret = 1 |
|
1699 | ret = 1 | |
1698 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node, |
|
1700 | m = cmdutil.match(repo, pats, opts, default='relglob') | |
1699 | badmatch=lambda x,y: True, |
|
1701 | m.bad = lambda x,y: True | |
1700 | default='relglob'): |
|
1702 | for src, abs, rel, exact in cmdutil.walk(repo, m, node): | |
1701 | if src == 'b': |
|
1703 | if src == 'b': | |
1702 | continue |
|
1704 | continue | |
1703 | if not node and abs not in repo.dirstate: |
|
1705 | if not node and abs not in repo.dirstate: | |
@@ -2185,7 +2187,8 b' def remove(ui, repo, *pats, **opts):' | |||||
2185 | modified, added, removed, deleted, unknown = mardu |
|
2187 | modified, added, removed, deleted, unknown = mardu | |
2186 |
|
2188 | |||
2187 | remove, forget = [], [] |
|
2189 | remove, forget = [], [] | |
2188 |
|
|
2190 | m = cmdutil.match(repo, pats, opts) | |
|
2191 | for src, abs, rel, exact in cmdutil.walk(repo, m): | |||
2189 |
|
2192 | |||
2190 | reason = None |
|
2193 | reason = None | |
2191 | if abs in removed or abs in unknown: |
|
2194 | if abs in removed or abs in unknown: | |
@@ -2339,15 +2342,19 b' def revert(ui, repo, *pats, **opts):' | |||||
2339 | try: |
|
2342 | try: | |
2340 | # walk dirstate. |
|
2343 | # walk dirstate. | |
2341 | files = [] |
|
2344 | files = [] | |
2342 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, |
|
2345 | ||
2343 | badmatch=mf.has_key): |
|
2346 | m = cmdutil.match(repo, pats, opts) | |
|
2347 | def bad(f, msg): | |||
|
2348 | if f not in mf: | |||
|
2349 | repo.ui.warn("%s: %s\n" % (m.rel(f), msg)) | |||
|
2350 | return False | |||
|
2351 | m.bad = bad | |||
|
2352 | for src, abs, rel, exact in cmdutil.walk(repo, m): | |||
2344 | names[abs] = (rel, exact) |
|
2353 | names[abs] = (rel, exact) | |
2345 | if src != 'b': |
|
|||
2346 | files.append(abs) |
|
|||
2347 |
|
2354 | |||
2348 | # walk target manifest. |
|
2355 | # walk target manifest. | |
2349 |
|
2356 | |||
2350 |
def bad |
|
2357 | def badfn(path, msg): | |
2351 | if path in names: |
|
2358 | if path in names: | |
2352 | return True |
|
2359 | return True | |
2353 | path_ = path + '/' |
|
2360 | path_ = path + '/' | |
@@ -2356,8 +2363,9 b' def revert(ui, repo, *pats, **opts):' | |||||
2356 | return True |
|
2363 | return True | |
2357 | return False |
|
2364 | return False | |
2358 |
|
2365 | |||
2359 |
|
|
2366 | m = cmdutil.match(repo, pats, opts) | |
2360 | badmatch=badmatch): |
|
2367 | m.bad = badfn | |
|
2368 | for src, abs, rel, exact in cmdutil.walk(repo, m, node=node): | |||
2361 | if abs in names or src == 'b': |
|
2369 | if abs in names or src == 'b': | |
2362 | continue |
|
2370 | continue | |
2363 | names[abs] = (rel, exact) |
|
2371 | names[abs] = (rel, exact) |
@@ -37,7 +37,7 b' no changes needed to a' | |||||
37 | %% should say file not managed |
|
37 | %% should say file not managed | |
38 | file not managed: q |
|
38 | file not managed: q | |
39 | %% should say file not found |
|
39 | %% should say file not found | |
40 |
notfound: No such file |
|
40 | notfound: No such file or directory | |
41 | A z |
|
41 | A z | |
42 | ? e.orig |
|
42 | ? e.orig | |
43 | %% should add a, remove d, forget z |
|
43 | %% should add a, remove d, forget z |
General Comments 0
You need to be logged in to leave comments.
Login now