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