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