Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 1568:1d7d0c07e8f3
make all commands be repo-wide by default
- refactor code in commands.py so that:
if no pattern is given, the command will be repo-wide
else it will work on the working dir
- update the doc
- fix the tests
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Thu, 01 Dec 2005 10:51:45 -0600 |
parents | b4956bbbadc9 |
children | 6a104941d56a 63799b01985c |
comparison
equal
deleted
inserted
replaced
1567:b4956bbbadc9 | 1568:1d7d0c07e8f3 |
---|---|
31 cwd = repo.getcwd() | 31 cwd = repo.getcwd() |
32 if cwd: | 32 if cwd: |
33 return [util.normpath(os.path.join(cwd, x)) for x in args] | 33 return [util.normpath(os.path.join(cwd, x)) for x in args] |
34 return args | 34 return args |
35 | 35 |
36 def matchpats(repo, cwd, pats=[], opts={}, head=''): | 36 def matchpats(repo, pats=[], opts={}, head=''): |
37 cwd = repo.getcwd() | |
38 if not pats and cwd: | |
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']] | |
41 cwd = '' | |
37 return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), | 42 return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), |
38 opts.get('exclude'), head) | 43 opts.get('exclude'), head) + (cwd,) |
39 | 44 |
40 def makewalk(repo, pats, opts, head=''): | 45 def makewalk(repo, pats, opts, head=''): |
41 cwd = repo.getcwd() | 46 files, matchfn, anypats, cwd = matchpats(repo, pats, opts, head) |
42 files, matchfn, anypats = matchpats(repo, cwd, pats, opts, head) | |
43 exact = dict(zip(files, files)) | 47 exact = dict(zip(files, files)) |
44 def walk(): | 48 def walk(): |
45 for src, fn in repo.walk(files=files, match=matchfn): | 49 for src, fn in repo.walk(files=files, match=matchfn): |
46 yield src, fn, util.pathto(cwd, fn), fn in exact | 50 yield src, fn, util.pathto(cwd, fn), fn in exact |
47 return files, matchfn, walk() | 51 return files, matchfn, walk() |
49 def walk(repo, pats, opts, head=''): | 53 def walk(repo, pats, opts, head=''): |
50 files, matchfn, results = makewalk(repo, pats, opts, head) | 54 files, matchfn, results = makewalk(repo, pats, opts, head) |
51 for r in results: | 55 for r in results: |
52 yield r | 56 yield r |
53 | 57 |
54 def walkchangerevs(ui, repo, cwd, pats, opts): | 58 def walkchangerevs(ui, repo, pats, opts): |
55 '''Iterate over files and the revs they changed in. | 59 '''Iterate over files and the revs they changed in. |
56 | 60 |
57 Callers most commonly need to iterate backwards over the history | 61 Callers most commonly need to iterate backwards over the history |
58 it is interested in. Doing so has awful (quadratic-looking) | 62 it is interested in. Doing so has awful (quadratic-looking) |
59 performance, so we use iterators in a "windowed" way. | 63 performance, so we use iterators in a "windowed" way. |
79 over with "add" - use to display data''' | 83 over with "add" - use to display data''' |
80 | 84 |
81 if repo.changelog.count() == 0: | 85 if repo.changelog.count() == 0: |
82 return [], False | 86 return [], False |
83 | 87 |
84 cwd = repo.getcwd() | 88 files, matchfn, anypats, cwd = matchpats(repo, pats, opts) |
85 if not pats and cwd: | |
86 opts['include'] = [os.path.join(cwd, i) for i in opts['include']] | |
87 opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']] | |
88 files, matchfn, anypats = matchpats(repo, (pats and cwd) or '', | |
89 pats, opts) | |
90 revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0'])) | 89 revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0'])) |
91 wanted = {} | 90 wanted = {} |
92 slowpath = anypats | 91 slowpath = anypats |
93 window = 300 | 92 window = 300 |
94 fncache = {} | 93 fncache = {} |
481 | 480 |
482 Schedule files to be version controlled and added to the repository. | 481 Schedule files to be version controlled and added to the repository. |
483 | 482 |
484 The files will be added to the repository at the next commit. | 483 The files will be added to the repository at the next commit. |
485 | 484 |
486 If no names are given, add all files in the current directory and | 485 If no names are given, add all files in the repository. |
487 its subdirectories. | |
488 """ | 486 """ |
489 | 487 |
490 names = [] | 488 names = [] |
491 for src, abs, rel, exact in walk(repo, pats, opts): | 489 for src, abs, rel, exact in walk(repo, pats, opts): |
492 if exact: | 490 if exact: |
757 """commit the specified files or all outstanding changes | 755 """commit the specified files or all outstanding changes |
758 | 756 |
759 Commit changes to the given files into the repository. | 757 Commit changes to the given files into the repository. |
760 | 758 |
761 If a list of files is omitted, all changes reported by "hg status" | 759 If a list of files is omitted, all changes reported by "hg status" |
762 from the root of the repository will be commited. | 760 will be commited. |
763 | 761 |
764 The HGEDITOR or EDITOR environment variables are used to start an | 762 The HGEDITOR or EDITOR environment variables are used to start an |
765 editor to add a commit comment. | 763 editor to add a commit comment. |
766 """ | 764 """ |
767 message = opts['message'] | 765 message = opts['message'] |
780 raise util.Abort(_("can't read commit message '%s': %s") % | 778 raise util.Abort(_("can't read commit message '%s': %s") % |
781 (logfile, inst.strerror)) | 779 (logfile, inst.strerror)) |
782 | 780 |
783 if opts['addremove']: | 781 if opts['addremove']: |
784 addremove(ui, repo, *pats, **opts) | 782 addremove(ui, repo, *pats, **opts) |
785 cwd = repo.getcwd() | 783 fns, match, anypats, cwd = matchpats(repo, pats, opts) |
786 if not pats and cwd: | |
787 opts['include'] = [os.path.join(cwd, i) for i in opts['include']] | |
788 opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']] | |
789 fns, match, anypats = matchpats(repo, (pats and repo.getcwd()) or '', | |
790 pats, opts) | |
791 if pats: | 784 if pats: |
792 c, a, d, u = repo.changes(files=fns, match=match) | 785 c, a, d, u = repo.changes(files=fns, match=match) |
793 files = c + a + [fn for fn in d if repo.dirstate.state(fn) == 'r'] | 786 files = c + a + [fn for fn in d if repo.dirstate.state(fn) == 'r'] |
794 else: | 787 else: |
795 files = [] | 788 files = [] |
1095 for src, abs, rel, exact in items: | 1088 for src, abs, rel, exact in items: |
1096 line = fmt % (src, abs, rel, exact and 'exact' or '') | 1089 line = fmt % (src, abs, rel, exact and 'exact' or '') |
1097 ui.write("%s\n" % line.rstrip()) | 1090 ui.write("%s\n" % line.rstrip()) |
1098 | 1091 |
1099 def diff(ui, repo, *pats, **opts): | 1092 def diff(ui, repo, *pats, **opts): |
1100 """diff working directory (or selected files) | 1093 """diff repository (or selected files) |
1101 | 1094 |
1102 Show differences between revisions for the specified files. | 1095 Show differences between revisions for the specified files. |
1103 | 1096 |
1104 Differences between files are shown using the unified diff format. | 1097 Differences between files are shown using the unified diff format. |
1105 | 1098 |
1121 if len(revs) > 1: | 1114 if len(revs) > 1: |
1122 node2 = revs[1] | 1115 node2 = revs[1] |
1123 if len(revs) > 2: | 1116 if len(revs) > 2: |
1124 raise util.Abort(_("too many revisions to diff")) | 1117 raise util.Abort(_("too many revisions to diff")) |
1125 | 1118 |
1126 fns, matchfn, anypats = matchpats(repo, repo.getcwd(), pats, opts) | 1119 fns, matchfn, anypats, cwd = matchpats(repo, pats, opts) |
1127 | 1120 |
1128 dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn, | 1121 dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn, |
1129 text=opts['text']) | 1122 text=opts['text']) |
1130 | 1123 |
1131 def doexport(ui, repo, changeset, seqno, total, revwidth, opts): | 1124 def doexport(ui, repo, changeset, seqno, total, revwidth, opts): |
1292 counts[change] += 1 | 1285 counts[change] += 1 |
1293 return counts['+'], counts['-'] | 1286 return counts['+'], counts['-'] |
1294 | 1287 |
1295 fstate = {} | 1288 fstate = {} |
1296 skip = {} | 1289 skip = {} |
1297 changeiter, getchange = walkchangerevs(ui, repo, repo.getcwd(), pats, opts) | 1290 changeiter, getchange = walkchangerevs(ui, repo, pats, opts) |
1298 count = 0 | 1291 count = 0 |
1299 incrementing = False | 1292 incrementing = False |
1300 for st, rev, fns in changeiter: | 1293 for st, rev, fns in changeiter: |
1301 if st == 'window': | 1294 if st == 'window': |
1302 incrementing = rev | 1295 incrementing = rev |
1555 def debug(self, *args): | 1548 def debug(self, *args): |
1556 if self.debugflag: | 1549 if self.debugflag: |
1557 self.write(*args) | 1550 self.write(*args) |
1558 def __getattr__(self, key): | 1551 def __getattr__(self, key): |
1559 return getattr(self.ui, key) | 1552 return getattr(self.ui, key) |
1560 cwd = repo.getcwd() | 1553 changeiter, getchange = walkchangerevs(ui, repo, pats, opts) |
1561 if not pats and cwd: | |
1562 opts['include'] = [os.path.join(cwd, i) for i in opts['include']] | |
1563 opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']] | |
1564 changeiter, getchange = walkchangerevs(ui, repo, (pats and cwd) or '', | |
1565 pats, opts) | |
1566 for st, rev, fns in changeiter: | 1554 for st, rev, fns in changeiter: |
1567 if st == 'window': | 1555 if st == 'window': |
1568 du = dui(ui) | 1556 du = dui(ui) |
1569 elif st == 'add': | 1557 elif st == 'add': |
1570 du.bump(rev) | 1558 du.bump(rev) |
1869 If a file has been deleted, it is recreated. If the executable | 1857 If a file has been deleted, it is recreated. If the executable |
1870 mode of a file was changed, it is reset. | 1858 mode of a file was changed, it is reset. |
1871 | 1859 |
1872 If names are given, all files matching the names are reverted. | 1860 If names are given, all files matching the names are reverted. |
1873 | 1861 |
1874 If no names are given, all files in the current directory and | 1862 If no arguments are given, all files in the repository are reverted. |
1875 its subdirectories are reverted. | |
1876 """ | 1863 """ |
1877 node = opts['rev'] and repo.lookup(opts['rev']) or \ | 1864 node = opts['rev'] and repo.lookup(opts['rev']) or \ |
1878 repo.dirstate.parents()[0] | 1865 repo.dirstate.parents()[0] |
1879 | 1866 |
1880 files, choose, anypats = matchpats(repo, repo.getcwd(), pats, opts) | 1867 files, choose, anypats, cwd = matchpats(repo, pats, opts) |
1881 (c, a, d, u) = repo.changes(match=choose) | 1868 (c, a, d, u) = repo.changes(match=choose) |
1882 repo.forget(a) | 1869 repo.forget(a) |
1883 repo.undelete(d) | 1870 repo.undelete(d) |
1884 | 1871 |
1885 return repo.update(node, False, True, choose, False) | 1872 return repo.update(node, False, True, choose, False) |
1998 httpd.serve_forever() | 1985 httpd.serve_forever() |
1999 | 1986 |
2000 def status(ui, repo, *pats, **opts): | 1987 def status(ui, repo, *pats, **opts): |
2001 """show changed files in the working directory | 1988 """show changed files in the working directory |
2002 | 1989 |
2003 Show changed files in the working directory. If no names are | 1990 Show changed files in the repository. If names are |
2004 given, all files are shown. Otherwise, only files matching the | 1991 given, only files that match are shown. |
2005 given names are shown. | |
2006 | 1992 |
2007 The codes used to show the status of files are: | 1993 The codes used to show the status of files are: |
2008 M = modified | 1994 M = modified |
2009 A = added | 1995 A = added |
2010 R = removed | 1996 R = removed |
2011 ? = not tracked | 1997 ? = not tracked |
2012 """ | 1998 """ |
2013 | 1999 |
2014 cwd = repo.getcwd() | 2000 files, matchfn, anypats, cwd = matchpats(repo, pats, opts) |
2015 files, matchfn, anypats = matchpats(repo, cwd, pats, opts) | |
2016 (c, a, d, u) = [[util.pathto(cwd, x) for x in n] | 2001 (c, a, d, u) = [[util.pathto(cwd, x) for x in n] |
2017 for n in repo.changes(files=files, match=matchfn)] | 2002 for n in repo.changes(files=files, match=matchfn)] |
2018 | 2003 |
2019 changetypes = [(_('modified'), 'M', c), | 2004 changetypes = [(_('modified'), 'M', c), |
2020 (_('added'), 'A', a), | 2005 (_('added'), 'A', a), |