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