]> granicus.if.org Git - git/commitdiff
Merge branch 'nd/parseopt-completion-more'
authorJunio C Hamano <gitster@pobox.com>
Tue, 10 Apr 2018 07:28:22 +0000 (16:28 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 10 Apr 2018 07:28:22 +0000 (16:28 +0900)
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

1  2 
contrib/completion/git-completion.bash
git.c

diff --cc git.c
index ceaa58ef40e536f1290cce3ad1223004063e41a6,42e7a65d843afc0e2347f003d20613e241413149..3a89893712e6b327e714ad81d12d3e4ca354926c
--- 1/git.c
--- 2/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 <path>] [-c name=value]\n"
 -      "           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]\n"
 -      "           [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]\n"
 -      "           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]\n"
 -      "           <command> [<args>]";
 +      N_("git [--version] [--help] [-C <path>] [-c <name>=<value>]\n"
 +         "           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]\n"
 +         "           [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]\n"
 +         "           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]\n"
 +         "           <command> [<args>]");
  
  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 },