Mercurial > hg > mercurial-crew-with-dirclash
annotate mercurial/commands.py @ 476:0a338d506268
Really _call_ method revlog.count in revlog.lookup()
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Really _call_ method revlog.count in revlog.lookup()
This fixes e.g. 'hg export 398737777' (exists in the mercurial repo).
manifest hash: 9de9ad4c40d0746cb3db346a01c373e3b4aba54a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFCvovbW7P1GVgWeRoRAiyEAJ9gVZZiMGA3YItcWRHeai/9C+dMTgCbBiii
QoFaXQ9wZDds8fVVsvENAYw=
=msWK
-----END PGP SIGNATURE-----
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Sun, 26 Jun 2005 12:04:59 +0100 |
parents | 0ab093b473c5 |
children | 520540fd6b64 934279f3ca53 |
rev | line source |
---|---|
249 | 1 # commands.py - command processing for mercurial |
2 # | |
3 # Copyright 2005 Matt Mackall <mpm@selenic.com> | |
4 # | |
5 # This software may be used and distributed according to the terms | |
6 # of the GNU General Public License, incorporated herein by reference. | |
7 | |
262 | 8 import os, re, sys, signal |
419
28511fc21073
[PATCH] file seperator handling for the other 'OS'
mpm@selenic.com
parents:
417
diff
changeset
|
9 import fancyopts, ui, hg, util |
262 | 10 from demandload import * |
423
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
396
diff
changeset
|
11 demandload(globals(), "mdiff time hgweb traceback random signal errno version") |
209 | 12 |
13 class UnknownCommand(Exception): pass | |
14 | |
245 | 15 def filterfiles(filters, files): |
16 l = [ x for x in files if x in filters ] | |
213 | 17 |
245 | 18 for t in filters: |
419
28511fc21073
[PATCH] file seperator handling for the other 'OS'
mpm@selenic.com
parents:
417
diff
changeset
|
19 if t and t[-1] != "/": t += "/" |
245 | 20 l += [ x for x in files if x.startswith(t) ] |
213 | 21 return l |
22 | |
245 | 23 def relfilter(repo, files): |
213 | 24 if os.getcwd() != repo.root: |
25 p = os.getcwd()[len(repo.root) + 1: ] | |
419
28511fc21073
[PATCH] file seperator handling for the other 'OS'
mpm@selenic.com
parents:
417
diff
changeset
|
26 return filterfiles([util.pconvert(p)], files) |
245 | 27 return files |
213 | 28 |
209 | 29 def relpath(repo, args): |
30 if os.getcwd() != repo.root: | |
31 p = os.getcwd()[len(repo.root) + 1: ] | |
419
28511fc21073
[PATCH] file seperator handling for the other 'OS'
mpm@selenic.com
parents:
417
diff
changeset
|
32 return [ util.pconvert(os.path.normpath(os.path.join(p, x))) for x in args ] |
209 | 33 return args |
245 | 34 |
396
8f8bb77d560e
Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
395
diff
changeset
|
35 def dodiff(ui, repo, path, files = None, node1 = None, node2 = None): |
245 | 36 def date(c): |
37 return time.asctime(time.gmtime(float(c[2].split(' ')[0]))) | |
38 | |
39 if node2: | |
40 change = repo.changelog.read(node2) | |
41 mmap2 = repo.manifest.read(change[0]) | |
42 (c, a, d) = repo.diffrevs(node1, node2) | |
43 def read(f): return repo.file(f).read(mmap2[f]) | |
44 date2 = date(change) | |
45 else: | |
46 date2 = time.asctime() | |
312 | 47 (c, a, d, u) = repo.diffdir(path, node1) |
245 | 48 if not node1: |
49 node1 = repo.dirstate.parents()[0] | |
417 | 50 def read(f): return repo.wfile(f).read() |
245 | 51 |
396
8f8bb77d560e
Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
395
diff
changeset
|
52 if ui.quiet: |
8f8bb77d560e
Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
395
diff
changeset
|
53 r = None |
8f8bb77d560e
Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
395
diff
changeset
|
54 else: |
8f8bb77d560e
Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
395
diff
changeset
|
55 hexfunc = ui.verbose and hg.hex or hg.short |
8f8bb77d560e
Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
395
diff
changeset
|
56 r = [hexfunc(node) for node in [node1, node2] if node] |
8f8bb77d560e
Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
395
diff
changeset
|
57 |
245 | 58 change = repo.changelog.read(node1) |
59 mmap = repo.manifest.read(change[0]) | |
60 date1 = date(change) | |
61 | |
62 if files: | |
63 c, a, d = map(lambda x: filterfiles(files, x), (c, a, d)) | |
64 | |
65 for f in c: | |
275 | 66 to = None |
67 if f in mmap: | |
68 to = repo.file(f).read(mmap[f]) | |
245 | 69 tn = read(f) |
396
8f8bb77d560e
Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
395
diff
changeset
|
70 sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f, r)) |
245 | 71 for f in a: |
264
4c1d7072d5cd
Attempt to make diff deal with null sources properly
mpm@selenic.com
parents:
262
diff
changeset
|
72 to = None |
245 | 73 tn = read(f) |
396
8f8bb77d560e
Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
395
diff
changeset
|
74 sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f, r)) |
245 | 75 for f in d: |
76 to = repo.file(f).read(mmap[f]) | |
264
4c1d7072d5cd
Attempt to make diff deal with null sources properly
mpm@selenic.com
parents:
262
diff
changeset
|
77 tn = None |
396
8f8bb77d560e
Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
395
diff
changeset
|
78 sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f, r)) |
329
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
79 |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
80 def show_changeset(ui, repo, rev=0, changenode=None, filelog=None): |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
81 """show a single changeset or file revision""" |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
82 changelog = repo.changelog |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
83 if filelog: |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
84 log = filelog |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
85 filerev = rev |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
86 node = filenode = filelog.node(filerev) |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
87 changerev = filelog.linkrev(filenode) |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
88 changenode = changenode or changelog.node(changerev) |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
89 else: |
347
a0b2758edee7
Cleaned up show_changeset()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
330
diff
changeset
|
90 log = changelog |
329
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
91 changerev = rev |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
92 if changenode is None: |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
93 changenode = changelog.node(changerev) |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
94 elif not changerev: |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
95 rev = changerev = changelog.rev(changenode) |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
96 node = changenode |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
97 |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
98 if ui.quiet: |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
99 ui.write("%d:%s\n" % (rev, hg.hex(node))) |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
100 return |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
101 |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
102 changes = changelog.read(changenode) |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
103 |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
104 parents = [(log.rev(parent), hg.hex(parent)) |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
105 for parent in log.parents(node) |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
106 if ui.debugflag or parent != hg.nullid] |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
107 if not ui.debugflag and len(parents) == 1 and parents[0][0] == rev-1: |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
108 parents = [] |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
109 |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
110 if filelog: |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
111 ui.write("revision: %d:%s\n" % (filerev, hg.hex(filenode))) |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
112 for parent in parents: |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
113 ui.write("parent: %d:%s\n" % parent) |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
114 ui.status("changeset: %d:%s\n" % (changerev, hg.hex(changenode))) |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
115 else: |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
116 ui.write("changeset: %d:%s\n" % (changerev, hg.hex(changenode))) |
387
c07c6fb2f0a8
Show tags in hg history etc.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
386
diff
changeset
|
117 for tag in repo.nodetags(changenode): |
c07c6fb2f0a8
Show tags in hg history etc.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
386
diff
changeset
|
118 ui.status("tag: %s\n" % tag) |
329
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
119 for parent in parents: |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
120 ui.write("parent: %d:%s\n" % parent) |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
121 ui.note("manifest: %d:%s\n" % (repo.manifest.rev(changes[0]), |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
122 hg.hex(changes[0]))) |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
123 ui.status("user: %s\n" % changes[1]) |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
124 ui.status("date: %s\n" % time.asctime( |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
125 time.localtime(float(changes[2].split(' ')[0])))) |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
126 ui.note("files: %s\n" % " ".join(changes[3])) |
347
a0b2758edee7
Cleaned up show_changeset()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
330
diff
changeset
|
127 description = changes[4].strip() |
329
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
128 if description: |
330 | 129 if ui.verbose: |
130 ui.status("description:\n") | |
347
a0b2758edee7
Cleaned up show_changeset()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
330
diff
changeset
|
131 ui.status(description) |
365
f94d3632a323
One too many newlines in verbose output showed up in regression
mpm@selenic.com
parents:
363
diff
changeset
|
132 ui.status("\n") |
330 | 133 else: |
347
a0b2758edee7
Cleaned up show_changeset()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
330
diff
changeset
|
134 ui.status("summary: %s\n" % description.splitlines()[0]) |
329
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
135 ui.status("\n") |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
136 |
470
0ab093b473c5
Fix up version module name and command conflict
mpm@selenic.com
parents:
468
diff
changeset
|
137 def show_version(ui): |
423
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
396
diff
changeset
|
138 """output version and copyright information""" |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
396
diff
changeset
|
139 ui.write("Mercurial version %s\n" % version.get_version()) |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
396
diff
changeset
|
140 ui.status( |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
396
diff
changeset
|
141 "\nCopyright (C) 2005 Matt Mackall <mpm@selenic.com>\n" |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
396
diff
changeset
|
142 "This is free software; see the source for copying conditions. " |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
396
diff
changeset
|
143 "There is NO\nwarranty; " |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
396
diff
changeset
|
144 "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
396
diff
changeset
|
145 ) |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
396
diff
changeset
|
146 |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
147 def help(ui, cmd=None): |
255 | 148 '''show help for a given command or all commands''' |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
149 if cmd: |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
150 try: |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
151 i = find(cmd) |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
152 ui.write("%s\n\n" % i[2]) |
293 | 153 |
154 if i[1]: | |
155 for s, l, d, c in i[1]: | |
156 opt=' ' | |
157 if s: opt = opt + '-' + s + ' ' | |
158 if l: opt = opt + '--' + l + ' ' | |
159 if d: opt = opt + '(' + str(d) + ')' | |
160 ui.write(opt, "\n") | |
161 if c: ui.write(' %s\n' % c) | |
162 ui.write("\n") | |
163 | |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
164 ui.write(i[0].__doc__, "\n") |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
165 except UnknownCommand: |
268 | 166 ui.warn("hg: unknown command %s\n" % cmd) |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
167 sys.exit(0) |
255 | 168 else: |
423
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
396
diff
changeset
|
169 if not ui.quiet: |
470
0ab093b473c5
Fix up version module name and command conflict
mpm@selenic.com
parents:
468
diff
changeset
|
170 show_version(ui) |
423
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
396
diff
changeset
|
171 ui.write('\n') |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
396
diff
changeset
|
172 ui.write('hg commands:\n\n') |
209 | 173 |
255 | 174 h = {} |
470
0ab093b473c5
Fix up version module name and command conflict
mpm@selenic.com
parents:
468
diff
changeset
|
175 for c,e in table.items(): |
0ab093b473c5
Fix up version module name and command conflict
mpm@selenic.com
parents:
468
diff
changeset
|
176 f = c |
0ab093b473c5
Fix up version module name and command conflict
mpm@selenic.com
parents:
468
diff
changeset
|
177 aliases = None |
0ab093b473c5
Fix up version module name and command conflict
mpm@selenic.com
parents:
468
diff
changeset
|
178 if "|" in f: |
0ab093b473c5
Fix up version module name and command conflict
mpm@selenic.com
parents:
468
diff
changeset
|
179 l = f.split("|") |
0ab093b473c5
Fix up version module name and command conflict
mpm@selenic.com
parents:
468
diff
changeset
|
180 f, aliases = l[0], l[1:] |
0ab093b473c5
Fix up version module name and command conflict
mpm@selenic.com
parents:
468
diff
changeset
|
181 if f.startswith("debug"): continue |
255 | 182 d = "" |
470
0ab093b473c5
Fix up version module name and command conflict
mpm@selenic.com
parents:
468
diff
changeset
|
183 if e[0].__doc__: |
0ab093b473c5
Fix up version module name and command conflict
mpm@selenic.com
parents:
468
diff
changeset
|
184 d = e[0].__doc__.splitlines(0)[0].rstrip() |
0ab093b473c5
Fix up version module name and command conflict
mpm@selenic.com
parents:
468
diff
changeset
|
185 h[f] = d |
255 | 186 |
187 fns = h.keys() | |
188 fns.sort() | |
189 m = max(map(len, fns)) | |
190 for f in fns: | |
423
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
396
diff
changeset
|
191 ui.write(' %-*s %s\n' % (m, f, h[f])) |
255 | 192 |
193 # Commands start here, listed alphabetically | |
209 | 194 |
245 | 195 def add(ui, repo, file, *files): |
196 '''add the specified files on the next commit''' | |
197 repo.add(relpath(repo, (file,) + files)) | |
213 | 198 |
353 | 199 def addremove(ui, repo, *files): |
255 | 200 """add all new files, delete all missing files""" |
353 | 201 if files: |
202 files = relpath(repo, files) | |
203 d = [] | |
204 u = [] | |
205 for f in files: | |
206 p = repo.wjoin(f) | |
207 s = repo.dirstate.state(f) | |
208 isfile = os.path.isfile(p) | |
209 if s != 'r' and not isfile: | |
210 d.append(f) | |
211 elif s not in 'nmai' and isfile: | |
212 u.append(f) | |
213 else: | |
214 (c, a, d, u) = repo.diffdir(repo.root) | |
259 | 215 repo.add(u) |
245 | 216 repo.remove(d) |
219
8ff4532376a4
hg checkout: refuse to checkout if there are outstanding changes
mpm@selenic.com
parents:
214
diff
changeset
|
217 |
245 | 218 def annotate(u, repo, file, *files, **ops): |
255 | 219 """show changeset information per file line""" |
209 | 220 def getnode(rev): |
221 return hg.short(repo.changelog.node(rev)) | |
222 | |
223 def getname(rev): | |
224 try: | |
225 return bcache[rev] | |
226 except KeyError: | |
227 cl = repo.changelog.read(repo.changelog.node(rev)) | |
228 name = cl[1] | |
229 f = name.find('@') | |
230 if f >= 0: | |
231 name = name[:f] | |
232 bcache[rev] = name | |
233 return name | |
234 | |
235 bcache = {} | |
236 opmap = [['user', getname], ['number', str], ['changeset', getnode]] | |
237 if not ops['user'] and not ops['changeset']: | |
238 ops['number'] = 1 | |
239 | |
227 | 240 node = repo.dirstate.parents()[0] |
209 | 241 if ops['revision']: |
242 node = repo.changelog.lookup(ops['revision']) | |
243 change = repo.changelog.read(node) | |
244 mmap = repo.manifest.read(change[0]) | |
245 maxuserlen = 0 | |
246 maxchangelen = 0 | |
245 | 247 for f in relpath(repo, (file,) + files): |
209 | 248 lines = repo.file(f).annotate(mmap[f]) |
249 pieces = [] | |
250 | |
251 for o, f in opmap: | |
252 if ops[o]: | |
253 l = [ f(n) for n,t in lines ] | |
254 m = max(map(len, l)) | |
255 pieces.append([ "%*s" % (m, x) for x in l]) | |
256 | |
257 for p,l in zip(zip(*pieces), lines): | |
258 u.write(" ".join(p) + ": " + l[1]) | |
259 | |
248 | 260 def cat(ui, repo, file, rev = []): |
255 | 261 """output the latest or given revision of a file""" |
281 | 262 r = repo.file(relpath(repo, [file])[0]) |
248 | 263 n = r.tip() |
264 if rev: n = r.lookup(rev) | |
265 sys.stdout.write(r.read(n)) | |
266 | |
289 | 267 def commit(ui, repo, *files, **opts): |
245 | 268 """commit the specified files or all outstanding changes""" |
289 | 269 text = opts['text'] |
270 if not text and opts['logfile']: | |
271 try: text = open(opts['logfile']).read() | |
272 except IOError: pass | |
273 | |
354 | 274 if opts['addremove']: |
275 addremove(ui, repo, *files) | |
317 | 276 repo.commit(relpath(repo, files), text, opts['user'], opts['date']) |
245 | 277 |
363 | 278 def copy(ui, repo, source, dest): |
279 """mark a file as copied or renamed for the next commit""" | |
280 return repo.copy(*relpath(repo, (source, dest))) | |
281 | |
460 | 282 def debugcheckdirstate(ui, repo): |
283 parent1, parent2 = repo.dirstate.parents() | |
284 dc = repo.dirstate.dup() | |
285 keys = dc.keys() | |
286 keys.sort() | |
287 m1n = repo.changelog.read(parent1)[0] | |
288 m2n = repo.changelog.read(parent2)[0] | |
289 m1 = repo.manifest.read(m1n) | |
290 m2 = repo.manifest.read(m2n) | |
291 errors = 0 | |
292 for f in dc: | |
293 state = repo.dirstate.state(f) | |
294 if state in "nr" and f not in m1: | |
295 print "%s in state %s, but not listed in manifest1" % (f, state) | |
296 errors += 1 | |
297 if state in "a" and f in m1: | |
298 print "%s in state %s, but also listed in manifest1" % (f, state) | |
299 errors += 1 | |
300 if state in "m" and f not in m1 and f not in m2: | |
301 print "%s in state %s, but not listed in either manifest" % (f, state) | |
302 errors += 1 | |
303 for f in m1: | |
304 state = repo.dirstate.state(f) | |
305 if state not in "nrm": | |
306 print "%s in manifest1, but listed as state %s" % (f, state) | |
307 errors += 1 | |
308 if errors: | |
309 print ".hg/dirstate inconsistent with current parent's manifest, aborting" | |
310 sys.exit(1) | |
311 | |
312 def debugdumpdirstate(ui, repo): | |
313 dc = repo.dirstate.dup() | |
314 keys = dc.keys() | |
315 keys.sort() | |
316 for file in keys: | |
317 print "%s => %c" % (file, dc[file][0]) | |
318 | |
248 | 319 def debugindex(ui, file): |
417 | 320 r = hg.revlog(hg.opener(""), file, "") |
248 | 321 print " rev offset length base linkrev"+\ |
322 " p1 p2 nodeid" | |
323 for i in range(r.count()): | |
324 e = r.index[i] | |
325 print "% 6d % 9d % 7d % 6d % 7d %s.. %s.. %s.." % ( | |
326 i, e[0], e[1], e[2], e[3], | |
327 hg.hex(e[4][:5]), hg.hex(e[5][:5]), hg.hex(e[6][:5])) | |
328 | |
329 def debugindexdot(ui, file): | |
417 | 330 r = hg.revlog(hg.opener(""), file, "") |
248 | 331 print "digraph G {" |
332 for i in range(r.count()): | |
333 e = r.index[i] | |
334 print "\t%d -> %d" % (r.rev(e[4]), i) | |
335 if e[5] != hg.nullid: | |
336 print "\t%d -> %d" % (r.rev(e[5]), i) | |
337 print "}" | |
338 | |
245 | 339 def diff(ui, repo, *files, **opts): |
255 | 340 """diff working directory (or selected files)""" |
245 | 341 revs = [] |
342 if opts['rev']: | |
343 revs = map(lambda x: repo.lookup(x), opts['rev']) | |
396
8f8bb77d560e
Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
395
diff
changeset
|
344 |
245 | 345 if len(revs) > 2: |
346 self.ui.warn("too many revisions to diff\n") | |
347 sys.exit(1) | |
348 | |
349 if files: | |
350 files = relpath(repo, files) | |
351 else: | |
352 files = relpath(repo, [""]) | |
353 | |
396
8f8bb77d560e
Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
395
diff
changeset
|
354 dodiff(ui, repo, os.getcwd(), files, *revs) |
245 | 355 |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
356 def export(ui, repo, changeset): |
255 | 357 """dump the changeset header and diffs for a revision""" |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
358 node = repo.lookup(changeset) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
359 prev, other = repo.changelog.parents(node) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
360 change = repo.changelog.read(node) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
361 print "# HG changeset patch" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
362 print "# User %s" % change[1] |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
363 print "# Node ID %s" % hg.hex(node) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
364 print "# Parent %s" % hg.hex(prev) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
365 print |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
366 if other != hg.nullid: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
367 print "# Parent %s" % hg.hex(other) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
368 print change[4].rstrip() |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
369 print |
396
8f8bb77d560e
Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
395
diff
changeset
|
370 |
8f8bb77d560e
Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
395
diff
changeset
|
371 dodiff(ui, repo, "", None, prev, node) |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
372 |
245 | 373 def forget(ui, repo, file, *files): |
374 """don't add the specified files on the next commit""" | |
375 repo.forget(relpath(repo, (file,) + files)) | |
376 | |
221 | 377 def heads(ui, repo): |
329
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
378 """show current repository heads""" |
221 | 379 for n in repo.changelog.heads(): |
329
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
380 show_changeset(ui, repo, changenode=n) |
221 | 381 |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
382 def history(ui, repo): |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
383 """show the changelog history""" |
270
5a80ed2158c8
Reverse order of hg log and hg history lists
mpm@selenic.com
parents:
268
diff
changeset
|
384 for i in range(repo.changelog.count() - 1, -1, -1): |
329
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
385 show_changeset(ui, repo, rev=i) |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
386 |
339
a76fc9c4b67b
added hg identify|id (based on a patch from Andrew Thompson)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
338
diff
changeset
|
387 def identify(ui, repo): |
a76fc9c4b67b
added hg identify|id (based on a patch from Andrew Thompson)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
338
diff
changeset
|
388 """print information about the working copy""" |
343 | 389 parents = [p for p in repo.dirstate.parents() if p != hg.nullid] |
340
97a897d32dfc
Handle the case where the current working copy is not based on a checkout.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
339
diff
changeset
|
390 if not parents: |
343 | 391 ui.write("unknown\n") |
340
97a897d32dfc
Handle the case where the current working copy is not based on a checkout.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
339
diff
changeset
|
392 return |
97a897d32dfc
Handle the case where the current working copy is not based on a checkout.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
339
diff
changeset
|
393 |
386
494c8e3f47f3
Improvements for hg identify:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
371
diff
changeset
|
394 hexfunc = ui.verbose and hg.hex or hg.short |
494c8e3f47f3
Improvements for hg identify:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
371
diff
changeset
|
395 (c, a, d, u) = repo.diffdir(repo.root) |
494c8e3f47f3
Improvements for hg identify:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
371
diff
changeset
|
396 output = ["%s%s" % ('+'.join([hexfunc(parent) for parent in parents]), |
494c8e3f47f3
Improvements for hg identify:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
371
diff
changeset
|
397 (c or a or d) and "+" or "")] |
494c8e3f47f3
Improvements for hg identify:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
371
diff
changeset
|
398 |
339
a76fc9c4b67b
added hg identify|id (based on a patch from Andrew Thompson)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
338
diff
changeset
|
399 if not ui.quiet: |
386
494c8e3f47f3
Improvements for hg identify:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
371
diff
changeset
|
400 # multiple tags for a single parent separated by '/' |
494c8e3f47f3
Improvements for hg identify:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
371
diff
changeset
|
401 parenttags = ['/'.join(tags) |
494c8e3f47f3
Improvements for hg identify:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
371
diff
changeset
|
402 for tags in map(repo.nodetags, parents) if tags] |
494c8e3f47f3
Improvements for hg identify:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
371
diff
changeset
|
403 # tags for multiple parents separated by ' + ' |
494c8e3f47f3
Improvements for hg identify:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
371
diff
changeset
|
404 output.append(' + '.join(parenttags)) |
339
a76fc9c4b67b
added hg identify|id (based on a patch from Andrew Thompson)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
338
diff
changeset
|
405 |
386
494c8e3f47f3
Improvements for hg identify:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
371
diff
changeset
|
406 ui.write("%s\n" % ' '.join(output)) |
339
a76fc9c4b67b
added hg identify|id (based on a patch from Andrew Thompson)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
338
diff
changeset
|
407 |
437 | 408 def import_(ui, repo, patch1, *patches, **opts): |
409 """import an ordered set of patches""" | |
410 try: | |
411 import psyco | |
412 psyco.full() | |
413 except: | |
414 pass | |
415 | |
416 patches = (patch1,) + patches | |
417 | |
418 d = opts["base"] | |
419 strip = opts["strip"] | |
420 | |
421 for patch in patches: | |
422 ui.status("applying %s\n" % patch) | |
423 pf = os.path.join(d, patch) | |
424 | |
425 text = "" | |
426 for l in file(pf): | |
427 if l[:4] == "--- ": break | |
428 text += l | |
429 | |
430 # make sure text isn't empty | |
431 if not text: text = "imported patch %s\n" % patch | |
432 | |
433 f = os.popen("patch -p%d < %s" % (strip, pf)) | |
434 files = [] | |
435 for l in f.read().splitlines(): | |
436 l.rstrip('\r\n'); | |
437 if not quiet: | |
438 print l | |
439 if l[:14] == 'patching file ': | |
443 | 440 pf = l[14:] |
441 if pf not in files: | |
442 files.append(pf) | |
443 patcherr = f.close() | |
444 if patcherr: | |
445 sys.stderr.write("patch failed") | |
446 sys.exit(1) | |
437 | 447 |
448 if len(files) > 0: | |
449 addremove(ui, repo, *files) | |
450 repo.commit(files, text) | |
451 | |
393 | 452 def init(ui, source=None, **opts): |
290 | 453 """create a new repository or copy an existing one""" |
454 | |
455 if source: | |
456 paths = {} | |
457 for name, path in ui.configitems("paths"): | |
458 paths[name] = path | |
459 | |
460 if source in paths: source = paths[source] | |
255 | 461 |
290 | 462 link = 0 |
463 if not source.startswith("http://"): | |
464 d1 = os.stat(os.getcwd()).st_dev | |
465 d2 = os.stat(source).st_dev | |
466 if d1 == d2: link = 1 | |
467 | |
468 if link: | |
469 ui.debug("copying by hardlink\n") | |
470 os.system("cp -al %s/.hg .hg" % source) | |
300 | 471 try: |
472 os.remove(".hg/dirstate") | |
473 except: pass | |
338 | 474 |
475 repo = hg.repository(ui, ".") | |
476 | |
290 | 477 else: |
478 repo = hg.repository(ui, ".", create=1) | |
479 other = hg.repository(ui, source) | |
480 cg = repo.getchangegroup(other) | |
481 repo.addchangegroup(cg) | |
390
50aea13227a2
create .hg/hgrc with [paths] default entry only if source was given on hg init.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
387
diff
changeset
|
482 |
50aea13227a2
create .hg/hgrc with [paths] default entry only if source was given on hg init.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
387
diff
changeset
|
483 f = repo.opener("hgrc", "w") |
50aea13227a2
create .hg/hgrc with [paths] default entry only if source was given on hg init.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
387
diff
changeset
|
484 f.write("[paths]\n") |
50aea13227a2
create .hg/hgrc with [paths] default entry only if source was given on hg init.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
387
diff
changeset
|
485 f.write("default = %s\n" % source) |
393 | 486 |
487 if opts['update']: | |
488 update(ui, repo) | |
290 | 489 else: |
338 | 490 repo = hg.repository(ui, ".", create=1) |
491 | |
255 | 492 def log(ui, repo, f): |
493 """show the revision history of a single file""" | |
494 f = relpath(repo, [f])[0] | |
495 | |
496 r = repo.file(f) | |
270
5a80ed2158c8
Reverse order of hg log and hg history lists
mpm@selenic.com
parents:
268
diff
changeset
|
497 for i in range(r.count() - 1, -1, -1): |
329
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
498 show_changeset(ui, repo, filelog=r, rev=i) |
255 | 499 |
500 def manifest(ui, repo, rev = []): | |
501 """output the latest or given revision of the project manifest""" | |
502 n = repo.manifest.tip() | |
503 if rev: | |
504 n = repo.manifest.lookup(rev) | |
505 m = repo.manifest.read(n) | |
276 | 506 mf = repo.manifest.readflags(n) |
255 | 507 files = m.keys() |
508 files.sort() | |
509 | |
510 for f in files: | |
276 | 511 ui.write("%40s %3s %s\n" % (hg.hex(m[f]), mf[f] and "755" or "644", f)) |
255 | 512 |
513 def parents(ui, repo, node = None): | |
514 '''show the parents of the current working dir''' | |
515 if node: | |
516 p = repo.changelog.parents(repo.lookup(hg.bin(node))) | |
517 else: | |
518 p = repo.dirstate.parents() | |
519 | |
520 for n in p: | |
521 if n != hg.nullid: | |
329
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
522 show_changeset(ui, repo, changenode=n) |
255 | 523 |
404 | 524 def pull(ui, repo, source="default", **opts): |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
525 """pull changes from the specified source""" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
526 paths = {} |
286 | 527 for name, path in ui.configitems("paths"): |
290 | 528 paths[name] = path |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
529 |
404 | 530 if source in paths: |
531 source = paths[source] | |
532 | |
533 ui.status('pulling from %s\n' % (source)) | |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
534 |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
535 other = hg.repository(ui, source) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
536 cg = repo.getchangegroup(other) |
404 | 537 r = repo.addchangegroup(cg) |
538 if cg and not r: | |
539 if opts['update']: | |
540 return update(ui, repo) | |
541 else: | |
542 ui.status("(run 'hg update' to get a working copy)\n") | |
543 | |
544 return r | |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
545 |
371
6e3436082697
hg push: "default-push" default target path
mpm@selenic.com
parents:
367
diff
changeset
|
546 def push(ui, repo, dest="default-push"): |
319 | 547 """push changes to the specified destination""" |
548 paths = {} | |
549 for name, path in ui.configitems("paths"): | |
550 paths[name] = path | |
551 | |
552 if dest in paths: dest = paths[dest] | |
553 | |
554 if not dest.startswith("ssh://"): | |
555 ui.warn("abort: can only push to ssh:// destinations currently\n") | |
556 return 1 | |
557 | |
558 m = re.match(r'ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?', dest) | |
559 if not m: | |
560 ui.warn("abort: couldn't parse destination %s\n" % dest) | |
561 return 1 | |
562 | |
563 user, host, port, path = map(m.group, (2, 3, 5, 7)) | |
564 host = user and ("%s@%s" % (user, host)) or host | |
565 port = port and (" -p %s") % port or "" | |
566 path = path or "" | |
567 | |
568 sport = random.randrange(30000, 60000) | |
569 cmd = "ssh %s%s -R %d:localhost:%d 'cd %s; hg pull http://localhost:%d/'" | |
570 cmd = cmd % (host, port, sport+1, sport, path, sport+1) | |
571 | |
572 child = os.fork() | |
573 if not child: | |
574 sys.stdout = file("/dev/null", "w") | |
575 sys.stderr = sys.stdout | |
576 hgweb.server(repo.root, "pull", "", "localhost", sport) | |
577 else: | |
578 r = os.system(cmd) | |
579 os.kill(child, signal.SIGTERM) | |
320 | 580 return r |
319 | 581 |
403 | 582 def rawcommit(ui, repo, *flist, **rc): |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
583 "raw commit interface" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
584 |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
585 text = rc['text'] |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
586 if not text and rc['logfile']: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
587 try: text = open(rc['logfile']).read() |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
588 except IOError: pass |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
589 if not text and not rc['logfile']: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
590 print "missing commit text" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
591 return 1 |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
592 |
403 | 593 files = relpath(repo, list(flist)) |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
594 if rc['files']: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
595 files += open(rc['files']).read().splitlines() |
452
a1e91c24dab5
rawcommit: do lookup of parents at the appropriate layer
mpm@selenic.com
parents:
443
diff
changeset
|
596 |
a1e91c24dab5
rawcommit: do lookup of parents at the appropriate layer
mpm@selenic.com
parents:
443
diff
changeset
|
597 rc['parent'] = map(repo.lookup, rc['parent']) |
a1e91c24dab5
rawcommit: do lookup of parents at the appropriate layer
mpm@selenic.com
parents:
443
diff
changeset
|
598 |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
599 repo.rawcommit(files, text, rc['user'], rc['date'], *rc['parent']) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
600 |
245 | 601 def recover(ui, repo): |
255 | 602 """roll back an interrupted transaction""" |
245 | 603 repo.recover() |
604 | |
605 def remove(ui, repo, file, *files): | |
606 """remove the specified files on the next commit""" | |
607 repo.remove(relpath(repo, (file,) + files)) | |
608 | |
468 | 609 def root(ui, repo): |
610 """print the root (top) of the current working dir""" | |
611 ui.write(repo.root + "\n") | |
612 | |
245 | 613 def serve(ui, repo, **opts): |
255 | 614 """export the repository via HTTP""" |
245 | 615 hgweb.server(repo.root, opts["name"], opts["templates"], |
616 opts["address"], opts["port"]) | |
617 | |
213 | 618 def status(ui, repo): |
619 '''show changed files in the working directory | |
620 | |
245 | 621 C = changed |
622 A = added | |
623 R = removed | |
624 ? = not tracked''' | |
312 | 625 |
626 (c, a, d, u) = repo.diffdir(os.getcwd()) | |
220 | 627 (c, a, d, u) = map(lambda x: relfilter(repo, x), (c, a, d, u)) |
213 | 628 |
629 for f in c: print "C", f | |
220 | 630 for f in a: print "A", f |
213 | 631 for f in d: print "R", f |
220 | 632 for f in u: print "?", f |
213 | 633 |
401
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
634 def tag(ui, repo, name, rev = None, **opts): |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
635 """add a tag for the current tip or a given revision""" |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
636 |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
637 if name == "tip": |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
638 ui.warn("abort: 'tip' is a reserved name!\n") |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
639 return -1 |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
640 |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
641 (c, a, d, u) = repo.diffdir(repo.root) |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
642 for x in (c, a, d, u): |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
643 if ".hgtags" in x: |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
644 ui.warn("abort: working copy of .hgtags is changed!\n") |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
645 ui.status("(please commit .hgtags manually)\n") |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
646 return -1 |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
647 |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
648 if rev: |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
649 r = hg.hex(repo.lookup(rev)) |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
650 else: |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
651 r = hg.hex(repo.changelog.tip()) |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
652 |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
653 add = 0 |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
654 if not os.path.exists(repo.wjoin(".hgtags")): add = 1 |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
655 repo.wfile(".hgtags", "a").write("%s %s\n" % (r, name)) |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
656 if add: repo.add([".hgtags"]) |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
657 |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
658 if not opts['text']: |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
659 opts['text'] = "Added tag %s for changeset %s" % (name, r) |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
660 |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
661 repo.commit([".hgtags"], opts['text'], opts['user'], opts['date']) |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
662 |
248 | 663 def tags(ui, repo): |
255 | 664 """list repository tags""" |
343 | 665 |
666 l = repo.tagslist() | |
667 l.reverse() | |
668 for t,n in l: | |
248 | 669 try: |
670 r = repo.changelog.rev(n) | |
671 except KeyError: | |
672 r = "?" | |
343 | 673 print "%-30s %5d:%s" % (t, repo.changelog.rev(n), hg.hex(n)) |
248 | 674 |
245 | 675 def tip(ui, repo): |
255 | 676 """show the tip revision""" |
245 | 677 n = repo.changelog.tip() |
329
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
678 show_changeset(ui, repo, changenode=n) |
245 | 679 |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
680 def undo(ui, repo): |
255 | 681 """undo the last transaction""" |
210 | 682 repo.undo() |
683 | |
275 | 684 def update(ui, repo, node=None, merge=False, clean=False): |
254 | 685 '''update or merge working directory |
686 | |
687 If there are no outstanding changes in the working directory and | |
688 there is a linear relationship between the current version and the | |
689 requested version, the result is the requested version. | |
690 | |
691 Otherwise the result is a merge between the contents of the | |
692 current working directory and the requested version. Files that | |
693 changed between either parent are marked as changed for the next | |
694 commit and a commit must be performed before any further updates | |
695 are allowed. | |
696 ''' | |
697 node = node and repo.lookup(node) or repo.changelog.tip() | |
275 | 698 return repo.update(node, allow=merge, force=clean) |
254 | 699 |
247 | 700 def verify(ui, repo): |
701 """verify the integrity of the repository""" | |
702 return repo.verify() | |
703 | |
255 | 704 # Command options and aliases are listed here, alphabetically |
705 | |
209 | 706 table = { |
245 | 707 "add": (add, [], "hg add [files]"), |
353 | 708 "addremove": (addremove, [], "hg addremove [files]"), |
437 | 709 "annotate": (annotate, |
209 | 710 [('r', 'revision', '', 'revision'), |
711 ('u', 'user', None, 'show user'), | |
712 ('n', 'number', None, 'show revision number'), | |
713 ('c', 'changeset', None, 'show changeset')], | |
714 'hg annotate [-u] [-c] [-n] [-r id] [files]'), | |
437 | 715 "cat": (cat, [], 'hg cat <file> [rev]'), |
289 | 716 "commit|ci": (commit, |
717 [('t', 'text', "", 'commit text'), | |
354 | 718 ('A', 'addremove', None, 'run add/remove during commit'), |
317 | 719 ('l', 'logfile', "", 'commit text file'), |
720 ('d', 'date', "", 'data'), | |
721 ('u', 'user', "", 'user')], | |
289 | 722 'hg commit [files]'), |
363 | 723 "copy": (copy, [], 'hg copy <source> <dest>'), |
460 | 724 "debugcheckdirstate": (debugcheckdirstate, [], 'debugcheckdirstate'), |
725 "debugdumpdirstate": (debugdumpdirstate, [], 'debugdumpdirstate'), | |
248 | 726 "debugindex": (debugindex, [], 'debugindex <file>'), |
727 "debugindexdot": (debugindexdot, [], 'debugindexdot <file>'), | |
245 | 728 "diff": (diff, [('r', 'rev', [], 'revision')], |
729 'hg diff [-r A] [-r B] [files]'), | |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
730 "export": (export, [], "hg export <changeset>"), |
245 | 731 "forget": (forget, [], "hg forget [files]"), |
732 "heads": (heads, [], 'hg heads'), | |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
733 "history": (history, [], 'hg history'), |
245 | 734 "help": (help, [], 'hg help [command]'), |
339
a76fc9c4b67b
added hg identify|id (based on a patch from Andrew Thompson)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
338
diff
changeset
|
735 "identify|id": (identify, [], 'hg identify'), |
437 | 736 "import|patch": (import_, |
737 [('p', 'strip', 1, 'path strip'), | |
738 ('b', 'base', "", 'base path')], | |
739 "hg import [options] <patches>"), | |
393 | 740 "init": (init, [('u', 'update', None, 'update after init')], |
741 'hg init [options] [url]'), | |
245 | 742 "log": (log, [], 'hg log <file>'), |
437 | 743 "manifest": (manifest, [], 'hg manifest [rev]'), |
227 | 744 "parents": (parents, [], 'hg parents [node]'), |
437 | 745 "pull": (pull, |
404 | 746 [('u', 'update', None, 'update working directory')], |
747 'hg pull [options] [source]'), | |
319 | 748 "push": (push, [], 'hg push <destination>'), |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
749 "rawcommit": (rawcommit, |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
750 [('p', 'parent', [], 'parent'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
751 ('d', 'date', "", 'data'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
752 ('u', 'user', "", 'user'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
753 ('F', 'files', "", 'file list'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
754 ('t', 'text', "", 'commit text'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
755 ('l', 'logfile', "", 'commit text file')], |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
756 'hg rawcommit [options] [files]'), |
245 | 757 "recover": (recover, [], "hg recover"), |
437 | 758 "remove|rm": (remove, [], "hg remove [files]"), |
468 | 759 "root": (root, [], "hg root"), |
245 | 760 "serve": (serve, [('p', 'port', 8000, 'listen port'), |
761 ('a', 'address', '', 'interface address'), | |
762 ('n', 'name', os.getcwd(), 'repository name'), | |
763 ('t', 'templates', "", 'template map')], | |
764 "hg serve [options]"), | |
213 | 765 "status": (status, [], 'hg status'), |
401
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
766 "tag": (tag, [('t', 'text', "", 'commit text'), |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
767 ('d', 'date', "", 'date'), |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
768 ('u', 'user', "", 'user')], |
af4848f83e68
From: Radoslaw Szkodzinski <astralstorm@gorzow.mm.pl>
mpm@selenic.com
parents:
396
diff
changeset
|
769 'hg tag [options] <name> [rev]'), |
248 | 770 "tags": (tags, [], 'hg tags'), |
245 | 771 "tip": (tip, [], 'hg tip'), |
210 | 772 "undo": (undo, [], 'hg undo'), |
437 | 773 "update|up|checkout|co": |
774 (update, | |
775 [('m', 'merge', None, 'allow merging of conflicts'), | |
776 ('C', 'clean', None, 'overwrite locally modified files')], | |
777 'hg update [options] [node]'), | |
247 | 778 "verify": (verify, [], 'hg verify'), |
470
0ab093b473c5
Fix up version module name and command conflict
mpm@selenic.com
parents:
468
diff
changeset
|
779 "version": (show_version, [], 'hg version'), |
209 | 780 } |
781 | |
423
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
396
diff
changeset
|
782 norepo = "init version help debugindex debugindexdot" |
209 | 783 |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
784 def find(cmd): |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
785 i = None |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
786 for e in table.keys(): |
335 | 787 if re.match("(%s)$" % e, cmd): |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
788 return table[e] |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
789 |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
790 raise UnknownCommand(cmd) |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
791 |
214 | 792 class SignalInterrupt(Exception): pass |
793 | |
794 def catchterm(*args): | |
795 raise SignalInterrupt | |
796 | |
249 | 797 def run(): |
798 sys.exit(dispatch(sys.argv[1:])) | |
799 | |
209 | 800 def dispatch(args): |
801 options = {} | |
802 opts = [('v', 'verbose', None, 'verbose'), | |
803 ('d', 'debug', None, 'debug'), | |
804 ('q', 'quiet', None, 'quiet'), | |
309 | 805 ('p', 'profile', None, 'profile'), |
209 | 806 ('y', 'noninteractive', None, 'run non-interactively'), |
423
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
396
diff
changeset
|
807 ('', 'version', None, 'output version information and exit'), |
209 | 808 ] |
809 | |
810 args = fancyopts.fancyopts(args, opts, options, | |
811 'hg [options] <command> [options] [files]') | |
812 | |
813 if not args: | |
814 cmd = "help" | |
815 else: | |
816 cmd, args = args[0], args[1:] | |
817 | |
818 u = ui.ui(options["verbose"], options["debug"], options["quiet"], | |
819 not options["noninteractive"]) | |
820 | |
423
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
396
diff
changeset
|
821 if options["version"]: |
470
0ab093b473c5
Fix up version module name and command conflict
mpm@selenic.com
parents:
468
diff
changeset
|
822 show_version(u) |
423
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
396
diff
changeset
|
823 sys.exit(0) |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
396
diff
changeset
|
824 |
252 | 825 try: |
826 i = find(cmd) | |
827 except UnknownCommand: | |
268 | 828 u.warn("hg: unknown command '%s'\n" % cmd) |
252 | 829 help(u) |
830 sys.exit(1) | |
209 | 831 |
214 | 832 signal.signal(signal.SIGTERM, catchterm) |
833 | |
209 | 834 cmdoptions = {} |
293 | 835 try: |
836 args = fancyopts.fancyopts(args, i[1], cmdoptions, i[2]) | |
837 except fancyopts.getopt.GetoptError, inst: | |
838 u.warn("hg %s: %s\n" % (cmd, inst)) | |
839 help(u, cmd) | |
840 sys.exit(-1) | |
209 | 841 |
842 if cmd not in norepo.split(): | |
843 repo = hg.repository(ui = u) | |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
844 d = lambda: i[0](u, repo, *args, **cmdoptions) |
209 | 845 else: |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
846 d = lambda: i[0](u, *args, **cmdoptions) |
209 | 847 |
848 try: | |
309 | 849 if options['profile']: |
850 import hotshot, hotshot.stats | |
851 prof = hotshot.Profile("hg.prof") | |
852 r = prof.runcall(d) | |
853 prof.close() | |
854 stats = hotshot.stats.load("hg.prof") | |
855 stats.strip_dirs() | |
856 stats.sort_stats('time', 'calls') | |
857 stats.print_stats(40) | |
858 return r | |
859 else: | |
860 return d() | |
214 | 861 except SignalInterrupt: |
862 u.warn("killed!\n") | |
209 | 863 except KeyboardInterrupt: |
864 u.warn("interrupted!\n") | |
250 | 865 except IOError, inst: |
395 | 866 if hasattr(inst, "code"): |
867 u.warn("abort: %s\n" % inst) | |
868 elif hasattr(inst, "reason"): | |
869 u.warn("abort: error %d: %s\n" % (inst.reason[0], inst.reason[1])) | |
870 elif hasattr(inst, "args") and inst[0] == errno.EPIPE: | |
250 | 871 u.warn("broken pipe\n") |
872 else: | |
873 raise | |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
874 except TypeError, inst: |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
875 # was this an argument error? |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
876 tb = traceback.extract_tb(sys.exc_info()[2]) |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
877 if len(tb) > 2: # no |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
878 raise |
293 | 879 u.debug(inst, "\n") |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
880 u.warn("%s: invalid arguments\n" % i[0].__name__) |
293 | 881 help(u, cmd) |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
882 sys.exit(-1) |
293 | 883 |