##// END OF EJS Templates
hg init: when hardlinking, remove dirstate...
mpm@selenic.com -
r300:d3400605 default
parent child Browse files
Show More
@@ -1,652 +1,655 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 try:
310 os.remove(".hg/dirstate")
311 except: pass
309 312 else:
310 313 repo = hg.repository(ui, ".", create=1)
311 314 other = hg.repository(ui, source)
312 315 cg = repo.getchangegroup(other)
313 316 repo.addchangegroup(cg)
314 317 else:
315 318 hg.repository(ui, ".", create=1)
316 319
317 320 def log(ui, repo, f):
318 321 """show the revision history of a single file"""
319 322 f = relpath(repo, [f])[0]
320 323
321 324 r = repo.file(f)
322 325 for i in range(r.count() - 1, -1, -1):
323 326 n = r.node(i)
324 327 (p1, p2) = r.parents(n)
325 328 (h, h1, h2) = map(hg.hex, (n, p1, p2))
326 329 (i1, i2) = map(r.rev, (p1, p2))
327 330 cr = r.linkrev(n)
328 331 cn = hg.hex(repo.changelog.node(cr))
329 332 print "rev: %4d:%s" % (i, h)
330 333 print "changeset: %4d:%s" % (cr, cn)
331 334 print "parents: %4d:%s" % (i1, h1)
332 335 if i2: print " %4d:%s" % (i2, h2)
333 336 changes = repo.changelog.read(repo.changelog.node(cr))
334 337 print "user: %s" % changes[1]
335 338 print "date: %s" % time.asctime(
336 339 time.localtime(float(changes[2].split(' ')[0])))
337 340 print "description:"
338 341 print changes[4].rstrip()
339 342 print
340 343
341 344 def manifest(ui, repo, rev = []):
342 345 """output the latest or given revision of the project manifest"""
343 346 n = repo.manifest.tip()
344 347 if rev:
345 348 n = repo.manifest.lookup(rev)
346 349 m = repo.manifest.read(n)
347 350 mf = repo.manifest.readflags(n)
348 351 files = m.keys()
349 352 files.sort()
350 353
351 354 for f in files:
352 355 ui.write("%40s %3s %s\n" % (hg.hex(m[f]), mf[f] and "755" or "644", f))
353 356
354 357 def parents(ui, repo, node = None):
355 358 '''show the parents of the current working dir'''
356 359 if node:
357 360 p = repo.changelog.parents(repo.lookup(hg.bin(node)))
358 361 else:
359 362 p = repo.dirstate.parents()
360 363
361 364 for n in p:
362 365 if n != hg.nullid:
363 366 ui.write("%d:%s\n" % (repo.changelog.rev(n), hg.hex(n)))
364 367
365 368 def patch(ui, repo, patch1, *patches, **opts):
366 369 """import an ordered set of patches"""
367 370 try:
368 371 import psyco
369 372 psyco.full()
370 373 except:
371 374 pass
372 375
373 376 patches = (patch1,) + patches
374 377
375 378 d = opts["base"]
376 379 strip = opts["strip"]
377 380 quiet = opts["quiet"] and "> /dev/null" or ""
378 381
379 382 for patch in patches:
380 383 ui.status("applying %s\n" % patch)
381 384 pf = os.path.join(d, patch)
382 385
383 386 text = ""
384 387 for l in file(pf):
385 388 if l[:4] == "--- ": break
386 389 text += l
387 390
388 391 f = os.popen("lsdiff --strip %d %s" % (strip, pf))
389 392 files = filter(None, map(lambda x: x.rstrip(), f.read().splitlines()))
390 393 f.close()
391 394
392 395 if files:
393 396 if os.system("patch -p%d < %s %s" % (strip, pf, quiet)):
394 397 raise "patch failed!"
395 398 repo.commit(files, text)
396 399
397 400 def pull(ui, repo, source):
398 401 """pull changes from the specified source"""
399 402 paths = {}
400 403 for name, path in ui.configitems("paths"):
401 404 paths[name] = path
402 405
403 406 if source in paths: source = paths[source]
404 407
405 408 other = hg.repository(ui, source)
406 409 cg = repo.getchangegroup(other)
407 410 repo.addchangegroup(cg)
408 411
409 412 def rawcommit(ui, repo, files, **rc):
410 413 "raw commit interface"
411 414
412 415 text = rc['text']
413 416 if not text and rc['logfile']:
414 417 try: text = open(rc['logfile']).read()
415 418 except IOError: pass
416 419 if not text and not rc['logfile']:
417 420 print "missing commit text"
418 421 return 1
419 422
420 423 files = relpath(repo, files)
421 424 if rc['files']:
422 425 files += open(rc['files']).read().splitlines()
423 426
424 427 repo.rawcommit(files, text, rc['user'], rc['date'], *rc['parent'])
425 428
426 429 def recover(ui, repo):
427 430 """roll back an interrupted transaction"""
428 431 repo.recover()
429 432
430 433 def remove(ui, repo, file, *files):
431 434 """remove the specified files on the next commit"""
432 435 repo.remove(relpath(repo, (file,) + files))
433 436
434 437 def serve(ui, repo, **opts):
435 438 """export the repository via HTTP"""
436 439 hgweb.server(repo.root, opts["name"], opts["templates"],
437 440 opts["address"], opts["port"])
438 441
439 442 def status(ui, repo):
440 443 '''show changed files in the working directory
441 444
442 445 C = changed
443 446 A = added
444 447 R = removed
445 448 ? = not tracked'''
446 449
447 450 (c, a, d, u) = repo.diffdir(repo.root)
448 451 (c, a, d, u) = map(lambda x: relfilter(repo, x), (c, a, d, u))
449 452
450 453 for f in c: print "C", f
451 454 for f in a: print "A", f
452 455 for f in d: print "R", f
453 456 for f in u: print "?", f
454 457
455 458 def tags(ui, repo):
456 459 """list repository tags"""
457 460 repo.lookup(0) # prime the cache
458 461 i = repo.tags.items()
459 462 n = []
460 463 for e in i:
461 464 try:
462 465 l = repo.changelog.rev(e[1])
463 466 except KeyError:
464 467 l = -2
465 468 n.append((l, e))
466 469
467 470 n.sort()
468 471 n.reverse()
469 472 i = [ e[1] for e in n ]
470 473 for k, n in i:
471 474 try:
472 475 r = repo.changelog.rev(n)
473 476 except KeyError:
474 477 r = "?"
475 478 print "%-30s %5d:%s" % (k, repo.changelog.rev(n), hg.hex(n))
476 479
477 480 def tip(ui, repo):
478 481 """show the tip revision"""
479 482 n = repo.changelog.tip()
480 483 t = repo.changelog.rev(n)
481 484 ui.status("%d:%s\n" % (t, hg.hex(n)))
482 485
483 486 def undo(ui, repo):
484 487 """undo the last transaction"""
485 488 repo.undo()
486 489
487 490 def update(ui, repo, node=None, merge=False, clean=False):
488 491 '''update or merge working directory
489 492
490 493 If there are no outstanding changes in the working directory and
491 494 there is a linear relationship between the current version and the
492 495 requested version, the result is the requested version.
493 496
494 497 Otherwise the result is a merge between the contents of the
495 498 current working directory and the requested version. Files that
496 499 changed between either parent are marked as changed for the next
497 500 commit and a commit must be performed before any further updates
498 501 are allowed.
499 502 '''
500 503 node = node and repo.lookup(node) or repo.changelog.tip()
501 504 return repo.update(node, allow=merge, force=clean)
502 505
503 506 def verify(ui, repo):
504 507 """verify the integrity of the repository"""
505 508 return repo.verify()
506 509
507 510 # Command options and aliases are listed here, alphabetically
508 511
509 512 table = {
510 513 "add": (add, [], "hg add [files]"),
511 514 "addremove": (addremove, [], "hg addremove"),
512 515 "ann|annotate": (annotate,
513 516 [('r', 'revision', '', 'revision'),
514 517 ('u', 'user', None, 'show user'),
515 518 ('n', 'number', None, 'show revision number'),
516 519 ('c', 'changeset', None, 'show changeset')],
517 520 'hg annotate [-u] [-c] [-n] [-r id] [files]'),
518 521 "cat|dump": (cat, [], 'hg cat <file> [rev]'),
519 522 "commit|ci": (commit,
520 523 [('t', 'text', "", 'commit text'),
521 524 ('l', 'logfile', "", 'commit text file')],
522 525 'hg commit [files]'),
523 526 "debugaddchangegroup": (debugaddchangegroup, [], 'debugaddchangegroup'),
524 527 "debugchangegroup": (debugchangegroup, [], 'debugchangegroup [roots]'),
525 528 "debugindex": (debugindex, [], 'debugindex <file>'),
526 529 "debugindexdot": (debugindexdot, [], 'debugindexdot <file>'),
527 530 "diff": (diff, [('r', 'rev', [], 'revision')],
528 531 'hg diff [-r A] [-r B] [files]'),
529 532 "export": (export, [], "hg export <changeset>"),
530 533 "forget": (forget, [], "hg forget [files]"),
531 534 "heads": (heads, [], 'hg heads'),
532 535 "history": (history, [], 'hg history'),
533 536 "help": (help, [], 'hg help [command]'),
534 537 "init": (init, [], 'hg init [url]'),
535 538 "log": (log, [], 'hg log <file>'),
536 539 "manifest|dumpmanifest": (manifest, [], 'hg manifest [rev]'),
537 540 "parents": (parents, [], 'hg parents [node]'),
538 541 "patch|import": (patch,
539 542 [('p', 'strip', 1, 'path strip'),
540 543 ('b', 'base', "", 'base path'),
541 544 ('q', 'quiet', "", 'silence diff')],
542 545 "hg import [options] patches"),
543 546 "pull|merge": (pull, [], 'hg pull [source]'),
544 547 "rawcommit": (rawcommit,
545 548 [('p', 'parent', [], 'parent'),
546 549 ('d', 'date', "", 'data'),
547 550 ('u', 'user', "", 'user'),
548 551 ('F', 'files', "", 'file list'),
549 552 ('t', 'text', "", 'commit text'),
550 553 ('l', 'logfile', "", 'commit text file')],
551 554 'hg rawcommit [options] [files]'),
552 555 "recover": (recover, [], "hg recover"),
553 556 "remove": (remove, [], "hg remove [files]"),
554 557 "serve": (serve, [('p', 'port', 8000, 'listen port'),
555 558 ('a', 'address', '', 'interface address'),
556 559 ('n', 'name', os.getcwd(), 'repository name'),
557 560 ('t', 'templates', "", 'template map')],
558 561 "hg serve [options]"),
559 562 "status": (status, [], 'hg status'),
560 563 "tags": (tags, [], 'hg tags'),
561 564 "tip": (tip, [], 'hg tip'),
562 565 "undo": (undo, [], 'hg undo'),
563 566 "update|up|checkout|co|resolve": (update,
564 567 [('m', 'merge', None,
565 568 'allow merging of conflicts'),
566 569 ('C', 'clean', None,
567 570 'overwrite locally modified files')],
568 571 'hg update [options] [node]'),
569 572 "verify": (verify, [], 'hg verify'),
570 573 }
571 574
572 575 norepo = "init branch help debugindex debugindexdot"
573 576
574 577 def find(cmd):
575 578 i = None
576 579 for e in table.keys():
577 580 if re.match(e + "$", cmd):
578 581 return table[e]
579 582
580 583 raise UnknownCommand(cmd)
581 584
582 585 class SignalInterrupt(Exception): pass
583 586
584 587 def catchterm(*args):
585 588 raise SignalInterrupt
586 589
587 590 def run():
588 591 sys.exit(dispatch(sys.argv[1:]))
589 592
590 593 def dispatch(args):
591 594 options = {}
592 595 opts = [('v', 'verbose', None, 'verbose'),
593 596 ('d', 'debug', None, 'debug'),
594 597 ('q', 'quiet', None, 'quiet'),
595 598 ('y', 'noninteractive', None, 'run non-interactively'),
596 599 ]
597 600
598 601 args = fancyopts.fancyopts(args, opts, options,
599 602 'hg [options] <command> [options] [files]')
600 603
601 604 if not args:
602 605 cmd = "help"
603 606 else:
604 607 cmd, args = args[0], args[1:]
605 608
606 609 u = ui.ui(options["verbose"], options["debug"], options["quiet"],
607 610 not options["noninteractive"])
608 611
609 612 try:
610 613 i = find(cmd)
611 614 except UnknownCommand:
612 615 u.warn("hg: unknown command '%s'\n" % cmd)
613 616 help(u)
614 617 sys.exit(1)
615 618
616 619 signal.signal(signal.SIGTERM, catchterm)
617 620
618 621 cmdoptions = {}
619 622 try:
620 623 args = fancyopts.fancyopts(args, i[1], cmdoptions, i[2])
621 624 except fancyopts.getopt.GetoptError, inst:
622 625 u.warn("hg %s: %s\n" % (cmd, inst))
623 626 help(u, cmd)
624 627 sys.exit(-1)
625 628
626 629 if cmd not in norepo.split():
627 630 repo = hg.repository(ui = u)
628 631 d = lambda: i[0](u, repo, *args, **cmdoptions)
629 632 else:
630 633 d = lambda: i[0](u, *args, **cmdoptions)
631 634
632 635 try:
633 636 return d()
634 637 except SignalInterrupt:
635 638 u.warn("killed!\n")
636 639 except KeyboardInterrupt:
637 640 u.warn("interrupted!\n")
638 641 except IOError, inst:
639 642 if inst.errno == 32:
640 643 u.warn("broken pipe\n")
641 644 else:
642 645 raise
643 646 except TypeError, inst:
644 647 # was this an argument error?
645 648 tb = traceback.extract_tb(sys.exc_info()[2])
646 649 if len(tb) > 2: # no
647 650 raise
648 651 u.debug(inst, "\n")
649 652 u.warn("%s: invalid arguments\n" % i[0].__name__)
650 653 help(u, cmd)
651 654 sys.exit(-1)
652 655
General Comments 0
You need to be logged in to leave comments. Login now