Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 1625:e1bcf7fa983f
correct the relative path when walking from a subdir
- yield the correct relative path when walking from a subdir
(regardless the walk is repo-wide or not)
- have a consistent output from all commands: filename are
absolute when no patterns are specified and relative otherwise.
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Tue, 17 Jan 2006 16:10:22 +0100 |
parents | 5e9168401a68 |
children | f2b1df3dbcbb |
comparison
equal
deleted
inserted
replaced
1624:d9e576e55d81 | 1625:e1bcf7fa983f |
---|---|
38 if not pats and cwd: | 38 if not pats and cwd: |
39 opts['include'] = [os.path.join(cwd, i) for i in opts['include']] | 39 opts['include'] = [os.path.join(cwd, i) for i in opts['include']] |
40 opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']] | 40 opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']] |
41 cwd = '' | 41 cwd = '' |
42 return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), | 42 return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), |
43 opts.get('exclude'), head) + (cwd,) | 43 opts.get('exclude'), head) |
44 | 44 |
45 def makewalk(repo, pats, opts, node=None, head=''): | 45 def makewalk(repo, pats, opts, node=None, head=''): |
46 files, matchfn, anypats, cwd = matchpats(repo, pats, opts, head) | 46 files, matchfn, anypats = matchpats(repo, pats, opts, head) |
47 exact = dict(zip(files, files)) | 47 exact = dict(zip(files, files)) |
48 def walk(): | 48 def walk(): |
49 for src, fn in repo.walk(node=node, files=files, match=matchfn): | 49 for src, fn in repo.walk(node=node, files=files, match=matchfn): |
50 yield src, fn, util.pathto(cwd, fn), fn in exact | 50 yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact |
51 return files, matchfn, walk() | 51 return files, matchfn, walk() |
52 | 52 |
53 def walk(repo, pats, opts, node=None, head=''): | 53 def walk(repo, pats, opts, node=None, head=''): |
54 files, matchfn, results = makewalk(repo, pats, opts, node, head) | 54 files, matchfn, results = makewalk(repo, pats, opts, node, head) |
55 for r in results: | 55 for r in results: |
80 possible display | 80 possible display |
81 | 81 |
82 "iter", rev, None: in-order traversal of the revs earlier iterated | 82 "iter", rev, None: in-order traversal of the revs earlier iterated |
83 over with "add" - use to display data''' | 83 over with "add" - use to display data''' |
84 | 84 |
85 files, matchfn, anypats, cwd = matchpats(repo, pats, opts) | 85 files, matchfn, anypats = matchpats(repo, pats, opts) |
86 | 86 |
87 if repo.changelog.count() == 0: | 87 if repo.changelog.count() == 0: |
88 return [], False, matchfn | 88 return [], False, matchfn |
89 | 89 |
90 revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0'])) | 90 revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0'])) |
513 add, remove = [], [] | 513 add, remove = [], [] |
514 for src, abs, rel, exact in walk(repo, pats, opts): | 514 for src, abs, rel, exact in walk(repo, pats, opts): |
515 if src == 'f' and repo.dirstate.state(abs) == '?': | 515 if src == 'f' and repo.dirstate.state(abs) == '?': |
516 add.append(abs) | 516 add.append(abs) |
517 if ui.verbose or not exact: | 517 if ui.verbose or not exact: |
518 ui.status(_('adding %s\n') % rel) | 518 ui.status(_('adding %s\n') % ((pats and rel) or abs)) |
519 if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel): | 519 if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel): |
520 remove.append(abs) | 520 remove.append(abs) |
521 if ui.verbose or not exact: | 521 if ui.verbose or not exact: |
522 ui.status(_('removing %s\n') % rel) | 522 ui.status(_('removing %s\n') % ((pats and rel) or abs)) |
523 repo.add(add) | 523 repo.add(add) |
524 repo.remove(remove) | 524 repo.remove(remove) |
525 | 525 |
526 def annotate(ui, repo, *pats, **opts): | 526 def annotate(ui, repo, *pats, **opts): |
527 """show changeset information per file line | 527 """show changeset information per file line |
566 change = repo.changelog.read(node) | 566 change = repo.changelog.read(node) |
567 mmap = repo.manifest.read(change[0]) | 567 mmap = repo.manifest.read(change[0]) |
568 | 568 |
569 for src, abs, rel, exact in walk(repo, pats, opts): | 569 for src, abs, rel, exact in walk(repo, pats, opts): |
570 if abs not in mmap: | 570 if abs not in mmap: |
571 ui.warn(_("warning: %s is not in the repository!\n") % rel) | 571 ui.warn(_("warning: %s is not in the repository!\n") % |
572 ((pats and rel) or abs)) | |
572 continue | 573 continue |
573 | 574 |
574 f = repo.file(abs) | 575 f = repo.file(abs) |
575 if not opts['text'] and util.binary(f.read(mmap[abs])): | 576 if not opts['text'] and util.binary(f.read(mmap[abs])): |
576 ui.write(_("%s: binary file\n") % rel) | 577 ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) |
577 continue | 578 continue |
578 | 579 |
579 lines = f.annotate(mmap[abs]) | 580 lines = f.annotate(mmap[abs]) |
580 pieces = [] | 581 pieces = [] |
581 | 582 |
781 raise util.Abort(_("can't read commit message '%s': %s") % | 782 raise util.Abort(_("can't read commit message '%s': %s") % |
782 (logfile, inst.strerror)) | 783 (logfile, inst.strerror)) |
783 | 784 |
784 if opts['addremove']: | 785 if opts['addremove']: |
785 addremove(ui, repo, *pats, **opts) | 786 addremove(ui, repo, *pats, **opts) |
786 fns, match, anypats, cwd = matchpats(repo, pats, opts) | 787 fns, match, anypats = matchpats(repo, pats, opts) |
787 if pats: | 788 if pats: |
788 modified, added, removed, deleted, unknown = ( | 789 modified, added, removed, deleted, unknown = ( |
789 repo.changes(files=fns, match=match)) | 790 repo.changes(files=fns, match=match)) |
790 files = modified + added + removed | 791 files = modified + added + removed |
791 else: | 792 else: |
1120 if len(revs) > 1: | 1121 if len(revs) > 1: |
1121 node2 = revs[1] | 1122 node2 = revs[1] |
1122 if len(revs) > 2: | 1123 if len(revs) > 2: |
1123 raise util.Abort(_("too many revisions to diff")) | 1124 raise util.Abort(_("too many revisions to diff")) |
1124 | 1125 |
1125 fns, matchfn, anypats, cwd = matchpats(repo, pats, opts) | 1126 fns, matchfn, anypats = matchpats(repo, pats, opts) |
1126 | 1127 |
1127 dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn, | 1128 dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn, |
1128 text=opts['text']) | 1129 text=opts['text']) |
1129 | 1130 |
1130 def doexport(ui, repo, changeset, seqno, total, revwidth, opts): | 1131 def doexport(ui, repo, changeset, seqno, total, revwidth, opts): |
1201 forget = [] | 1202 forget = [] |
1202 for src, abs, rel, exact in walk(repo, pats, opts): | 1203 for src, abs, rel, exact in walk(repo, pats, opts): |
1203 if repo.dirstate.state(abs) == 'a': | 1204 if repo.dirstate.state(abs) == 'a': |
1204 forget.append(abs) | 1205 forget.append(abs) |
1205 if ui.verbose or not exact: | 1206 if ui.verbose or not exact: |
1206 ui.status(_('forgetting %s\n') % rel) | 1207 ui.status(_('forgetting %s\n') % ((pats and rel) or abs)) |
1207 repo.forget(forget) | 1208 repo.forget(forget) |
1208 | 1209 |
1209 def grep(ui, repo, pattern, *pats, **opts): | 1210 def grep(ui, repo, pattern, *pats, **opts): |
1210 """search for a pattern in specified files and revisions | 1211 """search for a pattern in specified files and revisions |
1211 | 1212 |
1542 if not node and repo.dirstate.state(abs) == '?': | 1543 if not node and repo.dirstate.state(abs) == '?': |
1543 continue | 1544 continue |
1544 if opts['fullpath']: | 1545 if opts['fullpath']: |
1545 ui.write(os.path.join(repo.root, abs), end) | 1546 ui.write(os.path.join(repo.root, abs), end) |
1546 else: | 1547 else: |
1547 ui.write(rel, end) | 1548 ui.write(((pats and rel) or abs), end) |
1548 | 1549 |
1549 def log(ui, repo, *pats, **opts): | 1550 def log(ui, repo, *pats, **opts): |
1550 """show revision history of entire repository or files | 1551 """show revision history of entire repository or files |
1551 | 1552 |
1552 Print the revision history of the specified files or the entire project. | 1553 Print the revision history of the specified files or the entire project. |
1896 If no arguments are given, all files in the repository are reverted. | 1897 If no arguments are given, all files in the repository are reverted. |
1897 """ | 1898 """ |
1898 node = opts['rev'] and repo.lookup(opts['rev']) or \ | 1899 node = opts['rev'] and repo.lookup(opts['rev']) or \ |
1899 repo.dirstate.parents()[0] | 1900 repo.dirstate.parents()[0] |
1900 | 1901 |
1901 files, choose, anypats, cwd = matchpats(repo, pats, opts) | 1902 files, choose, anypats = matchpats(repo, pats, opts) |
1902 modified, added, removed, deleted, unknown = repo.changes(match=choose) | 1903 modified, added, removed, deleted, unknown = repo.changes(match=choose) |
1903 repo.forget(added) | 1904 repo.forget(added) |
1904 repo.undelete(removed + deleted) | 1905 repo.undelete(removed + deleted) |
1905 | 1906 |
1906 return repo.update(node, False, True, choose, False) | 1907 return repo.update(node, False, True, choose, False) |
2030 R = removed | 2031 R = removed |
2031 ! = deleted, but still tracked | 2032 ! = deleted, but still tracked |
2032 ? = not tracked | 2033 ? = not tracked |
2033 """ | 2034 """ |
2034 | 2035 |
2035 files, matchfn, anypats, cwd = matchpats(repo, pats, opts) | 2036 files, matchfn, anypats = matchpats(repo, pats, opts) |
2037 cwd = (pats and repo.getcwd()) or '' | |
2036 modified, added, removed, deleted, unknown = [ | 2038 modified, added, removed, deleted, unknown = [ |
2037 [util.pathto(cwd, x) for x in n] | 2039 [util.pathto(cwd, x) for x in n] |
2038 for n in repo.changes(files=files, match=matchfn)] | 2040 for n in repo.changes(files=files, match=matchfn)] |
2039 | 2041 |
2040 changetypes = [(_('modified'), 'M', modified), | 2042 changetypes = [(_('modified'), 'M', modified), |