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