author | Thomas Arendsen Hein <thomas@intevation.de> |
Mon, 13 Jun 2005 08:49:21 +0100 | |
changeset 329 | 67c19ad374a9 |
parent 320 | 292e10b5831a |
child 330 | 27d08c0c2a7e |
permissions | -rw-r--r-- |
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 |
9 |
import fancyopts, ui, hg |
|
10 |
from demandload import * |
|
319 | 11 |
demandload(globals(), "mdiff time hgweb traceback random signal") |
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: |
19 |
if t and t[-1] != os.sep: t += os.sep |
|
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: ] |
|
281 | 26 |
return filterfiles([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: ] |
|
245 | 32 |
return [ os.path.normpath(os.path.join(p, x)) for x in args ] |
209 | 33 |
return args |
245 | 34 |
|
312 | 35 |
def dodiff(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] |
|
50 |
def read(f): return file(os.path.join(repo.root, f)).read() |
|
51 |
||
52 |
change = repo.changelog.read(node1) |
|
53 |
mmap = repo.manifest.read(change[0]) |
|
54 |
date1 = date(change) |
|
55 |
||
56 |
if files: |
|
57 |
c, a, d = map(lambda x: filterfiles(files, x), (c, a, d)) |
|
58 |
||
59 |
for f in c: |
|
275 | 60 |
to = None |
61 |
if f in mmap: |
|
62 |
to = repo.file(f).read(mmap[f]) |
|
245 | 63 |
tn = read(f) |
64 |
sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) |
|
65 |
for f in a: |
|
264
4c1d7072d5cd
Attempt to make diff deal with null sources properly
mpm@selenic.com
parents:
262
diff
changeset
|
66 |
to = None |
245 | 67 |
tn = read(f) |
68 |
sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) |
|
69 |
for f in d: |
|
70 |
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
|
71 |
tn = None |
245 | 72 |
sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) |
329
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
73 |
|
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
74 |
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
|
75 |
"""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
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
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
|
81 |
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
|
82 |
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
|
83 |
else: |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
84 |
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
|
85 |
log = changelog |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
86 |
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
|
87 |
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
|
88 |
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
|
89 |
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
|
90 |
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
|
91 |
|
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 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
|
93 |
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
|
94 |
return |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
95 |
|
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
96 |
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
|
97 |
description = changes[4].strip().splitlines() |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
98 |
|
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
99 |
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
|
100 |
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
|
101 |
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
|
102 |
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
|
103 |
parents = [] |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
104 |
|
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
105 |
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
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
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
|
110 |
else: |
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("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
|
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.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
|
115 |
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
|
116 |
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
|
117 |
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
|
118 |
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
|
119 |
ui.note("files: %s\n" % " ".join(changes[3])) |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
120 |
if description: |
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.status("description: %s\n" % description[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 |
ui.note(''.join(["| %s\n" % line.rstrip() for line in description[1:]])) |
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("\n") |
67c19ad374a9
Use common output function show_changeset() for hg heads|history|log|tip.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
320
diff
changeset
|
124 |
|
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
125 |
def help(ui, cmd=None): |
255 | 126 |
'''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
|
127 |
if cmd: |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
128 |
try: |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
129 |
i = find(cmd) |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
130 |
ui.write("%s\n\n" % i[2]) |
293 | 131 |
|
132 |
if i[1]: |
|
133 |
for s, l, d, c in i[1]: |
|
134 |
opt=' ' |
|
135 |
if s: opt = opt + '-' + s + ' ' |
|
136 |
if l: opt = opt + '--' + l + ' ' |
|
137 |
if d: opt = opt + '(' + str(d) + ')' |
|
138 |
ui.write(opt, "\n") |
|
139 |
if c: ui.write(' %s\n' % c) |
|
140 |
ui.write("\n") |
|
141 |
||
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
142 |
ui.write(i[0].__doc__, "\n") |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
143 |
except UnknownCommand: |
268 | 144 |
ui.warn("hg: unknown command %s\n" % cmd) |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
145 |
sys.exit(0) |
255 | 146 |
else: |
147 |
ui.status('hg commands:\n\n') |
|
209 | 148 |
|
255 | 149 |
h = {} |
150 |
for e in table.values(): |
|
151 |
f = e[0] |
|
152 |
if f.__name__.startswith("debug"): continue |
|
153 |
d = "" |
|
154 |
if f.__doc__: |
|
155 |
d = f.__doc__.splitlines(0)[0].rstrip() |
|
156 |
h[f.__name__] = d |
|
157 |
||
158 |
fns = h.keys() |
|
159 |
fns.sort() |
|
160 |
m = max(map(len, fns)) |
|
161 |
for f in fns: |
|
162 |
ui.status(' %-*s %s\n' % (m, f, h[f])) |
|
163 |
||
164 |
# Commands start here, listed alphabetically |
|
209 | 165 |
|
245 | 166 |
def add(ui, repo, file, *files): |
167 |
'''add the specified files on the next commit''' |
|
168 |
repo.add(relpath(repo, (file,) + files)) |
|
213 | 169 |
|
245 | 170 |
def addremove(ui, repo): |
255 | 171 |
"""add all new files, delete all missing files""" |
230 | 172 |
(c, a, d, u) = repo.diffdir(repo.root) |
259 | 173 |
repo.add(u) |
245 | 174 |
repo.remove(d) |
219
8ff4532376a4
hg checkout: refuse to checkout if there are outstanding changes
mpm@selenic.com
parents:
214
diff
changeset
|
175 |
|
245 | 176 |
def annotate(u, repo, file, *files, **ops): |
255 | 177 |
"""show changeset information per file line""" |
209 | 178 |
def getnode(rev): |
179 |
return hg.short(repo.changelog.node(rev)) |
|
180 |
||
181 |
def getname(rev): |
|
182 |
try: |
|
183 |
return bcache[rev] |
|
184 |
except KeyError: |
|
185 |
cl = repo.changelog.read(repo.changelog.node(rev)) |
|
186 |
name = cl[1] |
|
187 |
f = name.find('@') |
|
188 |
if f >= 0: |
|
189 |
name = name[:f] |
|
190 |
bcache[rev] = name |
|
191 |
return name |
|
192 |
||
193 |
bcache = {} |
|
194 |
opmap = [['user', getname], ['number', str], ['changeset', getnode]] |
|
195 |
if not ops['user'] and not ops['changeset']: |
|
196 |
ops['number'] = 1 |
|
197 |
||
227 | 198 |
node = repo.dirstate.parents()[0] |
209 | 199 |
if ops['revision']: |
200 |
node = repo.changelog.lookup(ops['revision']) |
|
201 |
change = repo.changelog.read(node) |
|
202 |
mmap = repo.manifest.read(change[0]) |
|
203 |
maxuserlen = 0 |
|
204 |
maxchangelen = 0 |
|
245 | 205 |
for f in relpath(repo, (file,) + files): |
209 | 206 |
lines = repo.file(f).annotate(mmap[f]) |
207 |
pieces = [] |
|
208 |
||
209 |
for o, f in opmap: |
|
210 |
if ops[o]: |
|
211 |
l = [ f(n) for n,t in lines ] |
|
212 |
m = max(map(len, l)) |
|
213 |
pieces.append([ "%*s" % (m, x) for x in l]) |
|
214 |
||
215 |
for p,l in zip(zip(*pieces), lines): |
|
216 |
u.write(" ".join(p) + ": " + l[1]) |
|
217 |
||
248 | 218 |
def cat(ui, repo, file, rev = []): |
255 | 219 |
"""output the latest or given revision of a file""" |
281 | 220 |
r = repo.file(relpath(repo, [file])[0]) |
248 | 221 |
n = r.tip() |
222 |
if rev: n = r.lookup(rev) |
|
223 |
sys.stdout.write(r.read(n)) |
|
224 |
||
289 | 225 |
def commit(ui, repo, *files, **opts): |
245 | 226 |
"""commit the specified files or all outstanding changes""" |
289 | 227 |
text = opts['text'] |
228 |
if not text and opts['logfile']: |
|
229 |
try: text = open(opts['logfile']).read() |
|
230 |
except IOError: pass |
|
231 |
||
317 | 232 |
repo.commit(relpath(repo, files), text, opts['user'], opts['date']) |
245 | 233 |
|
248 | 234 |
def debugaddchangegroup(ui, repo): |
235 |
data = sys.stdin.read() |
|
236 |
repo.addchangegroup(data) |
|
237 |
||
238 |
def debugchangegroup(ui, repo, roots): |
|
239 |
newer = repo.newer(map(repo.lookup, roots)) |
|
240 |
for chunk in repo.changegroup(newer): |
|
241 |
sys.stdout.write(chunk) |
|
242 |
||
243 |
def debugindex(ui, file): |
|
244 |
r = hg.revlog(open, file, "") |
|
245 |
print " rev offset length base linkrev"+\ |
|
246 |
" p1 p2 nodeid" |
|
247 |
for i in range(r.count()): |
|
248 |
e = r.index[i] |
|
249 |
print "% 6d % 9d % 7d % 6d % 7d %s.. %s.. %s.." % ( |
|
250 |
i, e[0], e[1], e[2], e[3], |
|
251 |
hg.hex(e[4][:5]), hg.hex(e[5][:5]), hg.hex(e[6][:5])) |
|
252 |
||
253 |
def debugindexdot(ui, file): |
|
254 |
r = hg.revlog(open, file, "") |
|
255 |
print "digraph G {" |
|
256 |
for i in range(r.count()): |
|
257 |
e = r.index[i] |
|
258 |
print "\t%d -> %d" % (r.rev(e[4]), i) |
|
259 |
if e[5] != hg.nullid: |
|
260 |
print "\t%d -> %d" % (r.rev(e[5]), i) |
|
261 |
print "}" |
|
262 |
||
245 | 263 |
def diff(ui, repo, *files, **opts): |
255 | 264 |
"""diff working directory (or selected files)""" |
245 | 265 |
revs = [] |
266 |
if opts['rev']: |
|
267 |
revs = map(lambda x: repo.lookup(x), opts['rev']) |
|
268 |
||
269 |
if len(revs) > 2: |
|
270 |
self.ui.warn("too many revisions to diff\n") |
|
271 |
sys.exit(1) |
|
272 |
||
273 |
if files: |
|
274 |
files = relpath(repo, files) |
|
275 |
else: |
|
276 |
files = relpath(repo, [""]) |
|
277 |
||
312 | 278 |
dodiff(repo, os.getcwd(), files, *revs) |
245 | 279 |
|
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
280 |
def export(ui, repo, changeset): |
255 | 281 |
"""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
|
282 |
node = repo.lookup(changeset) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
283 |
prev, other = repo.changelog.parents(node) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
284 |
change = repo.changelog.read(node) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
285 |
print "# HG changeset patch" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
286 |
print "# User %s" % change[1] |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
287 |
print "# Node ID %s" % hg.hex(node) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
288 |
print "# Parent %s" % hg.hex(prev) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
289 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
290 |
if other != hg.nullid: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
291 |
print "# Parent %s" % hg.hex(other) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
292 |
print change[4].rstrip() |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
293 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
294 |
|
312 | 295 |
dodiff(repo, "", None, prev, node) |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
296 |
|
245 | 297 |
def forget(ui, repo, file, *files): |
298 |
"""don't add the specified files on the next commit""" |
|
299 |
repo.forget(relpath(repo, (file,) + files)) |
|
300 |
||
221 | 301 |
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
|
302 |
"""show current repository heads""" |
221 | 303 |
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
|
304 |
show_changeset(ui, repo, changenode=n) |
221 | 305 |
|
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
306 |
def history(ui, repo): |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
307 |
"""show the changelog history""" |
270
5a80ed2158c8
Reverse order of hg log and hg history lists
mpm@selenic.com
parents:
268
diff
changeset
|
308 |
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
|
309 |
show_changeset(ui, repo, rev=i) |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
310 |
|
290 | 311 |
def init(ui, source=None): |
312 |
"""create a new repository or copy an existing one""" |
|
313 |
||
314 |
if source: |
|
315 |
paths = {} |
|
316 |
for name, path in ui.configitems("paths"): |
|
317 |
paths[name] = path |
|
318 |
||
319 |
if source in paths: source = paths[source] |
|
255 | 320 |
|
290 | 321 |
link = 0 |
322 |
if not source.startswith("http://"): |
|
323 |
d1 = os.stat(os.getcwd()).st_dev |
|
324 |
d2 = os.stat(source).st_dev |
|
325 |
if d1 == d2: link = 1 |
|
326 |
||
327 |
if link: |
|
328 |
ui.debug("copying by hardlink\n") |
|
329 |
os.system("cp -al %s/.hg .hg" % source) |
|
300 | 330 |
try: |
331 |
os.remove(".hg/dirstate") |
|
332 |
except: pass |
|
290 | 333 |
else: |
334 |
repo = hg.repository(ui, ".", create=1) |
|
335 |
other = hg.repository(ui, source) |
|
336 |
cg = repo.getchangegroup(other) |
|
337 |
repo.addchangegroup(cg) |
|
338 |
else: |
|
339 |
hg.repository(ui, ".", create=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
|
340 |
|
255 | 341 |
def log(ui, repo, f): |
342 |
"""show the revision history of a single file""" |
|
343 |
f = relpath(repo, [f])[0] |
|
344 |
||
345 |
r = repo.file(f) |
|
270
5a80ed2158c8
Reverse order of hg log and hg history lists
mpm@selenic.com
parents:
268
diff
changeset
|
346 |
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
|
347 |
show_changeset(ui, repo, filelog=r, rev=i) |
255 | 348 |
|
349 |
def manifest(ui, repo, rev = []): |
|
350 |
"""output the latest or given revision of the project manifest""" |
|
351 |
n = repo.manifest.tip() |
|
352 |
if rev: |
|
353 |
n = repo.manifest.lookup(rev) |
|
354 |
m = repo.manifest.read(n) |
|
276 | 355 |
mf = repo.manifest.readflags(n) |
255 | 356 |
files = m.keys() |
357 |
files.sort() |
|
358 |
||
359 |
for f in files: |
|
276 | 360 |
ui.write("%40s %3s %s\n" % (hg.hex(m[f]), mf[f] and "755" or "644", f)) |
255 | 361 |
|
362 |
def parents(ui, repo, node = None): |
|
363 |
'''show the parents of the current working dir''' |
|
364 |
if node: |
|
365 |
p = repo.changelog.parents(repo.lookup(hg.bin(node))) |
|
366 |
else: |
|
367 |
p = repo.dirstate.parents() |
|
368 |
||
369 |
for n in p: |
|
370 |
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
|
371 |
show_changeset(ui, repo, changenode=n) |
255 | 372 |
|
294
f8d56da6ac8f
hg patch: fix to actually take a list of patches
mpm@selenic.com
parents:
293
diff
changeset
|
373 |
def patch(ui, repo, patch1, *patches, **opts): |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
374 |
"""import an ordered set of patches""" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
375 |
try: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
376 |
import psyco |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
377 |
psyco.full() |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
378 |
except: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
379 |
pass |
294
f8d56da6ac8f
hg patch: fix to actually take a list of patches
mpm@selenic.com
parents:
293
diff
changeset
|
380 |
|
295 | 381 |
patches = (patch1,) + patches |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
382 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
383 |
d = opts["base"] |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
384 |
strip = opts["strip"] |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
385 |
quiet = opts["quiet"] and "> /dev/null" or "" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
386 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
387 |
for patch in patches: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
388 |
ui.status("applying %s\n" % patch) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
389 |
pf = os.path.join(d, patch) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
390 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
391 |
text = "" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
392 |
for l in file(pf): |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
393 |
if l[:4] == "--- ": break |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
394 |
text += l |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
395 |
|
310 | 396 |
# make sure text isn't empty |
397 |
if not text: text = "imported patch %s\n" % patch |
|
398 |
||
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
399 |
f = os.popen("lsdiff --strip %d %s" % (strip, pf)) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
400 |
files = filter(None, map(lambda x: x.rstrip(), f.read().splitlines())) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
401 |
f.close() |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
402 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
403 |
if files: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
404 |
if os.system("patch -p%d < %s %s" % (strip, pf, quiet)): |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
405 |
raise "patch failed!" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
406 |
repo.commit(files, text) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
407 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
408 |
def pull(ui, repo, source): |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
409 |
"""pull changes from the specified source""" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
410 |
paths = {} |
286 | 411 |
for name, path in ui.configitems("paths"): |
290 | 412 |
paths[name] = path |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
413 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
414 |
if source in paths: source = paths[source] |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
415 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
416 |
other = hg.repository(ui, source) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
417 |
cg = repo.getchangegroup(other) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
418 |
repo.addchangegroup(cg) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
419 |
|
319 | 420 |
def push(ui, repo, dest): |
421 |
"""push changes to the specified destination""" |
|
422 |
paths = {} |
|
423 |
for name, path in ui.configitems("paths"): |
|
424 |
paths[name] = path |
|
425 |
||
426 |
if dest in paths: dest = paths[dest] |
|
427 |
||
428 |
if not dest.startswith("ssh://"): |
|
429 |
ui.warn("abort: can only push to ssh:// destinations currently\n") |
|
430 |
return 1 |
|
431 |
||
432 |
m = re.match(r'ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?', dest) |
|
433 |
if not m: |
|
434 |
ui.warn("abort: couldn't parse destination %s\n" % dest) |
|
435 |
return 1 |
|
436 |
||
437 |
user, host, port, path = map(m.group, (2, 3, 5, 7)) |
|
438 |
host = user and ("%s@%s" % (user, host)) or host |
|
439 |
port = port and (" -p %s") % port or "" |
|
440 |
path = path or "" |
|
441 |
||
442 |
sport = random.randrange(30000, 60000) |
|
443 |
cmd = "ssh %s%s -R %d:localhost:%d 'cd %s; hg pull http://localhost:%d/'" |
|
444 |
cmd = cmd % (host, port, sport+1, sport, path, sport+1) |
|
445 |
||
446 |
child = os.fork() |
|
447 |
if not child: |
|
448 |
sys.stdout = file("/dev/null", "w") |
|
449 |
sys.stderr = sys.stdout |
|
450 |
hgweb.server(repo.root, "pull", "", "localhost", sport) |
|
451 |
else: |
|
452 |
r = os.system(cmd) |
|
453 |
os.kill(child, signal.SIGTERM) |
|
320 | 454 |
return r |
319 | 455 |
|
266
4af7677de4a9
Fix argument processing for patch and rawcommit
mpm@selenic.com
parents:
264
diff
changeset
|
456 |
def rawcommit(ui, repo, files, **rc): |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
457 |
"raw commit interface" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
458 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
459 |
text = rc['text'] |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
460 |
if not text and rc['logfile']: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
461 |
try: text = open(rc['logfile']).read() |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
462 |
except IOError: pass |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
463 |
if not text and not rc['logfile']: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
464 |
print "missing commit text" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
465 |
return 1 |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
466 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
467 |
files = relpath(repo, files) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
468 |
if rc['files']: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
469 |
files += open(rc['files']).read().splitlines() |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
470 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
471 |
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
|
472 |
|
245 | 473 |
def recover(ui, repo): |
255 | 474 |
"""roll back an interrupted transaction""" |
245 | 475 |
repo.recover() |
476 |
||
477 |
def remove(ui, repo, file, *files): |
|
478 |
"""remove the specified files on the next commit""" |
|
479 |
repo.remove(relpath(repo, (file,) + files)) |
|
480 |
||
481 |
def serve(ui, repo, **opts): |
|
255 | 482 |
"""export the repository via HTTP""" |
245 | 483 |
hgweb.server(repo.root, opts["name"], opts["templates"], |
484 |
opts["address"], opts["port"]) |
|
485 |
||
213 | 486 |
def status(ui, repo): |
487 |
'''show changed files in the working directory |
|
488 |
||
245 | 489 |
C = changed |
490 |
A = added |
|
491 |
R = removed |
|
492 |
? = not tracked''' |
|
312 | 493 |
|
494 |
(c, a, d, u) = repo.diffdir(os.getcwd()) |
|
220 | 495 |
(c, a, d, u) = map(lambda x: relfilter(repo, x), (c, a, d, u)) |
213 | 496 |
|
497 |
for f in c: print "C", f |
|
220 | 498 |
for f in a: print "A", f |
213 | 499 |
for f in d: print "R", f |
220 | 500 |
for f in u: print "?", f |
213 | 501 |
|
248 | 502 |
def tags(ui, repo): |
255 | 503 |
"""list repository tags""" |
248 | 504 |
repo.lookup(0) # prime the cache |
505 |
i = repo.tags.items() |
|
257 | 506 |
n = [] |
507 |
for e in i: |
|
508 |
try: |
|
509 |
l = repo.changelog.rev(e[1]) |
|
510 |
except KeyError: |
|
511 |
l = -2 |
|
512 |
n.append((l, e)) |
|
513 |
||
514 |
n.sort() |
|
515 |
n.reverse() |
|
516 |
i = [ e[1] for e in n ] |
|
248 | 517 |
for k, n in i: |
518 |
try: |
|
519 |
r = repo.changelog.rev(n) |
|
520 |
except KeyError: |
|
521 |
r = "?" |
|
522 |
print "%-30s %5d:%s" % (k, repo.changelog.rev(n), hg.hex(n)) |
|
523 |
||
245 | 524 |
def tip(ui, repo): |
255 | 525 |
"""show the tip revision""" |
245 | 526 |
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
|
527 |
show_changeset(ui, repo, changenode=n) |
245 | 528 |
|
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
529 |
def undo(ui, repo): |
255 | 530 |
"""undo the last transaction""" |
210 | 531 |
repo.undo() |
532 |
||
275 | 533 |
def update(ui, repo, node=None, merge=False, clean=False): |
254 | 534 |
'''update or merge working directory |
535 |
||
536 |
If there are no outstanding changes in the working directory and |
|
537 |
there is a linear relationship between the current version and the |
|
538 |
requested version, the result is the requested version. |
|
539 |
||
540 |
Otherwise the result is a merge between the contents of the |
|
541 |
current working directory and the requested version. Files that |
|
542 |
changed between either parent are marked as changed for the next |
|
543 |
commit and a commit must be performed before any further updates |
|
544 |
are allowed. |
|
545 |
''' |
|
546 |
node = node and repo.lookup(node) or repo.changelog.tip() |
|
275 | 547 |
return repo.update(node, allow=merge, force=clean) |
254 | 548 |
|
247 | 549 |
def verify(ui, repo): |
550 |
"""verify the integrity of the repository""" |
|
551 |
return repo.verify() |
|
552 |
||
255 | 553 |
# Command options and aliases are listed here, alphabetically |
554 |
||
209 | 555 |
table = { |
245 | 556 |
"add": (add, [], "hg add [files]"), |
557 |
"addremove": (addremove, [], "hg addremove"), |
|
209 | 558 |
"ann|annotate": (annotate, |
559 |
[('r', 'revision', '', 'revision'), |
|
560 |
('u', 'user', None, 'show user'), |
|
561 |
('n', 'number', None, 'show revision number'), |
|
562 |
('c', 'changeset', None, 'show changeset')], |
|
563 |
'hg annotate [-u] [-c] [-n] [-r id] [files]'), |
|
248 | 564 |
"cat|dump": (cat, [], 'hg cat <file> [rev]'), |
289 | 565 |
"commit|ci": (commit, |
566 |
[('t', 'text', "", 'commit text'), |
|
317 | 567 |
('l', 'logfile', "", 'commit text file'), |
568 |
('d', 'date', "", 'data'), |
|
569 |
('u', 'user', "", 'user')], |
|
289 | 570 |
'hg commit [files]'), |
248 | 571 |
"debugaddchangegroup": (debugaddchangegroup, [], 'debugaddchangegroup'), |
572 |
"debugchangegroup": (debugchangegroup, [], 'debugchangegroup [roots]'), |
|
573 |
"debugindex": (debugindex, [], 'debugindex <file>'), |
|
574 |
"debugindexdot": (debugindexdot, [], 'debugindexdot <file>'), |
|
245 | 575 |
"diff": (diff, [('r', 'rev', [], 'revision')], |
576 |
'hg diff [-r A] [-r B] [files]'), |
|
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
577 |
"export": (export, [], "hg export <changeset>"), |
245 | 578 |
"forget": (forget, [], "hg forget [files]"), |
579 |
"heads": (heads, [], 'hg heads'), |
|
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
580 |
"history": (history, [], 'hg history'), |
245 | 581 |
"help": (help, [], 'hg help [command]'), |
290 | 582 |
"init": (init, [], 'hg init [url]'), |
245 | 583 |
"log": (log, [], 'hg log <file>'), |
248 | 584 |
"manifest|dumpmanifest": (manifest, [], 'hg manifest [rev]'), |
227 | 585 |
"parents": (parents, [], 'hg parents [node]'), |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
586 |
"patch|import": (patch, |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
587 |
[('p', 'strip', 1, 'path strip'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
588 |
('b', 'base', "", 'base path'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
589 |
('q', 'quiet', "", 'silence diff')], |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
590 |
"hg import [options] patches"), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
591 |
"pull|merge": (pull, [], 'hg pull [source]'), |
319 | 592 |
"push": (push, [], 'hg push <destination>'), |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
593 |
"rawcommit": (rawcommit, |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
594 |
[('p', 'parent', [], 'parent'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
595 |
('d', 'date', "", 'data'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
596 |
('u', 'user', "", 'user'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
597 |
('F', 'files', "", 'file list'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
598 |
('t', 'text', "", 'commit text'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
599 |
('l', 'logfile', "", 'commit text file')], |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
600 |
'hg rawcommit [options] [files]'), |
245 | 601 |
"recover": (recover, [], "hg recover"), |
602 |
"remove": (remove, [], "hg remove [files]"), |
|
603 |
"serve": (serve, [('p', 'port', 8000, 'listen port'), |
|
604 |
('a', 'address', '', 'interface address'), |
|
605 |
('n', 'name', os.getcwd(), 'repository name'), |
|
606 |
('t', 'templates', "", 'template map')], |
|
607 |
"hg serve [options]"), |
|
213 | 608 |
"status": (status, [], 'hg status'), |
248 | 609 |
"tags": (tags, [], 'hg tags'), |
245 | 610 |
"tip": (tip, [], 'hg tip'), |
210 | 611 |
"undo": (undo, [], 'hg undo'), |
275 | 612 |
"update|up|checkout|co|resolve": (update, |
613 |
[('m', 'merge', None, |
|
614 |
'allow merging of conflicts'), |
|
615 |
('C', 'clean', None, |
|
616 |
'overwrite locally modified files')], |
|
617 |
'hg update [options] [node]'), |
|
247 | 618 |
"verify": (verify, [], 'hg verify'), |
209 | 619 |
} |
620 |
||
248 | 621 |
norepo = "init branch help debugindex debugindexdot" |
209 | 622 |
|
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
623 |
def find(cmd): |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
624 |
i = None |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
625 |
for e in table.keys(): |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
626 |
if re.match(e + "$", cmd): |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
627 |
return table[e] |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
628 |
|
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
629 |
raise UnknownCommand(cmd) |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
630 |
|
214 | 631 |
class SignalInterrupt(Exception): pass |
632 |
||
633 |
def catchterm(*args): |
|
634 |
raise SignalInterrupt |
|
635 |
||
249 | 636 |
def run(): |
637 |
sys.exit(dispatch(sys.argv[1:])) |
|
638 |
||
209 | 639 |
def dispatch(args): |
640 |
options = {} |
|
641 |
opts = [('v', 'verbose', None, 'verbose'), |
|
642 |
('d', 'debug', None, 'debug'), |
|
643 |
('q', 'quiet', None, 'quiet'), |
|
309 | 644 |
('p', 'profile', None, 'profile'), |
209 | 645 |
('y', 'noninteractive', None, 'run non-interactively'), |
646 |
] |
|
647 |
||
648 |
args = fancyopts.fancyopts(args, opts, options, |
|
649 |
'hg [options] <command> [options] [files]') |
|
650 |
||
651 |
if not args: |
|
652 |
cmd = "help" |
|
653 |
else: |
|
654 |
cmd, args = args[0], args[1:] |
|
655 |
||
656 |
u = ui.ui(options["verbose"], options["debug"], options["quiet"], |
|
657 |
not options["noninteractive"]) |
|
658 |
||
252 | 659 |
try: |
660 |
i = find(cmd) |
|
661 |
except UnknownCommand: |
|
268 | 662 |
u.warn("hg: unknown command '%s'\n" % cmd) |
252 | 663 |
help(u) |
664 |
sys.exit(1) |
|
209 | 665 |
|
214 | 666 |
signal.signal(signal.SIGTERM, catchterm) |
667 |
||
209 | 668 |
cmdoptions = {} |
293 | 669 |
try: |
670 |
args = fancyopts.fancyopts(args, i[1], cmdoptions, i[2]) |
|
671 |
except fancyopts.getopt.GetoptError, inst: |
|
672 |
u.warn("hg %s: %s\n" % (cmd, inst)) |
|
673 |
help(u, cmd) |
|
674 |
sys.exit(-1) |
|
209 | 675 |
|
676 |
if cmd not in norepo.split(): |
|
677 |
repo = hg.repository(ui = u) |
|
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
678 |
d = lambda: i[0](u, repo, *args, **cmdoptions) |
209 | 679 |
else: |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
680 |
d = lambda: i[0](u, *args, **cmdoptions) |
209 | 681 |
|
682 |
try: |
|
309 | 683 |
if options['profile']: |
684 |
import hotshot, hotshot.stats |
|
685 |
prof = hotshot.Profile("hg.prof") |
|
686 |
r = prof.runcall(d) |
|
687 |
prof.close() |
|
688 |
stats = hotshot.stats.load("hg.prof") |
|
689 |
stats.strip_dirs() |
|
690 |
stats.sort_stats('time', 'calls') |
|
691 |
stats.print_stats(40) |
|
692 |
return r |
|
693 |
else: |
|
694 |
return d() |
|
214 | 695 |
except SignalInterrupt: |
696 |
u.warn("killed!\n") |
|
209 | 697 |
except KeyboardInterrupt: |
698 |
u.warn("interrupted!\n") |
|
250 | 699 |
except IOError, inst: |
700 |
if inst.errno == 32: |
|
701 |
u.warn("broken pipe\n") |
|
702 |
else: |
|
703 |
raise |
|
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
704 |
except TypeError, inst: |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
705 |
# was this an argument error? |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
706 |
tb = traceback.extract_tb(sys.exc_info()[2]) |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
707 |
if len(tb) > 2: # no |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
708 |
raise |
293 | 709 |
u.debug(inst, "\n") |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
710 |
u.warn("%s: invalid arguments\n" % i[0].__name__) |
293 | 711 |
help(u, cmd) |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
712 |
sys.exit(-1) |
293 | 713 |