v7 is mostly code cleanup plus one more change: git-completion.bash now always checks completion.commands config key. This makes it much more convenient to customize the command complete list. You only have to fall back to setting $GIT_COMPLETION_CMD_GROUPS when you have very special needs. Interdiff diff --git a/Documentation/config.txt b/Documentation/config.txt index 2659153cb3..91f7eaed7b 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -1343,6 +1343,16 @@ credential.<url>.*:: credentialCache.ignoreSIGHUP:: Tell git-credential-cache--daemon to ignore SIGHUP, instead of quitting. +completion.commands:: + This is only used by git-completion.bash to add or remove + commands from the complete list. Normally only porcelain + commands and a few select others are in the complete list. You + can add more commands, separated by space, in this + variable. Prefixing a command with '-' will remove it from + the existing list. ++ +This variable should not be per-repository. + include::diff-config.txt[] difftool.<tool>.path:: diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 0fd29803d5..f7ca9a4d4f 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -50,10 +50,10 @@ # # GIT_COMPLETION_CMD_GROUPS=main,others # -# Or you could go with defaults add some extra commands specified -# in the configuration variable completion.commands [1] with +# Or you could go with main porcelain only and extra commands in +# the configuration variable completion.commands with # -# GIT_COMPLETION_CMD_GROUPS=mainporcelain,others,list-complete,config +# GIT_COMPLETION_CMD_GROUPS=mainporcelain,config # # Or go completely custom group with # @@ -61,15 +61,6 @@ # # Or you could even play with other command categories found in # command-list.txt. -# -# [1] Note that completion.commands should not be per-repository -# since the command list is generated once and cached. -# -# completion.commands could be used to exclude commands as -# well. If a command in this list begins with '-', then it -# will be excluded from the list of commands gathered by the -# groups specified before "config" in -# $GIT_COMPLETION_CMD_GROUPS. case "$COMP_WORDBREAKS" in *:*) : great ;; @@ -876,7 +867,7 @@ __git_commands () { then git --list-cmds="$GIT_COMPLETION_CMD_GROUPS" else - git --list-cmds=list-mainporcelain,others,list-complete + git --list-cmds=list-mainporcelain,others,list-complete,config fi ;; all) diff --git a/generate-cmdlist.sh b/generate-cmdlist.sh index bfd8ef0671..8d6d8b45ce 100755 --- a/generate-cmdlist.sh +++ b/generate-cmdlist.sh @@ -9,7 +9,7 @@ command_list () { grep -v '^#' "$1" } -get_categories() { +get_categories () { tr ' ' '\n'| grep -v '^$' | sort | @@ -32,7 +32,7 @@ get_synopsis () { }' "Documentation/$1.txt" } -define_categories() { +define_categories () { echo echo "/* Command categories */" bit=0 @@ -45,7 +45,7 @@ define_categories() { test "$bit" -gt 32 && die "Urgh.. too many categories?" } -define_category_names() { +define_category_names () { echo echo "/* Category names */" echo "static const char *category_names[] = {" @@ -60,7 +60,7 @@ define_category_names() { echo "};" } -print_command_list() { +print_command_list () { echo "static struct cmdname_help command_list[] = {" command_list "$1" | diff --git a/git.c b/git.c index fd08911e11..ea4feedd0b 100644 --- a/git.c +++ b/git.c @@ -38,6 +38,13 @@ static int use_pager = -1; static void list_builtins(struct string_list *list, unsigned int exclude_option); +static int match_token(const char *spec, int len, const char *token) +{ + int token_len = strlen(token); + + return len == token_len && !strncmp(spec, token, token_len); +} + static int list_cmds(const char *spec) { struct string_list list = STRING_LIST_INIT_DUP; @@ -47,13 +54,13 @@ static int list_cmds(const char *spec) const char *sep = strchrnul(spec, ','); int len = sep - spec; - if (len == 8 && !strncmp(spec, "builtins", 8)) + if (match_token(spec, len, "builtins")) list_builtins(&list, 0); - else if (len == 4 && !strncmp(spec, "main", 4)) + else if (match_token(spec, len, "main")) list_all_main_cmds(&list); - else if (len == 6 && !strncmp(spec, "others", 6)) + else if (match_token(spec, len, "others")) list_all_other_cmds(&list); - else if (len == 6 && !strncmp(spec, "config", 6)) + else if (match_token(spec, len, "config")) list_cmds_by_config(&list); else if (len > 5 && !strncmp(spec, "list-", 5)) { struct strbuf sb = STRBUF_INIT; Nguyễn Thái Ngọc Duy (13): generate-cmds.sh: factor out synopsis extract code generate-cmds.sh: export all commands to command-list.h help: use command-list.h for common command list Remove common-cmds.h git.c: convert --list-* to --list-cmds=* git --list-cmds: collect command list in a string_list completion: implement and use --list-cmds=main,others git: support --list-cmds=list-<category> help: add "-a --verbose" to list all commands with synopsis help: use command-list.txt for the source of guides command-list.txt: documentation and guide line completion: let git provide the completable command list completion: allow to customize the completable command list .gitignore | 2 +- Documentation/config.txt | 10 + Documentation/git-help.txt | 4 +- Documentation/gitattributes.txt | 2 +- Documentation/gitmodules.txt | 2 +- Documentation/gitrevisions.txt | 2 +- Makefile | 16 +- builtin/help.c | 39 +--- command-list.txt | 111 ++++++++--- contrib/completion/git-completion.bash | 160 +++++++--------- generate-cmdlist.sh | 126 ++++++++----- git.c | 68 ++++++- help.c | 244 ++++++++++++++++++++++--- help.h | 10 + t/t0012-help.sh | 26 ++- t/t9902-completion.sh | 5 +- 16 files changed, 573 insertions(+), 254 deletions(-) -- 2.17.0.705.g3525833791