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