From: Junio C Hamano Date: Tue, 10 Apr 2018 07:28:22 +0000 (+0900) Subject: Merge branch 'nd/parseopt-completion-more' X-Git-Tag: v2.18.0-rc0~154 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/ef06d74b4574b0da0928b4919c01da63fadcdca2 Merge branch 'nd/parseopt-completion-more' The mechanism to use parse-options API to automate the command line completion continues to get extended and polished. * nd/parseopt-completion-more: completion: use __gitcomp_builtin in _git_cherry completion: use __gitcomp_builtin in _git_ls_tree completion: delete option-only completion commands completion: add --option completion for most builtin commands completion: factor out _git_xxx calling code completion: mention the oldest version we need to support git.c: add hidden option --list-parseopt-builtins git.c: move cmd_struct declaration up --- ef06d74b4574b0da0928b4919c01da63fadcdca2 diff --cc git.c index ceaa58ef40,42e7a65d84..3a89893712 --- a/git.c +++ b/git.c @@@ -4,12 -4,30 +4,30 @@@ #include "help.h" #include "run-command.h" + #define RUN_SETUP (1<<0) + #define RUN_SETUP_GENTLY (1<<1) + #define USE_PAGER (1<<2) + /* + * require working tree to be present -- anything uses this needs + * RUN_SETUP for reading from the configuration file. + */ + #define NEED_WORK_TREE (1<<3) + #define SUPPORT_SUPER_PREFIX (1<<4) + #define DELAY_PAGER_CONFIG (1<<5) + #define NO_PARSEOPT (1<<6) /* parse-options is not used */ + + struct cmd_struct { + const char *cmd; + int (*fn)(int, const char **, const char *); + unsigned int option; + }; + const char git_usage_string[] = - "git [--version] [--help] [-C ] [-c name=value]\n" - " [--exec-path[=]] [--html-path] [--man-path] [--info-path]\n" - " [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]\n" - " [--git-dir=] [--work-tree=] [--namespace=]\n" - " []"; + N_("git [--version] [--help] [-C ] [-c =]\n" + " [--exec-path[=]] [--html-path] [--man-path] [--info-path]\n" + " [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]\n" + " [--git-dir=] [--work-tree=] [--namespace=]\n" + " []"); const char git_more_info_string[] = N_("'git help -a' and 'git help -g' list available subcommands and some\n" @@@ -206,10 -224,13 +224,13 @@@ static int handle_options(const char ** (*argv)++; (*argc)--; } else if (!strcmp(cmd, "--list-builtins")) { - list_builtins(); + list_builtins(0, '\n'); + exit(0); + } else if (!strcmp(cmd, "--list-parseopt-builtins")) { + list_builtins(NO_PARSEOPT, ' '); exit(0); } else { - fprintf(stderr, "Unknown option: %s\n", cmd); + fprintf(stderr, _("unknown option: %s\n"), cmd); usage(git_usage_string); } @@@ -388,15 -392,15 +392,15 @@@ static struct cmd_struct commands[] = { "clone", cmd_clone }, { "column", cmd_column, RUN_SETUP_GENTLY }, { "commit", cmd_commit, RUN_SETUP | NEED_WORK_TREE }, - { "commit-tree", cmd_commit_tree, RUN_SETUP }, + { "commit-tree", cmd_commit_tree, RUN_SETUP | NO_PARSEOPT }, - { "config", cmd_config, RUN_SETUP_GENTLY }, + { "config", cmd_config, RUN_SETUP_GENTLY | DELAY_PAGER_CONFIG }, { "count-objects", cmd_count_objects, RUN_SETUP }, - { "credential", cmd_credential, RUN_SETUP_GENTLY }, + { "credential", cmd_credential, RUN_SETUP_GENTLY | NO_PARSEOPT }, { "describe", cmd_describe, RUN_SETUP }, - { "diff", cmd_diff }, - { "diff-files", cmd_diff_files, RUN_SETUP | NEED_WORK_TREE }, - { "diff-index", cmd_diff_index, RUN_SETUP }, - { "diff-tree", cmd_diff_tree, RUN_SETUP }, + { "diff", cmd_diff, NO_PARSEOPT }, + { "diff-files", cmd_diff_files, RUN_SETUP | NEED_WORK_TREE | NO_PARSEOPT }, + { "diff-index", cmd_diff_index, RUN_SETUP | NO_PARSEOPT }, + { "diff-tree", cmd_diff_tree, RUN_SETUP | NO_PARSEOPT }, { "difftool", cmd_difftool, RUN_SETUP | NEED_WORK_TREE }, { "fast-export", cmd_fast_export, RUN_SETUP }, { "fetch", cmd_fetch, RUN_SETUP },