comparison mercurial/commands.py @ 1887:913397c27cd8

new command debugcomplete add a new command debugcomplete, it lists all the possible completion for the specified command. make the bash_completion script uses it instead of the awk code
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Sun, 12 Mar 2006 11:32:03 +0100
parents 2f4a0734c100
children 468730910353
comparison
equal deleted inserted replaced
1886:d4a3a8a332ab 1887:913397c27cd8
1010 def debugancestor(ui, index, rev1, rev2): 1010 def debugancestor(ui, index, rev1, rev2):
1011 """find the ancestor revision of two revisions in a given index""" 1011 """find the ancestor revision of two revisions in a given index"""
1012 r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "") 1012 r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "")
1013 a = r.ancestor(r.lookup(rev1), r.lookup(rev2)) 1013 a = r.ancestor(r.lookup(rev1), r.lookup(rev2))
1014 ui.write("%d:%s\n" % (r.rev(a), hex(a))) 1014 ui.write("%d:%s\n" % (r.rev(a), hex(a)))
1015
1016 def debugcomplete(ui, cmd):
1017 """returns the completion list associated with the given command"""
1018 clist = findpossible(cmd).keys()
1019 clist.sort()
1020 ui.write("%s\n" % " ".join(clist))
1015 1021
1016 def debugrebuildstate(ui, repo, rev=None): 1022 def debugrebuildstate(ui, repo, rev=None):
1017 """rebuild the dirstate as it would look like for the given revision""" 1023 """rebuild the dirstate as it would look like for the given revision"""
1018 if not rev: 1024 if not rev:
1019 rev = repo.changelog.tip() 1025 rev = repo.changelog.tip()
2425 _('forcibly copy over an existing managed file')), 2431 _('forcibly copy over an existing managed file')),
2426 ('I', 'include', [], _('include names matching the given patterns')), 2432 ('I', 'include', [], _('include names matching the given patterns')),
2427 ('X', 'exclude', [], _('exclude names matching the given patterns'))], 2433 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
2428 _('hg copy [OPTION]... [SOURCE]... DEST')), 2434 _('hg copy [OPTION]... [SOURCE]... DEST')),
2429 "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')), 2435 "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')),
2436 "debugcomplete": (debugcomplete, [], _('debugcomplete CMD')),
2430 "debugrebuildstate": 2437 "debugrebuildstate":
2431 (debugrebuildstate, 2438 (debugrebuildstate,
2432 [('r', 'rev', '', _('revision to rebuild to'))], 2439 [('r', 'rev', '', _('revision to rebuild to'))],
2433 _('debugrebuildstate [-r REV] [REV]')), 2440 _('debugrebuildstate [-r REV] [REV]')),
2434 "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')), 2441 "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')),
2656 ('', 'profile', None, _('print command execution profile')), 2663 ('', 'profile', None, _('print command execution profile')),
2657 ('', 'version', None, _('output version information and exit')), 2664 ('', 'version', None, _('output version information and exit')),
2658 ('h', 'help', None, _('display help and exit')), 2665 ('h', 'help', None, _('display help and exit')),
2659 ] 2666 ]
2660 2667
2661 norepo = ("clone init version help debugancestor debugdata" 2668 norepo = ("clone init version help debugancestor debugcomplete debugdata"
2662 " debugindex debugindexdot") 2669 " debugindex debugindexdot")
2663 optionalrepo = ("paths debugconfig") 2670 optionalrepo = ("paths debugconfig")
2664 2671
2665 def find(cmd): 2672 def findpossible(cmd):
2666 """Return (aliases, command table entry) for command string.""" 2673 """
2667 choice = [] 2674 Return cmd -> (aliases, command table entry)
2668 debugchoice = [] 2675 for each matching command
2676 """
2677 choice = {}
2678 debugchoice = {}
2669 for e in table.keys(): 2679 for e in table.keys():
2670 aliases = e.lstrip("^").split("|") 2680 aliases = e.lstrip("^").split("|")
2671 if cmd in aliases: 2681 if cmd in aliases:
2672 return aliases, table[e] 2682 choice[cmd] = (aliases, table[e])
2683 continue
2673 for a in aliases: 2684 for a in aliases:
2674 if a.startswith(cmd): 2685 if a.startswith(cmd):
2675 if aliases[0].startswith("debug"): 2686 if aliases[0].startswith("debug"):
2676 debugchoice.append([aliases, table[e]]) 2687 debugchoice[a] = (aliases, table[e])
2677 else: 2688 else:
2678 choice.append([aliases, table[e]]) 2689 choice[a] = (aliases, table[e])
2679 break 2690 break
2680 2691
2681 if not choice and debugchoice: 2692 if not choice and debugchoice:
2682 choice = debugchoice 2693 choice = debugchoice
2683 2694
2695 return choice
2696
2697 def find(cmd):
2698 """Return (aliases, command table entry) for command string."""
2699 choice = findpossible(cmd)
2700
2701 if choice.has_key(cmd):
2702 return choice[cmd]
2703
2684 if len(choice) > 1: 2704 if len(choice) > 1:
2685 clist = [] 2705 clist = choice.keys()
2686 for aliases, table_e in choice:
2687 if aliases[0].startswith(cmd):
2688 clist.append(aliases[0])
2689 for a in aliases[1:]:
2690 if a.startswith(cmd) and not aliases[0].startswith(a):
2691 clist.append(a)
2692 clist.sort() 2706 clist.sort()
2693 raise AmbiguousCommand(cmd, clist) 2707 raise AmbiguousCommand(cmd, clist)
2694 2708
2695 if choice: 2709 if choice:
2696 return choice[0] 2710 return choice.values()[0]
2697 2711
2698 raise UnknownCommand(cmd) 2712 raise UnknownCommand(cmd)
2699 2713
2700 class SignalInterrupt(Exception): 2714 class SignalInterrupt(Exception):
2701 """Exception raised on SIGTERM and SIGHUP.""" 2715 """Exception raised on SIGTERM and SIGHUP."""