comparison mercurial/commands.py @ 349:b2293093b89e

Merged with mercurial-identify (which includes upstream's current tip) -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Merged with mercurial-identify (which includes upstream's current tip) manifest hash: b135d201757b84bbe7f14a446d2b001fd0cc1aa2 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFCr9mNW7P1GVgWeRoRAmTjAJ919wnvZXbKI27N0cDJCrumR3z4rQCcD6PO yZTmrT6p+gt6GBO+j5FVBn0= =HWn8 -----END PGP SIGNATURE-----
author Thomas Arendsen Hein <thomas@intevation.de>
date Wed, 15 Jun 2005 08:32:29 +0100
parents a0b2758edee7 97a897d32dfc
children b4e0e20646bb
comparison
equal deleted inserted replaced
348:442eb02cf870 349:b2293093b89e
124 ui.status("\n\n") 124 ui.status("\n\n")
125 else: 125 else:
126 ui.status("summary: %s\n" % description.splitlines()[0]) 126 ui.status("summary: %s\n" % description.splitlines()[0])
127 ui.status("\n") 127 ui.status("\n")
128 128
129 def tags_load(repo):
130 repo.lookup(0) # prime the cache
131 i = repo.tags.items()
132 n = []
133 for e in i:
134 try:
135 l = repo.changelog.rev(e[1])
136 except KeyError:
137 l = -2
138 n.append((l, e))
139 return n
140
129 def help(ui, cmd=None): 141 def help(ui, cmd=None):
130 '''show help for a given command or all commands''' 142 '''show help for a given command or all commands'''
131 if cmd: 143 if cmd:
132 try: 144 try:
133 i = find(cmd) 145 i = find(cmd)
310 def history(ui, repo): 322 def history(ui, repo):
311 """show the changelog history""" 323 """show the changelog history"""
312 for i in range(repo.changelog.count() - 1, -1, -1): 324 for i in range(repo.changelog.count() - 1, -1, -1):
313 show_changeset(ui, repo, rev=i) 325 show_changeset(ui, repo, rev=i)
314 326
327 def identify(ui, repo):
328 """print information about the working copy"""
329 (c, a, d, u) = repo.diffdir(repo.root)
330 mflag = (c or a or d or u) and "+" or ""
331 parents = [parent for parent in repo.dirstate.parents()
332 if parent != hg.nullid]
333 if not parents:
334 ui.note("unknown\n")
335 return
336
337 tstring = ''
338 if not ui.quiet:
339 taglist = [e[1] for e in tags_load(repo)]
340 tstring = " %s" % ' + '.join([e[0] for e in taglist
341 if e[0] != 'tip' and e[1] in parents])
342
343 hexfunc = ui.verbose and hg.hex or hg.short
344 pstring = '+'.join([hexfunc(parent) for parent in parents])
345 ui.write("%s%s%s\n" % (pstring, mflag, tstring))
346
315 def init(ui, source=None): 347 def init(ui, source=None):
316 """create a new repository or copy an existing one""" 348 """create a new repository or copy an existing one"""
317 349
318 if source: 350 if source:
319 paths = {} 351 paths = {}
332 ui.debug("copying by hardlink\n") 364 ui.debug("copying by hardlink\n")
333 os.system("cp -al %s/.hg .hg" % source) 365 os.system("cp -al %s/.hg .hg" % source)
334 try: 366 try:
335 os.remove(".hg/dirstate") 367 os.remove(".hg/dirstate")
336 except: pass 368 except: pass
369
370 repo = hg.repository(ui, ".")
371
337 else: 372 else:
338 repo = hg.repository(ui, ".", create=1) 373 repo = hg.repository(ui, ".", create=1)
339 other = hg.repository(ui, source) 374 other = hg.repository(ui, source)
340 cg = repo.getchangegroup(other) 375 cg = repo.getchangegroup(other)
341 repo.addchangegroup(cg) 376 repo.addchangegroup(cg)
342 else: 377 else:
343 hg.repository(ui, ".", create=1) 378 repo = hg.repository(ui, ".", create=1)
379
380 f = repo.opener("hgrc", "w")
381 f.write("[paths]\n")
382 f.write("default = %s\n" % source)
344 383
345 def log(ui, repo, f): 384 def log(ui, repo, f):
346 """show the revision history of a single file""" 385 """show the revision history of a single file"""
347 f = relpath(repo, [f])[0] 386 f = relpath(repo, [f])[0]
348 387
407 if files: 446 if files:
408 if os.system("patch -p%d < %s %s" % (strip, pf, quiet)): 447 if os.system("patch -p%d < %s %s" % (strip, pf, quiet)):
409 raise "patch failed!" 448 raise "patch failed!"
410 repo.commit(files, text) 449 repo.commit(files, text)
411 450
412 def pull(ui, repo, source): 451 def pull(ui, repo, source="default"):
413 """pull changes from the specified source""" 452 """pull changes from the specified source"""
414 paths = {} 453 paths = {}
415 for name, path in ui.configitems("paths"): 454 for name, path in ui.configitems("paths"):
416 paths[name] = path 455 paths[name] = path
417 456
455 else: 494 else:
456 r = os.system(cmd) 495 r = os.system(cmd)
457 os.kill(child, signal.SIGTERM) 496 os.kill(child, signal.SIGTERM)
458 return r 497 return r
459 498
460 def rawcommit(ui, repo, files, **rc): 499 def rawcommit(ui, repo, flist, **rc):
461 "raw commit interface" 500 "raw commit interface"
462 501
463 text = rc['text'] 502 text = rc['text']
464 if not text and rc['logfile']: 503 if not text and rc['logfile']:
465 try: text = open(rc['logfile']).read() 504 try: text = open(rc['logfile']).read()
466 except IOError: pass 505 except IOError: pass
467 if not text and not rc['logfile']: 506 if not text and not rc['logfile']:
468 print "missing commit text" 507 print "missing commit text"
469 return 1 508 return 1
470 509
471 files = relpath(repo, files) 510 files = relpath(repo, flist)
472 if rc['files']: 511 if rc['files']:
473 files += open(rc['files']).read().splitlines() 512 files += open(rc['files']).read().splitlines()
474 513
475 repo.rawcommit(files, text, rc['user'], rc['date'], *rc['parent']) 514 repo.rawcommit(files, text, rc['user'], rc['date'], *rc['parent'])
476 515
503 for f in d: print "R", f 542 for f in d: print "R", f
504 for f in u: print "?", f 543 for f in u: print "?", f
505 544
506 def tags(ui, repo): 545 def tags(ui, repo):
507 """list repository tags""" 546 """list repository tags"""
508 repo.lookup(0) # prime the cache 547 n = tags_load(repo)
509 i = repo.tags.items()
510 n = []
511 for e in i:
512 try:
513 l = repo.changelog.rev(e[1])
514 except KeyError:
515 l = -2
516 n.append((l, e))
517 548
518 n.sort() 549 n.sort()
519 n.reverse() 550 n.reverse()
520 i = [ e[1] for e in n ] 551 i = [ e[1] for e in n ]
521 for k, n in i: 552 for k, n in i:
581 "export": (export, [], "hg export <changeset>"), 612 "export": (export, [], "hg export <changeset>"),
582 "forget": (forget, [], "hg forget [files]"), 613 "forget": (forget, [], "hg forget [files]"),
583 "heads": (heads, [], 'hg heads'), 614 "heads": (heads, [], 'hg heads'),
584 "history": (history, [], 'hg history'), 615 "history": (history, [], 'hg history'),
585 "help": (help, [], 'hg help [command]'), 616 "help": (help, [], 'hg help [command]'),
617 "identify|id": (identify, [], 'hg identify'),
586 "init": (init, [], 'hg init [url]'), 618 "init": (init, [], 'hg init [url]'),
587 "log": (log, [], 'hg log <file>'), 619 "log": (log, [], 'hg log <file>'),
588 "manifest|dumpmanifest": (manifest, [], 'hg manifest [rev]'), 620 "manifest|dumpmanifest": (manifest, [], 'hg manifest [rev]'),
589 "parents": (parents, [], 'hg parents [node]'), 621 "parents": (parents, [], 'hg parents [node]'),
590 "patch|import": (patch, 622 "patch|import": (patch,
625 norepo = "init branch help debugindex debugindexdot" 657 norepo = "init branch help debugindex debugindexdot"
626 658
627 def find(cmd): 659 def find(cmd):
628 i = None 660 i = None
629 for e in table.keys(): 661 for e in table.keys():
630 if re.match(e + "$", cmd): 662 if re.match("(%s)$" % e, cmd):
631 return table[e] 663 return table[e]
632 664
633 raise UnknownCommand(cmd) 665 raise UnknownCommand(cmd)
634 666
635 class SignalInterrupt(Exception): pass 667 class SignalInterrupt(Exception): pass