Mercurial > public > mercurial-scm > hg
annotate mercurial/commands.py @ 339:a76fc9c4b67b
added hg identify|id (based on a patch from Andrew Thompson)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
added hg identify|id (based on a patch from Andrew Thompson)
manifest hash: b8f801efb6cf14a6d754fed2cf47149f4e77b3cc
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFCr8BLW7P1GVgWeRoRAj3+AJ4jIvfBnu6vbF+SOS2ybVTboXe7pACfZkkT
2G2bbxYowVnrytOXVg6BhlU=
=wNpZ
-----END PGP SIGNATURE-----
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Wed, 15 Jun 2005 06:44:43 +0100 |
parents | 1e091b3293d5 |
children | 97a897d32dfc |
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] |
a76fc9c4b67b
added hg identify|id (based on a patch from Andrew Thompson)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
338
diff
changeset
|
333 tstring = '' |
a76fc9c4b67b
added hg identify|id (based on a patch from Andrew Thompson)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
338
diff
changeset
|
334 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
|
335 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
|
336 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
|
337 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
|
338 |
a76fc9c4b67b
added hg identify|id (based on a patch from Andrew Thompson)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
338
diff
changeset
|
339 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
|
340 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
|
341 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
|
342 |
290 | 343 def init(ui, source=None): |
344 """create a new repository or copy an existing one""" | |
345 | |
346 if source: | |
347 paths = {} | |
348 for name, path in ui.configitems("paths"): | |
349 paths[name] = path | |
350 | |
351 if source in paths: source = paths[source] | |
255 | 352 |
290 | 353 link = 0 |
354 if not source.startswith("http://"): | |
355 d1 = os.stat(os.getcwd()).st_dev | |
356 d2 = os.stat(source).st_dev | |
357 if d1 == d2: link = 1 | |
358 | |
359 if link: | |
360 ui.debug("copying by hardlink\n") | |
361 os.system("cp -al %s/.hg .hg" % source) | |
300 | 362 try: |
363 os.remove(".hg/dirstate") | |
364 except: pass | |
338 | 365 |
366 repo = hg.repository(ui, ".") | |
367 | |
290 | 368 else: |
369 repo = hg.repository(ui, ".", create=1) | |
370 other = hg.repository(ui, source) | |
371 cg = repo.getchangegroup(other) | |
372 repo.addchangegroup(cg) | |
373 else: | |
338 | 374 repo = hg.repository(ui, ".", create=1) |
375 | |
376 f = repo.opener("hgrc", "w") | |
377 f.write("[paths]\n") | |
378 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
|
379 |
255 | 380 def log(ui, repo, f): |
381 """show the revision history of a single file""" | |
382 f = relpath(repo, [f])[0] | |
383 | |
384 r = repo.file(f) | |
270
5a80ed2158c8
Reverse order of hg log and hg history lists
mpm@selenic.com
parents:
268
diff
changeset
|
385 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
|
386 show_changeset(ui, repo, filelog=r, rev=i) |
255 | 387 |
388 def manifest(ui, repo, rev = []): | |
389 """output the latest or given revision of the project manifest""" | |
390 n = repo.manifest.tip() | |
391 if rev: | |
392 n = repo.manifest.lookup(rev) | |
393 m = repo.manifest.read(n) | |
276 | 394 mf = repo.manifest.readflags(n) |
255 | 395 files = m.keys() |
396 files.sort() | |
397 | |
398 for f in files: | |
276 | 399 ui.write("%40s %3s %s\n" % (hg.hex(m[f]), mf[f] and "755" or "644", f)) |
255 | 400 |
401 def parents(ui, repo, node = None): | |
402 '''show the parents of the current working dir''' | |
403 if node: | |
404 p = repo.changelog.parents(repo.lookup(hg.bin(node))) | |
405 else: | |
406 p = repo.dirstate.parents() | |
407 | |
408 for n in p: | |
409 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
|
410 show_changeset(ui, repo, changenode=n) |
255 | 411 |
294
f8d56da6ac8f
hg patch: fix to actually take a list of patches
mpm@selenic.com
parents:
293
diff
changeset
|
412 def patch(ui, repo, patch1, *patches, **opts): |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
413 """import an ordered set of patches""" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
414 try: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
415 import psyco |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
416 psyco.full() |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
417 except: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
418 pass |
294
f8d56da6ac8f
hg patch: fix to actually take a list of patches
mpm@selenic.com
parents:
293
diff
changeset
|
419 |
295 | 420 patches = (patch1,) + patches |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
421 |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
422 d = opts["base"] |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
423 strip = opts["strip"] |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
424 quiet = opts["quiet"] and "> /dev/null" or "" |
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 for patch in patches: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
427 ui.status("applying %s\n" % patch) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
428 pf = os.path.join(d, patch) |
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 text = "" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
431 for l in file(pf): |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
432 if l[:4] == "--- ": break |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
433 text += l |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
434 |
310 | 435 # make sure text isn't empty |
436 if not text: text = "imported patch %s\n" % patch | |
437 | |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
438 f = os.popen("lsdiff --strip %d %s" % (strip, pf)) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
439 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
|
440 f.close() |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
441 |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
442 if files: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
443 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
|
444 raise "patch failed!" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
445 repo.commit(files, text) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
446 |
338 | 447 def pull(ui, repo, source="default"): |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
448 """pull changes from the specified source""" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
449 paths = {} |
286 | 450 for name, path in ui.configitems("paths"): |
290 | 451 paths[name] = path |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
452 |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
453 if source in paths: source = paths[source] |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
454 |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
455 other = hg.repository(ui, source) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
456 cg = repo.getchangegroup(other) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
457 repo.addchangegroup(cg) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
458 |
319 | 459 def push(ui, repo, dest): |
460 """push changes to the specified destination""" | |
461 paths = {} | |
462 for name, path in ui.configitems("paths"): | |
463 paths[name] = path | |
464 | |
465 if dest in paths: dest = paths[dest] | |
466 | |
467 if not dest.startswith("ssh://"): | |
468 ui.warn("abort: can only push to ssh:// destinations currently\n") | |
469 return 1 | |
470 | |
471 m = re.match(r'ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?', dest) | |
472 if not m: | |
473 ui.warn("abort: couldn't parse destination %s\n" % dest) | |
474 return 1 | |
475 | |
476 user, host, port, path = map(m.group, (2, 3, 5, 7)) | |
477 host = user and ("%s@%s" % (user, host)) or host | |
478 port = port and (" -p %s") % port or "" | |
479 path = path or "" | |
480 | |
481 sport = random.randrange(30000, 60000) | |
482 cmd = "ssh %s%s -R %d:localhost:%d 'cd %s; hg pull http://localhost:%d/'" | |
483 cmd = cmd % (host, port, sport+1, sport, path, sport+1) | |
484 | |
485 child = os.fork() | |
486 if not child: | |
487 sys.stdout = file("/dev/null", "w") | |
488 sys.stderr = sys.stdout | |
489 hgweb.server(repo.root, "pull", "", "localhost", sport) | |
490 else: | |
491 r = os.system(cmd) | |
492 os.kill(child, signal.SIGTERM) | |
320 | 493 return r |
319 | 494 |
333 | 495 def rawcommit(ui, repo, flist, **rc): |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
496 "raw commit interface" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
497 |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
498 text = rc['text'] |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
499 if not text and rc['logfile']: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
500 try: text = open(rc['logfile']).read() |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
501 except IOError: pass |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
502 if not text and not rc['logfile']: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
503 print "missing commit text" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
504 return 1 |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
505 |
333 | 506 files = relpath(repo, flist) |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
507 if rc['files']: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
508 files += open(rc['files']).read().splitlines() |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
509 |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
510 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
|
511 |
245 | 512 def recover(ui, repo): |
255 | 513 """roll back an interrupted transaction""" |
245 | 514 repo.recover() |
515 | |
516 def remove(ui, repo, file, *files): | |
517 """remove the specified files on the next commit""" | |
518 repo.remove(relpath(repo, (file,) + files)) | |
519 | |
520 def serve(ui, repo, **opts): | |
255 | 521 """export the repository via HTTP""" |
245 | 522 hgweb.server(repo.root, opts["name"], opts["templates"], |
523 opts["address"], opts["port"]) | |
524 | |
213 | 525 def status(ui, repo): |
526 '''show changed files in the working directory | |
527 | |
245 | 528 C = changed |
529 A = added | |
530 R = removed | |
531 ? = not tracked''' | |
312 | 532 |
533 (c, a, d, u) = repo.diffdir(os.getcwd()) | |
220 | 534 (c, a, d, u) = map(lambda x: relfilter(repo, x), (c, a, d, u)) |
213 | 535 |
536 for f in c: print "C", f | |
220 | 537 for f in a: print "A", f |
213 | 538 for f in d: print "R", f |
220 | 539 for f in u: print "?", f |
213 | 540 |
248 | 541 def tags(ui, repo): |
255 | 542 """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
|
543 n = tags_load(repo) |
257 | 544 |
545 n.sort() | |
546 n.reverse() | |
547 i = [ e[1] for e in n ] | |
248 | 548 for k, n in i: |
549 try: | |
550 r = repo.changelog.rev(n) | |
551 except KeyError: | |
552 r = "?" | |
553 print "%-30s %5d:%s" % (k, repo.changelog.rev(n), hg.hex(n)) | |
554 | |
245 | 555 def tip(ui, repo): |
255 | 556 """show the tip revision""" |
245 | 557 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
|
558 show_changeset(ui, repo, changenode=n) |
245 | 559 |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
560 def undo(ui, repo): |
255 | 561 """undo the last transaction""" |
210 | 562 repo.undo() |
563 | |
275 | 564 def update(ui, repo, node=None, merge=False, clean=False): |
254 | 565 '''update or merge working directory |
566 | |
567 If there are no outstanding changes in the working directory and | |
568 there is a linear relationship between the current version and the | |
569 requested version, the result is the requested version. | |
570 | |
571 Otherwise the result is a merge between the contents of the | |
572 current working directory and the requested version. Files that | |
573 changed between either parent are marked as changed for the next | |
574 commit and a commit must be performed before any further updates | |
575 are allowed. | |
576 ''' | |
577 node = node and repo.lookup(node) or repo.changelog.tip() | |
275 | 578 return repo.update(node, allow=merge, force=clean) |
254 | 579 |
247 | 580 def verify(ui, repo): |
581 """verify the integrity of the repository""" | |
582 return repo.verify() | |
583 | |
255 | 584 # Command options and aliases are listed here, alphabetically |
585 | |
209 | 586 table = { |
245 | 587 "add": (add, [], "hg add [files]"), |
588 "addremove": (addremove, [], "hg addremove"), | |
209 | 589 "ann|annotate": (annotate, |
590 [('r', 'revision', '', 'revision'), | |
591 ('u', 'user', None, 'show user'), | |
592 ('n', 'number', None, 'show revision number'), | |
593 ('c', 'changeset', None, 'show changeset')], | |
594 'hg annotate [-u] [-c] [-n] [-r id] [files]'), | |
248 | 595 "cat|dump": (cat, [], 'hg cat <file> [rev]'), |
289 | 596 "commit|ci": (commit, |
597 [('t', 'text', "", 'commit text'), | |
317 | 598 ('l', 'logfile', "", 'commit text file'), |
599 ('d', 'date', "", 'data'), | |
600 ('u', 'user', "", 'user')], | |
289 | 601 'hg commit [files]'), |
248 | 602 "debugaddchangegroup": (debugaddchangegroup, [], 'debugaddchangegroup'), |
603 "debugchangegroup": (debugchangegroup, [], 'debugchangegroup [roots]'), | |
604 "debugindex": (debugindex, [], 'debugindex <file>'), | |
605 "debugindexdot": (debugindexdot, [], 'debugindexdot <file>'), | |
245 | 606 "diff": (diff, [('r', 'rev', [], 'revision')], |
607 'hg diff [-r A] [-r B] [files]'), | |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
608 "export": (export, [], "hg export <changeset>"), |
245 | 609 "forget": (forget, [], "hg forget [files]"), |
610 "heads": (heads, [], 'hg heads'), | |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
611 "history": (history, [], 'hg history'), |
245 | 612 "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
|
613 "identify|id": (identify, [], 'hg identify'), |
290 | 614 "init": (init, [], 'hg init [url]'), |
245 | 615 "log": (log, [], 'hg log <file>'), |
248 | 616 "manifest|dumpmanifest": (manifest, [], 'hg manifest [rev]'), |
227 | 617 "parents": (parents, [], 'hg parents [node]'), |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
618 "patch|import": (patch, |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
619 [('p', 'strip', 1, 'path strip'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
620 ('b', 'base', "", 'base path'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
621 ('q', 'quiet', "", 'silence diff')], |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
622 "hg import [options] patches"), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
623 "pull|merge": (pull, [], 'hg pull [source]'), |
319 | 624 "push": (push, [], 'hg push <destination>'), |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
625 "rawcommit": (rawcommit, |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
626 [('p', 'parent', [], 'parent'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
627 ('d', 'date', "", 'data'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
628 ('u', 'user', "", 'user'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
629 ('F', 'files', "", 'file list'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
630 ('t', 'text', "", 'commit text'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
631 ('l', 'logfile', "", 'commit text file')], |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
632 'hg rawcommit [options] [files]'), |
245 | 633 "recover": (recover, [], "hg recover"), |
634 "remove": (remove, [], "hg remove [files]"), | |
635 "serve": (serve, [('p', 'port', 8000, 'listen port'), | |
636 ('a', 'address', '', 'interface address'), | |
637 ('n', 'name', os.getcwd(), 'repository name'), | |
638 ('t', 'templates', "", 'template map')], | |
639 "hg serve [options]"), | |
213 | 640 "status": (status, [], 'hg status'), |
248 | 641 "tags": (tags, [], 'hg tags'), |
245 | 642 "tip": (tip, [], 'hg tip'), |
210 | 643 "undo": (undo, [], 'hg undo'), |
275 | 644 "update|up|checkout|co|resolve": (update, |
645 [('m', 'merge', None, | |
646 'allow merging of conflicts'), | |
647 ('C', 'clean', None, | |
648 'overwrite locally modified files')], | |
649 'hg update [options] [node]'), | |
247 | 650 "verify": (verify, [], 'hg verify'), |
209 | 651 } |
652 | |
248 | 653 norepo = "init branch help debugindex debugindexdot" |
209 | 654 |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
655 def find(cmd): |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
656 i = None |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
657 for e in table.keys(): |
335 | 658 if re.match("(%s)$" % e, cmd): |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
659 return table[e] |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
660 |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
661 raise UnknownCommand(cmd) |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
662 |
214 | 663 class SignalInterrupt(Exception): pass |
664 | |
665 def catchterm(*args): | |
666 raise SignalInterrupt | |
667 | |
249 | 668 def run(): |
669 sys.exit(dispatch(sys.argv[1:])) | |
670 | |
209 | 671 def dispatch(args): |
672 options = {} | |
673 opts = [('v', 'verbose', None, 'verbose'), | |
674 ('d', 'debug', None, 'debug'), | |
675 ('q', 'quiet', None, 'quiet'), | |
309 | 676 ('p', 'profile', None, 'profile'), |
209 | 677 ('y', 'noninteractive', None, 'run non-interactively'), |
678 ] | |
679 | |
680 args = fancyopts.fancyopts(args, opts, options, | |
681 'hg [options] <command> [options] [files]') | |
682 | |
683 if not args: | |
684 cmd = "help" | |
685 else: | |
686 cmd, args = args[0], args[1:] | |
687 | |
688 u = ui.ui(options["verbose"], options["debug"], options["quiet"], | |
689 not options["noninteractive"]) | |
690 | |
252 | 691 try: |
692 i = find(cmd) | |
693 except UnknownCommand: | |
268 | 694 u.warn("hg: unknown command '%s'\n" % cmd) |
252 | 695 help(u) |
696 sys.exit(1) | |
209 | 697 |
214 | 698 signal.signal(signal.SIGTERM, catchterm) |
699 | |
209 | 700 cmdoptions = {} |
293 | 701 try: |
702 args = fancyopts.fancyopts(args, i[1], cmdoptions, i[2]) | |
703 except fancyopts.getopt.GetoptError, inst: | |
704 u.warn("hg %s: %s\n" % (cmd, inst)) | |
705 help(u, cmd) | |
706 sys.exit(-1) | |
209 | 707 |
708 if cmd not in norepo.split(): | |
709 repo = hg.repository(ui = u) | |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
710 d = lambda: i[0](u, repo, *args, **cmdoptions) |
209 | 711 else: |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
712 d = lambda: i[0](u, *args, **cmdoptions) |
209 | 713 |
714 try: | |
309 | 715 if options['profile']: |
716 import hotshot, hotshot.stats | |
717 prof = hotshot.Profile("hg.prof") | |
718 r = prof.runcall(d) | |
719 prof.close() | |
720 stats = hotshot.stats.load("hg.prof") | |
721 stats.strip_dirs() | |
722 stats.sort_stats('time', 'calls') | |
723 stats.print_stats(40) | |
724 return r | |
725 else: | |
726 return d() | |
214 | 727 except SignalInterrupt: |
728 u.warn("killed!\n") | |
209 | 729 except KeyboardInterrupt: |
730 u.warn("interrupted!\n") | |
250 | 731 except IOError, inst: |
732 if inst.errno == 32: | |
733 u.warn("broken pipe\n") | |
734 else: | |
735 raise | |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
736 except TypeError, inst: |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
737 # was this an argument error? |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
738 tb = traceback.extract_tb(sys.exc_info()[2]) |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
739 if len(tb) > 2: # no |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
740 raise |
293 | 741 u.debug(inst, "\n") |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
742 u.warn("%s: invalid arguments\n" % i[0].__name__) |
293 | 743 help(u, cmd) |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
744 sys.exit(-1) |
293 | 745 |