Show More
@@ -1,30 +1,5 b'' | |||
|
1 | 1 | shopt -s extglob |
|
2 | 2 | |
|
3 | _hg_command_list() | |
|
4 | { | |
|
5 | "$hg" --debug help 2>/dev/null | \ | |
|
6 | awk -F', ' '/^list of commands:/ {commands=1} | |
|
7 | commands==1 && /^ [^ ]/ { | |
|
8 | line = substr($0, 2) | |
|
9 | colon = index(line, ":") | |
|
10 | if (colon > 0) | |
|
11 | line = substr(line, 1, colon-1) | |
|
12 | n = split(line, aliases) | |
|
13 | command = aliases[1] | |
|
14 | if (index(command, "debug") == 1) { | |
|
15 | for (i=1; i<=n; i++) | |
|
16 | debug[j++] = aliases[i] | |
|
17 | next | |
|
18 | } | |
|
19 | print command | |
|
20 | for (i=2; i<=n; i++) | |
|
21 | if (index(command, aliases[i]) != 1) | |
|
22 | print aliases[i] | |
|
23 | } | |
|
24 | /^global options:/ {exit 0} | |
|
25 | END {for (i in debug) print debug[i]}' | |
|
26 | } | |
|
27 | ||
|
28 | 3 | _hg_option_list() |
|
29 | 4 | { |
|
30 | 5 | "$hg" -v help $1 2>/dev/null | \ |
@@ -40,21 +15,8 b' shopt -s extglob' | |||
|
40 | 15 | |
|
41 | 16 | _hg_commands() |
|
42 | 17 | { |
|
43 | local all commands result | |
|
44 | ||
|
45 | all=$(_hg_command_list) | |
|
46 | commands=${all%%$'\n'debug*} | |
|
47 | result=$(compgen -W '$commands' -- "$cur") | |
|
48 | ||
|
49 | # hide debug commands from users, but complete them if | |
|
50 | # there is no other possible command | |
|
51 | if [ "$result" = "" ]; then | |
|
52 | local debug | |
|
53 | debug=debug${all#*$'\n'debug} | |
|
54 | result=$(compgen -W '$debug' -- "$cur") | |
|
55 | fi | |
|
56 | ||
|
57 | COMPREPLY=(${COMPREPLY[@]:-} $result) | |
|
18 | local commands="$("$hg" debugcomplete "$cur")" | |
|
19 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$commands' -- "$cur")) | |
|
58 | 20 | } |
|
59 | 21 | |
|
60 | 22 | _hg_paths() |
@@ -1013,6 +1013,12 b' def debugancestor(ui, index, rev1, rev2)' | |||
|
1013 | 1013 | a = r.ancestor(r.lookup(rev1), r.lookup(rev2)) |
|
1014 | 1014 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) |
|
1015 | 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)) | |
|
1021 | ||
|
1016 | 1022 | def debugrebuildstate(ui, repo, rev=None): |
|
1017 | 1023 | """rebuild the dirstate as it would look like for the given revision""" |
|
1018 | 1024 | if not rev: |
@@ -2427,6 +2433,7 b' table = {' | |||
|
2427 | 2433 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2428 | 2434 | _('hg copy [OPTION]... [SOURCE]... DEST')), |
|
2429 | 2435 | "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')), |
|
2436 | "debugcomplete": (debugcomplete, [], _('debugcomplete CMD')), | |
|
2430 | 2437 | "debugrebuildstate": |
|
2431 | 2438 | (debugrebuildstate, |
|
2432 | 2439 | [('r', 'rev', '', _('revision to rebuild to'))], |
@@ -2658,42 +2665,49 b' globalopts = [' | |||
|
2658 | 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 | 2669 | " debugindex debugindexdot") |
|
2663 | 2670 | optionalrepo = ("paths debugconfig") |
|
2664 | 2671 | |
|
2665 | def find(cmd): | |
|
2666 | """Return (aliases, command table entry) for command string.""" | |
|
2667 | choice = [] | |
|
2668 | debugchoice = [] | |
|
2672 | def findpossible(cmd): | |
|
2673 | """ | |
|
2674 | Return cmd -> (aliases, command table entry) | |
|
2675 | for each matching command | |
|
2676 | """ | |
|
2677 | choice = {} | |
|
2678 | debugchoice = {} | |
|
2669 | 2679 | for e in table.keys(): |
|
2670 | 2680 | aliases = e.lstrip("^").split("|") |
|
2671 | 2681 | if cmd in aliases: |
|
2672 |
|
|
|
2682 | choice[cmd] = (aliases, table[e]) | |
|
2683 | continue | |
|
2673 | 2684 | for a in aliases: |
|
2674 | 2685 | if a.startswith(cmd): |
|
2675 | 2686 | if aliases[0].startswith("debug"): |
|
2676 |
debugchoice |
|
|
2687 | debugchoice[a] = (aliases, table[e]) | |
|
2677 | 2688 | else: |
|
2678 |
choice |
|
|
2689 | choice[a] = (aliases, table[e]) | |
|
2679 | 2690 | break |
|
2680 | 2691 | |
|
2681 | 2692 | if not choice and debugchoice: |
|
2682 | 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 | 2704 | if len(choice) > 1: |
|
2685 |
clist = |
|
|
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) | |
|
2705 | clist = choice.keys() | |
|
2692 | 2706 | clist.sort() |
|
2693 | 2707 | raise AmbiguousCommand(cmd, clist) |
|
2694 | 2708 | |
|
2695 | 2709 | if choice: |
|
2696 | return choice[0] | |
|
2710 | return choice.values()[0] | |
|
2697 | 2711 | |
|
2698 | 2712 | raise UnknownCommand(cmd) |
|
2699 | 2713 |
General Comments 0
You need to be logged in to leave comments.
Login now