From: Junio C Hamano Date: Fri, 30 Mar 2018 01:27:23 +0000 (-0700) Subject: Merge branch 'nd/parseopt-completion-more' into next X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/9007b165e2ed019e8aa0031957000f420fc76331?hp=--cc Merge branch 'nd/parseopt-completion-more' into next 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 --- 9007b165e2ed019e8aa0031957000f420fc76331 diff --cc git.c index 2a5840f37d,42e7a65d84..b73a550edd --- 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 }, @@@ -477,10 -480,9 +481,10 @@@ { "update-index", cmd_update_index, RUN_SETUP }, { "update-ref", cmd_update_ref, RUN_SETUP }, { "update-server-info", cmd_update_server_info, RUN_SETUP }, - { "upload-archive", cmd_upload_archive }, - { "upload-archive--writer", cmd_upload_archive_writer }, + { "upload-archive", cmd_upload_archive, NO_PARSEOPT }, + { "upload-archive--writer", cmd_upload_archive_writer, NO_PARSEOPT }, + { "upload-pack", cmd_upload_pack }, - { "var", cmd_var, RUN_SETUP_GENTLY }, + { "var", cmd_var, RUN_SETUP_GENTLY | NO_PARSEOPT }, { "verify-commit", cmd_verify_commit, RUN_SETUP }, { "verify-pack", cmd_verify_pack }, { "verify-tag", cmd_verify_tag, RUN_SETUP },