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