completion: add more parameter value completion
PATCH 1/1 completion: add more parameter value completion
This adds value completion for a couple more paramters. To make it easier to maintain these hard coded lists, add a comment at the original list/code to remind people to update git-completion.bash too.
---
This 6 month old patch was part of the attempt to automate value completion. That might never come, but at least this is still good.
apply.c | 4 +++ builtin/am.c | 4 +++ builtin/commit.c | 8 +++++ builtin/help.c | 4 +++ builtin/log.c | 8 +++++ builtin/pull.c | 4 +++ builtin/replace.c | 4 +++ contrib/completion/git-completion.bash | 43 ++++++++++++++++++++++++-- date.c | 4 +++ diff.c | 8 +++++ git-send-email.perl | 6 ++++ list-objects-filter-options.c | 4 +++ merge-recursive.c | 4 +++ pretty.c | 4 +++ ref-filter.c | 4 +++ submodule-config.c | 9 +++++- submodule.c | 4 +++ xdiff-interface.c | 4 +++ 18 files changed, 126 insertions(+), 4 deletions(-)
apply.c +4 -0
@@ -56,6 +56,10 @@ static int parse_whitespace_option(struct apply_state *state, const char *option state->ws_error_action = correct_ws_error;return 0 ; } +/* +* Please update $__git_whitespacelist in git-completion.bash +* when you add new options. +*/ return error (_ ("unrecognized whitespace option '%s'" ), option); }
builtin/am.c +4 -0
@@ -2125,6 +2125,10 @@ static int parse_opt_patchformat(const struct option *opt, const char *arg, int *opt_value =PATCH_FORMAT_HG ; else if (!strcmp(arg, "mboxrd")) *opt_value =PATCH_FORMAT_MBOXRD ; +/* +* Please update $__git_patchformat in git-completion.bash +* when you add new options +*/ else return error(_("Invalid value for --patch-format: %s"), arg);return 0 ;
builtin/commit.c +8 -0
@@ -1036,6 +1036,10 @@ static void handle_untracked_files_arg(struct wt_status *s) s->show_untracked_files =SHOW_NORMAL_UNTRACKED_FILES ; else if (!strcmp(untracked_files_arg, "all")) s->show_untracked_files =SHOW_ALL_UNTRACKED_FILES ; +/* +* Please update $__git_untracked_file_modes in +* git-completion.bash when add new options +*/ else die(_("Invalid untracked files mode '%s'"), untracked_files_arg); }
@@ -1177,6 +1181,10 @@ static int parse_and_validate_options(int argc, const char *argv[],else if (!strcmp (cleanup_arg,"scissors" )) cleanup_mode = use_editor ?COMMIT_MSG_CLEANUP_SCISSORS :COMMIT_MSG_CLEANUP_SPACE ; +/* +* Please update _git_commit() in git-completion.bash when you +* add new options. +*/ else die (_ ("Invalid cleanup mode %s" ), cleanup_arg);
builtin/help.c +4 -0
@@ -70,6 +70,10 @@ static enum help_format parse_help_format(const char *format)return HELP_FORMAT_INFO ;if (!strcmp (format,"web" ) || !strcmp (format,"html" ))return HELP_FORMAT_WEB ; +/* +* Please update _git_config() in git-completion.bash when you +* add new rebase modes. +*/ die (_ ("unrecognized help format '%s'" ), format); }
builtin/log.c +8 -0
@@ -83,6 +83,10 @@ static int parse_decoration_style(const char *value)return DECORATE_SHORT_REFS ; else if (!strcmp(value, "auto"))return auto_decoration_style (); +/* +* Please update _git_log() in git-completion.bash when you +* add new decoration styles. +*/ return -1 ; }
@@ -1225,6 +1229,10 @@ static int thread_callback(const struct option *opt, const char *arg, int unset) *thread =THREAD_SHALLOW ; else if (!strcmp(arg, "deep")) *thread =THREAD_DEEP ; +/* +* Please update _git_formatpatch() in git-completion.bash +* when you add new options. +*/ else return 1;return 0 ;
builtin/pull.c +4 -0
@@ -55,6 +55,10 @@ static enum rebase_type parse_config_rebase(const char *key, const char *value,return REBASE_MERGES ; else if (!strcmp(value, "interactive") || !strcmp(value, "i"))return REBASE_INTERACTIVE ; +/* +* Please update _git_config() in git-completion.bash when you +* add new rebase modes. +*/ if (fatal)die (_ ("Invalid value for %s: %s" ), key, value);
builtin/replace.c +4 -0
@@ -82,6 +82,10 @@ static int list_replace_refs(const char *pattern, const char *format) data.format =REPLACE_FORMAT_MEDIUM ; else if (!strcmp(format, "long")) data.format =REPLACE_FORMAT_LONG ; +/* +* Please update _git_replace() in git-completion.bash when +* you add ne format +*/ else return error(_("invalid replace format '%s'\n" "valid formats are 'short', 'medium' and 'long'"),
contrib/completion/git-completion.bash +40 -3
121 lines not on this page · raw message
date.c +4 -0
@@ -825,6 +825,10 @@ static enum date_mode_type parse_date_type(const char *format, const char **end)return DATE_UNIX ;if (skip_prefix (format,"format" , end))return DATE_STRFTIME ; +/* +* Please update $__git_log_date_formats in +* git-completion.bash when you add new formats. +*/ die ("unknown date format %s" , format); }
diff.c +8 -0
@@ -178,6 +178,10 @@ static int parse_submodule_params(struct diff_options *options, const char *valu options->submodule_format =DIFF_SUBMODULE_SHORT ; else if (!strcmp(value, "diff")) options->submodule_format =DIFF_SUBMODULE_INLINE_DIFF ; +/* +* Please update $__git_diff_submodule_formats in +* git-completion.bash when you add new formats. +*/ else return -1;return 0 ;
@@ -204,6 +208,10 @@ long parse_algorithm_value(const char *value)return XDF_PATIENCE_DIFF ; else if (!strcasecmp(value, "histogram"))return XDF_HISTOGRAM_DIFF ; +/* +* Please update $__git_diff_algorithms in git-completion.bash +* when you add new algorithms. +*/ return -1 ; }
git-send-email.perl +6 -0
@@ -465,6 +465,8 @@ sub read_config { my(%suppress_cc); if (@suppress_cc) { foreach my $entry (@suppress_cc) { + # Please update $__git_send_email_suppresscc_options + # in git-completion.bash when you add new options. die sprintf(__("Unknown --suppress-cc field: '%s'\n"), $entry) unless $entry =~ /^(?:all|cccmd|cc|author|self|sob|body|bodycc|misc-by)$/; $suppress_cc{$entry} = 1;
@@ -494,6 +496,8 @@ sub read_config { if ($confirm_unconfigured) { $confirm = scalar %suppress_cc ? 'compose' : 'auto'; }; +# Please update $__git_send_email_confirm_options in +# git-completion.bash when you add new options. die sprintf(__("Unknown --confirm setting: '%s'\n"), $confirm) unless $confirm =~ /^(?:auto|cc|compose|always|never)/;
@@ -587,6 +591,8 @@ sub parse_sendmail_aliases { if (/\(define-mail-alias\s+"(\S+?)"\s+"(\S+?)"\)/) { $aliases{$1} = [ $2 ]; }}} + # Please update _git_config() in git-completion.bash when you + # add new MUAs. ); if (@alias_files and $aliasfiletype and defined $parse_alias{$aliasfiletype}) {
list-objects-filter-options.c +4 -0
@@ -82,6 +82,10 @@ static int gently_parse_list_objects_filter( filter_options->sparse_path_value =strdup (v0);return 0 ; } +/* +* Please update _git_fetch() in git-completion.bash when you +* add new filter +*/ if (errbuf)strbuf_addf (errbuf,"invalid filter-spec '%s'" , arg);
merge-recursive.c +4 -0
@@ -3749,6 +3749,10 @@ int parse_merge_opt(struct merge_options *o, const char *s)return -1 ; o->merge_detect_rename =1 ; } +/* +* Please update $__git_merge_strategy_options in +* git-completion.bash when you add new options +*/ else return -1 ;return 0 ;
pretty.c +4 -0
@@ -98,6 +98,10 @@ static void setup_commit_formats(void) { "fuller", CMIT_FMT_FULLER, 0, 8 }, { "full", CMIT_FMT_FULL, 0, 8 }, { "oneline", CMIT_FMT_ONELINE, 1, 0 } + /* + * Please update $__git_log_pretty_formats in + * git-completion.bash when you add new formats. + */ }; commit_formats_len =ARRAY_SIZE (builtin_formats); builtin_formats_len = commit_formats_len;
ref-filter.c +4 -0
@@ -485,6 +485,10 @@ static struct { { "if", SOURCE_NONE, FIELD_STR, if_atom_parser }, { "then", SOURCE_NONE }, { "else", SOURCE_NONE }, + /* + * Please update $__git_ref_fieldlist in git-completion.bash + * when you add new atoms + */ };#define REF_FORMATTING_STATE_INIT { 0, NULL }
submodule-config.c +8 -1
@@ -281,7 +281,10 @@ static int parse_fetch_recurse(const char *opt, const char *arg,default :if (!strcmp (arg,"on-demand" ))return RECURSE_SUBMODULES_ON_DEMAND ; - +/* +* Please update $__git_fetch_recurse_submodules in +* git-completion.bash when you add new options. +*/ if (die_on_error)die ("bad %s argument: %s" , opt, arg);else
@@ -362,6 +365,10 @@ static int parse_push_recurse(const char *opt, const char *arg,return RECURSE_SUBMODULES_CHECK ; else if (!strcmp(arg, "only"))return RECURSE_SUBMODULES_ONLY ; +/* +* Please update $__git_push_recurse_submodules in +* git-completion.bash when you add new modes. +*/ else if (die_on_error) die("bad %s argument: %s", opt, arg); else
submodule.c +4 -0
@@ -434,6 +434,10 @@ void handle_ignore_submodules_arg(struct diff_options *diffopt, diffopt->flags.ignore_dirty_submodules =1 ; else if (strcmp(arg, "none")) die("bad --ignore-submodules argument: %s", arg); +/* +* Please update _git_status() in git-completion.bash when you +* add new options +*/ } static int prepare_submodule_summary(struct rev_info *rev, const char *path,
xdiff-interface.c +4 -0
@@ -306,6 +306,10 @@ int git_xmerge_config(const char *var, const char *value, void *cb) git_xmerge_style =XDL_MERGE_DIFF3 ; else if (!strcmp(value, "merge")) git_xmerge_style =0 ; +/* +* Please update _git_checkout() in +* git-completion.bash when you add new merge config +*/ else die("unknown style '%s' given for '%s'", value, var);
Signature · 1 line
2.20.1.560.g70ca8b83ee
Nguyễn Thái Ngọc Duy <[email protected]> writes:
Quoted 8 lines · Nguyễn Thái Ngọc Duy
This adds value completion for a couple more paramters. To make it easier to maintain these hard coded lists, add a comment at the original list/code to remind people to update git-completion.bash too.
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>---
This 6 month old patch was part of the attempt to automate value completion. That might never come, but at least this is still good.
Perhaps this is not yet good without proofreading.
builtin/help.c static enum help_format parse_help_format(const char *format) · line 76
Quoted 12 lines
builtin/help.c +4
-0@@ -70,6 +70,10 @@ static enum help_format parse_help_format(const char *format)return HELP_FORMAT_INFO ;if (!strcmp (format,"web" ) || !strcmp (format,"html" ))return HELP_FORMAT_WEB ; +/* +* Please update _git_config() in git-completion.bash when you +* add new rebase modes. +*/
Huh? s/rebase modes/help formats/, I guess.
Quoted 8 lines
builtin/help.c +0
-0die (_ ("unrecognized help format '%s'" ), format); }builtin/replace.c +0
-0
builtin/replace.c static int list_replace_refs(const char *pattern, const char *format) · line 87
Quoted 6 lines
builtin/replace.c +3
-0@@ -82,6 +82,10 @@ static int list_replace_refs(const char *pattern, const char *format) data.format =REPLACE_FORMAT_MEDIUM ; else if (!strcmp(format, "long")) data.format =REPLACE_FORMAT_LONG ; +/* +* Please update _git_replace() in git-completion.bash when +* you add ne format
s/ne/&w/;
PATCH v2 1/1 completion: add more parameter value completion
In reply to Nguyễn Thái Ngọc DuyThis adds value completion for a couple more paramters. To make it easier to maintain these hard coded lists, add a comment at the original list/code to remind people to update git-completion.bash too.
--- apply.c | 4 +++ builtin/am.c | 4 +++ builtin/commit.c | 8 +++++ builtin/help.c | 4 +++ builtin/log.c | 8 +++++ builtin/pull.c | 4 +++ builtin/replace.c | 4 +++ contrib/completion/git-completion.bash | 43 ++++++++++++++++++++++++-- date.c | 4 +++ diff.c | 8 +++++ git-send-email.perl | 6 ++++ list-objects-filter-options.c | 4 +++ merge-recursive.c | 4 +++ pretty.c | 4 +++ ref-filter.c | 4 +++ submodule-config.c | 9 +++++- submodule.c | 4 +++ xdiff-interface.c | 4 +++ 18 files changed, 126 insertions(+), 4 deletions(-)
apply.c +4 -0
@@ -56,6 +56,10 @@ static int parse_whitespace_option(struct apply_state *state, const char *option state->ws_error_action = correct_ws_error;return 0 ; } +/* +* Please update $__git_whitespacelist in git-completion.bash +* when you add new options. +*/ return error (_ ("unrecognized whitespace option '%s'" ), option); }
builtin/am.c +4 -0
@@ -2119,6 +2119,10 @@ static int parse_opt_patchformat(const struct option *opt, const char *arg, int *opt_value =PATCH_FORMAT_HG ; else if (!strcmp(arg, "mboxrd")) *opt_value =PATCH_FORMAT_MBOXRD ; +/* +* Please update $__git_patchformat in git-completion.bash +* when you add new options +*/ else return error(_("Invalid value for --patch-format: %s"), arg);return 0 ;
builtin/commit.c +8 -0
@@ -1038,6 +1038,10 @@ static void handle_untracked_files_arg(struct wt_status *s) s->show_untracked_files =SHOW_NORMAL_UNTRACKED_FILES ; else if (!strcmp(untracked_files_arg, "all")) s->show_untracked_files =SHOW_ALL_UNTRACKED_FILES ; +/* +* Please update $__git_untracked_file_modes in +* git-completion.bash when you add new options +*/ else die(_("Invalid untracked files mode '%s'"), untracked_files_arg); }
@@ -1179,6 +1183,10 @@ static int parse_and_validate_options(int argc, const char *argv[],else if (!strcmp (cleanup_arg,"scissors" )) cleanup_mode = use_editor ?COMMIT_MSG_CLEANUP_SCISSORS :COMMIT_MSG_CLEANUP_SPACE ; +/* +* Please update _git_commit() in git-completion.bash when you +* add new options. +*/ else die (_ ("Invalid cleanup mode %s" ), cleanup_arg);
builtin/help.c +4 -0
@@ -70,6 +70,10 @@ static enum help_format parse_help_format(const char *format)return HELP_FORMAT_INFO ;if (!strcmp (format,"web" ) || !strcmp (format,"html" ))return HELP_FORMAT_WEB ; +/* +* Please update _git_config() in git-completion.bash when you +* add new help formats. +*/ die (_ ("unrecognized help format '%s'" ), format); }
builtin/log.c +8 -0
@@ -84,6 +84,10 @@ static int parse_decoration_style(const char *value)return DECORATE_SHORT_REFS ; else if (!strcmp(value, "auto"))return auto_decoration_style (); +/* +* Please update _git_log() in git-completion.bash when you +* add new decoration styles. +*/ return -1 ; }
@@ -1228,6 +1232,10 @@ static int thread_callback(const struct option *opt, const char *arg, int unset) *thread =THREAD_SHALLOW ; else if (!strcmp(arg, "deep")) *thread =THREAD_DEEP ; +/* +* Please update _git_formatpatch() in git-completion.bash +* when you add new options. +*/ else return 1;return 0 ;
builtin/pull.c +4 -0
@@ -56,6 +56,10 @@ static enum rebase_type parse_config_rebase(const char *key, const char *value,return REBASE_MERGES ; else if (!strcmp(value, "interactive") || !strcmp(value, "i"))return REBASE_INTERACTIVE ; +/* +* Please update _git_config() in git-completion.bash when you +* add new rebase modes. +*/ if (fatal)die (_ ("Invalid value for %s: %s" ), key, value);
builtin/replace.c +4 -0
@@ -82,6 +82,10 @@ static int list_replace_refs(const char *pattern, const char *format) data.format =REPLACE_FORMAT_MEDIUM ; else if (!strcmp(format, "long")) data.format =REPLACE_FORMAT_LONG ; +/* +* Please update _git_replace() in git-completion.bash when +* you add new format +*/ else return error(_("invalid replace format '%s'\n" "valid formats are 'short', 'medium' and 'long'"),
contrib/completion/git-completion.bash +40 -3
121 lines not on this page · raw message
date.c +4 -0
@@ -921,6 +921,10 @@ static enum date_mode_type parse_date_type(const char *format, const char **end)return DATE_UNIX ;if (skip_prefix (format,"format" , end))return DATE_STRFTIME ; +/* +* Please update $__git_log_date_formats in +* git-completion.bash when you add new formats. +*/ die ("unknown date format %s" , format); }
diff.c +8 -0
@@ -178,6 +178,10 @@ static int parse_submodule_params(struct diff_options *options, const char *valu options->submodule_format =DIFF_SUBMODULE_SHORT ; else if (!strcmp(value, "diff")) options->submodule_format =DIFF_SUBMODULE_INLINE_DIFF ; +/* +* Please update $__git_diff_submodule_formats in +* git-completion.bash when you add new formats. +*/ else return -1;return 0 ;
@@ -204,6 +208,10 @@ long parse_algorithm_value(const char *value)return XDF_PATIENCE_DIFF ; else if (!strcasecmp(value, "histogram"))return XDF_HISTOGRAM_DIFF ; +/* +* Please update $__git_diff_algorithms in git-completion.bash +* when you add new algorithms. +*/ return -1 ; }
git-send-email.perl +6 -0
@@ -465,6 +465,8 @@ sub read_config { my(%suppress_cc); if (@suppress_cc) { foreach my $entry (@suppress_cc) { + # Please update $__git_send_email_suppresscc_options + # in git-completion.bash when you add new options. die sprintf(__("Unknown --suppress-cc field: '%s'\n"), $entry) unless $entry =~ /^(?:all|cccmd|cc|author|self|sob|body|bodycc|misc-by)$/; $suppress_cc{$entry} = 1;
@@ -494,6 +496,8 @@ sub read_config { if ($confirm_unconfigured) { $confirm = scalar %suppress_cc ? 'compose' : 'auto'; }; +# Please update $__git_send_email_confirm_options in +# git-completion.bash when you add new options. die sprintf(__("Unknown --confirm setting: '%s'\n"), $confirm) unless $confirm =~ /^(?:auto|cc|compose|always|never)/;
@@ -587,6 +591,8 @@ sub parse_sendmail_aliases { if (/\(define-mail-alias\s+"(\S+?)"\s+"(\S+?)"\)/) { $aliases{$1} = [ $2 ]; }}} + # Please update _git_config() in git-completion.bash when you + # add new MUAs. ); if (@alias_files and $aliasfiletype and defined $parse_alias{$aliasfiletype}) {
list-objects-filter-options.c +4 -0
@@ -82,6 +82,10 @@ static int gently_parse_list_objects_filter( filter_options->sparse_path_value =strdup (v0);return 0 ; } +/* +* Please update _git_fetch() in git-completion.bash when you +* add new filters +*/ if (errbuf)strbuf_addf (errbuf,"invalid filter-spec '%s'" , arg);
merge-recursive.c +4 -0
@@ -3764,6 +3764,10 @@ int parse_merge_opt(struct merge_options *o, const char *s)return -1 ; o->merge_detect_rename =1 ; } +/* +* Please update $__git_merge_strategy_options in +* git-completion.bash when you add new options +*/ else return -1 ;return 0 ;
pretty.c +4 -0
@@ -98,6 +98,10 @@ static void setup_commit_formats(void) { "fuller", CMIT_FMT_FULLER, 0, 8 }, { "full", CMIT_FMT_FULL, 0, 8 }, { "oneline", CMIT_FMT_ONELINE, 1, 0 } + /* + * Please update $__git_log_pretty_formats in + * git-completion.bash when you add new formats. + */ }; commit_formats_len =ARRAY_SIZE (builtin_formats); builtin_formats_len = commit_formats_len;
ref-filter.c +4 -0
@@ -485,6 +485,10 @@ static struct { { "if", SOURCE_NONE, FIELD_STR, if_atom_parser }, { "then", SOURCE_NONE }, { "else", SOURCE_NONE }, + /* + * Please update $__git_ref_fieldlist in git-completion.bash + * when you add new atoms + */ };#define REF_FORMATTING_STATE_INIT { 0, NULL }
submodule-config.c +8 -1
@@ -281,7 +281,10 @@ static int parse_fetch_recurse(const char *opt, const char *arg,default :if (!strcmp (arg,"on-demand" ))return RECURSE_SUBMODULES_ON_DEMAND ; - +/* +* Please update $__git_fetch_recurse_submodules in +* git-completion.bash when you add new options. +*/ if (die_on_error)die ("bad %s argument: %s" , opt, arg);else
@@ -362,6 +365,10 @@ static int parse_push_recurse(const char *opt, const char *arg,return RECURSE_SUBMODULES_CHECK ; else if (!strcmp(arg, "only"))return RECURSE_SUBMODULES_ONLY ; +/* +* Please update $__git_push_recurse_submodules in +* git-completion.bash when you add new modes. +*/ else if (die_on_error) die("bad %s argument: %s", opt, arg); else
submodule.c +4 -0
@@ -432,6 +432,10 @@ void handle_ignore_submodules_arg(struct diff_options *diffopt, diffopt->flags.ignore_dirty_submodules =1 ; else if (strcmp(arg, "none")) die("bad --ignore-submodules argument: %s", arg); +/* +* Please update _git_status() in git-completion.bash when you +* add new options +*/ } static int prepare_submodule_summary(struct rev_info *rev, const char *path,
xdiff-interface.c +4 -0
@@ -306,6 +306,10 @@ int git_xmerge_config(const char *var, const char *value, void *cb) git_xmerge_style =XDL_MERGE_DIFF3 ; else if (!strcmp(value, "merge")) git_xmerge_style =0 ; +/* +* Please update _git_checkout() in +* git-completion.bash when you add new merge config +*/ else die("unknown style '%s' given for '%s'", value, var);
Signature · 1 line
2.21.0.rc0.328.g0e39304f8d