Show More
@@ -8,6 +8,7 b'' | |||
|
8 | 8 | from demandload import demandload |
|
9 | 9 | from node import * |
|
10 | 10 | from i18n import gettext as _ |
|
11 | demandload(globals(), 'util') | |
|
11 | 12 | demandload(globals(), 'os sys') |
|
12 | 13 | |
|
13 | 14 | def make_filename(repo, pat, node, |
@@ -66,3 +67,26 b' def make_file(repo, pat, node=None,' | |||
|
66 | 67 | return open(make_filename(repo, pat, node, total, seqno, revwidth, |
|
67 | 68 | pathname), |
|
68 | 69 | mode) |
|
70 | ||
|
71 | def matchpats(repo, pats=[], opts={}, head=''): | |
|
72 | cwd = repo.getcwd() | |
|
73 | if not pats and cwd: | |
|
74 | opts['include'] = [os.path.join(cwd, i) for i in opts['include']] | |
|
75 | opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']] | |
|
76 | cwd = '' | |
|
77 | return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), | |
|
78 | opts.get('exclude'), head) | |
|
79 | ||
|
80 | def makewalk(repo, pats, opts, node=None, head='', badmatch=None): | |
|
81 | files, matchfn, anypats = matchpats(repo, pats, opts, head) | |
|
82 | exact = dict(zip(files, files)) | |
|
83 | def walk(): | |
|
84 | for src, fn in repo.walk(node=node, files=files, match=matchfn, | |
|
85 | badmatch=badmatch): | |
|
86 | yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact | |
|
87 | return files, matchfn, walk() | |
|
88 | ||
|
89 | def walk(repo, pats, opts, node=None, head='', badmatch=None): | |
|
90 | files, matchfn, results = makewalk(repo, pats, opts, node, head, badmatch) | |
|
91 | for r in results: | |
|
92 | yield r |
@@ -50,29 +50,6 b' def logmessage(opts):' | |||
|
50 | 50 | (logfile, inst.strerror)) |
|
51 | 51 | return message |
|
52 | 52 | |
|
53 | def matchpats(repo, pats=[], opts={}, head=''): | |
|
54 | cwd = repo.getcwd() | |
|
55 | if not pats and cwd: | |
|
56 | opts['include'] = [os.path.join(cwd, i) for i in opts['include']] | |
|
57 | opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']] | |
|
58 | cwd = '' | |
|
59 | return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), | |
|
60 | opts.get('exclude'), head) | |
|
61 | ||
|
62 | def makewalk(repo, pats, opts, node=None, head='', badmatch=None): | |
|
63 | files, matchfn, anypats = matchpats(repo, pats, opts, head) | |
|
64 | exact = dict(zip(files, files)) | |
|
65 | def walk(): | |
|
66 | for src, fn in repo.walk(node=node, files=files, match=matchfn, | |
|
67 | badmatch=badmatch): | |
|
68 | yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact | |
|
69 | return files, matchfn, walk() | |
|
70 | ||
|
71 | def walk(repo, pats, opts, node=None, head='', badmatch=None): | |
|
72 | files, matchfn, results = makewalk(repo, pats, opts, node, head, badmatch) | |
|
73 | for r in results: | |
|
74 | yield r | |
|
75 | ||
|
76 | 53 | def walkchangerevs(ui, repo, pats, opts): |
|
77 | 54 | '''Iterate over files and the revs they changed in. |
|
78 | 55 | |
@@ -115,7 +92,7 b' def walkchangerevs(ui, repo, pats, opts)' | |||
|
115 | 92 | windowsize *= 2 |
|
116 | 93 | |
|
117 | 94 | |
|
118 | files, matchfn, anypats = matchpats(repo, pats, opts) | |
|
95 | files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) | |
|
119 | 96 | follow = opts.get('follow') or opts.get('follow_first') |
|
120 | 97 | |
|
121 | 98 | if repo.changelog.count() == 0: |
@@ -653,7 +630,7 b' def add(ui, repo, *pats, **opts):' | |||
|
653 | 630 | """ |
|
654 | 631 | |
|
655 | 632 | names = [] |
|
656 | for src, abs, rel, exact in walk(repo, pats, opts): | |
|
633 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts): | |
|
657 | 634 | if exact: |
|
658 | 635 | if ui.verbose: |
|
659 | 636 | ui.status(_('adding %s\n') % rel) |
@@ -682,7 +659,7 b' def addremove(ui, repo, *pats, **opts):' | |||
|
682 | 659 | |
|
683 | 660 | def addremove_lock(ui, repo, pats, opts, wlock=None): |
|
684 | 661 | add, remove = [], [] |
|
685 | for src, abs, rel, exact in walk(repo, pats, opts): | |
|
662 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts): | |
|
686 | 663 | if src == 'f' and repo.dirstate.state(abs) == '?': |
|
687 | 664 | add.append(abs) |
|
688 | 665 | if ui.verbose or not exact: |
@@ -736,7 +713,8 b' def annotate(ui, repo, *pats, **opts):' | |||
|
736 | 713 | |
|
737 | 714 | ctx = repo.changectx(opts['rev'] or repo.dirstate.parents()[0]) |
|
738 | 715 | |
|
739 |
for src, abs, rel, exact in walk(repo, pats, opts, |
|
|
716 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, | |
|
717 | node=ctx.node()): | |
|
740 | 718 | fctx = ctx.filectx(abs) |
|
741 | 719 | if not opts['text'] and util.binary(fctx.data()): |
|
742 | 720 | ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) |
@@ -791,7 +769,7 b' def archive(ui, repo, dest, **opts):' | |||
|
791 | 769 | dest = cmdutil.make_filename(repo, dest, node) |
|
792 | 770 | if os.path.realpath(dest) == repo.root: |
|
793 | 771 | raise util.Abort(_('repository root cannot be destination')) |
|
794 | dummy, matchfn, dummy = matchpats(repo, [], opts) | |
|
772 | dummy, matchfn, dummy = cmdutil.matchpats(repo, [], opts) | |
|
795 | 773 | kind = opts.get('type') or 'files' |
|
796 | 774 | prefix = opts['prefix'] |
|
797 | 775 | if dest == '-': |
@@ -903,7 +881,8 b' def cat(ui, repo, file1, *pats, **opts):' | |||
|
903 | 881 | %p root-relative path name of file being printed |
|
904 | 882 | """ |
|
905 | 883 | ctx = repo.changectx(opts['rev'] or "-1") |
|
906 |
for src, abs, rel, exact in walk(repo, (file1,) + pats, opts, |
|
|
884 | for src, abs, rel, exact in cmdutil.walk(repo, (file1,) + pats, opts, | |
|
885 | ctx.node()): | |
|
907 | 886 | fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs) |
|
908 | 887 | fp.write(ctx.filectx(abs).data()) |
|
909 | 888 | |
@@ -967,7 +946,7 b' def commit(ui, repo, *pats, **opts):' | |||
|
967 | 946 | |
|
968 | 947 | if opts['addremove']: |
|
969 | 948 | addremove_lock(ui, repo, pats, opts) |
|
970 | fns, match, anypats = matchpats(repo, pats, opts) | |
|
949 | fns, match, anypats = cmdutil.matchpats(repo, pats, opts) | |
|
971 | 950 | if pats: |
|
972 | 951 | modified, added, removed = repo.status(files=fns, match=match)[:3] |
|
973 | 952 | files = modified + added + removed |
@@ -1124,7 +1103,7 b' def docopy(ui, repo, pats, opts, wlock):' | |||
|
1124 | 1103 | copylist = [] |
|
1125 | 1104 | for pat in pats: |
|
1126 | 1105 | srcs = [] |
|
1127 | for tag, abssrc, relsrc, exact in walk(repo, [pat], opts): | |
|
1106 | for tag, abssrc, relsrc, exact in cmdutil.walk(repo, [pat], opts): | |
|
1128 | 1107 | origsrc = okaytocopy(abssrc, relsrc, exact) |
|
1129 | 1108 | if origsrc: |
|
1130 | 1109 | srcs.append((origsrc, abssrc, relsrc, exact)) |
@@ -1341,7 +1320,7 b' def debugrename(ui, repo, file, rev=None' | |||
|
1341 | 1320 | |
|
1342 | 1321 | def debugwalk(ui, repo, *pats, **opts): |
|
1343 | 1322 | """show how files match on given patterns""" |
|
1344 | items = list(walk(repo, pats, opts)) | |
|
1323 | items = list(cmdutil.walk(repo, pats, opts)) | |
|
1345 | 1324 | if not items: |
|
1346 | 1325 | return |
|
1347 | 1326 | fmt = '%%s %%-%ds %%-%ds %%s' % ( |
@@ -1370,7 +1349,7 b' def diff(ui, repo, *pats, **opts):' | |||
|
1370 | 1349 | """ |
|
1371 | 1350 | node1, node2 = revpair(ui, repo, opts['rev']) |
|
1372 | 1351 | |
|
1373 | fns, matchfn, anypats = matchpats(repo, pats, opts) | |
|
1352 | fns, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) | |
|
1374 | 1353 | |
|
1375 | 1354 | patch.diff(repo, node1, node2, fns, match=matchfn, |
|
1376 | 1355 | opts=ui.diffopts(opts)) |
@@ -1423,7 +1402,7 b' def forget(ui, repo, *pats, **opts):' | |||
|
1423 | 1402 | """ |
|
1424 | 1403 | ui.warn(_("(the forget command is deprecated; use revert instead)\n")) |
|
1425 | 1404 | forget = [] |
|
1426 | for src, abs, rel, exact in walk(repo, pats, opts): | |
|
1405 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts): | |
|
1427 | 1406 | if repo.dirstate.state(abs) == 'a': |
|
1428 | 1407 | forget.append(abs) |
|
1429 | 1408 | if ui.verbose or not exact: |
@@ -1847,8 +1826,8 b' def locate(ui, repo, *pats, **opts):' | |||
|
1847 | 1826 | else: |
|
1848 | 1827 | node = None |
|
1849 | 1828 | |
|
1850 | for src, abs, rel, exact in walk(repo, pats, opts, node=node, | |
|
1851 | head='(?:.*/|)'): | |
|
1829 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node, | |
|
1830 | head='(?:.*/|)'): | |
|
1852 | 1831 | if not node and repo.dirstate.state(abs) == '?': |
|
1853 | 1832 | continue |
|
1854 | 1833 | if opts['fullpath']: |
@@ -2244,12 +2223,12 b' def remove(ui, repo, *pats, **opts):' | |||
|
2244 | 2223 | names = [] |
|
2245 | 2224 | if not opts['after'] and not pats: |
|
2246 | 2225 | raise util.Abort(_('no files specified')) |
|
2247 | files, matchfn, anypats = matchpats(repo, pats, opts) | |
|
2226 | files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) | |
|
2248 | 2227 | exact = dict.fromkeys(files) |
|
2249 | 2228 | mardu = map(dict.fromkeys, repo.status(files=files, match=matchfn))[:5] |
|
2250 | 2229 | modified, added, removed, deleted, unknown = mardu |
|
2251 | 2230 | remove, forget = [], [] |
|
2252 | for src, abs, rel, exact in walk(repo, pats, opts): | |
|
2231 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts): | |
|
2253 | 2232 | reason = None |
|
2254 | 2233 | if abs not in deleted and opts['after']: |
|
2255 | 2234 | reason = _('is still present') |
@@ -2356,15 +2335,16 b' def revert(ui, repo, *pats, **opts):' | |||
|
2356 | 2335 | |
|
2357 | 2336 | # walk dirstate. |
|
2358 | 2337 | |
|
2359 |
for src, abs, rel, exact in walk(repo, pats, opts, |
|
|
2338 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, | |
|
2339 | badmatch=mf.has_key): | |
|
2360 | 2340 | names[abs] = (rel, exact) |
|
2361 | 2341 | if src == 'b': |
|
2362 | 2342 | target_only[abs] = True |
|
2363 | 2343 | |
|
2364 | 2344 | # walk target manifest. |
|
2365 | 2345 | |
|
2366 | for src, abs, rel, exact in walk(repo, pats, opts, node=node, | |
|
2367 | badmatch=names.has_key): | |
|
2346 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node, | |
|
2347 | badmatch=names.has_key): | |
|
2368 | 2348 | if abs in names: continue |
|
2369 | 2349 | names[abs] = (rel, exact) |
|
2370 | 2350 | target_only[abs] = True |
@@ -2576,7 +2556,7 b' def status(ui, repo, *pats, **opts):' | |||
|
2576 | 2556 | |
|
2577 | 2557 | all = opts['all'] |
|
2578 | 2558 | |
|
2579 | files, matchfn, anypats = matchpats(repo, pats, opts) | |
|
2559 | files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) | |
|
2580 | 2560 | cwd = (pats and repo.getcwd()) or '' |
|
2581 | 2561 | modified, added, removed, deleted, unknown, ignored, clean = [ |
|
2582 | 2562 | [util.pathto(cwd, x) for x in n] |
General Comments 0
You need to be logged in to leave comments.
Login now