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