{"thread":{"id":"50347","subject":"[PATCH] completion: add more parameter value completion","startedAt":"2019-01-29T10:21:21Z","lastAt":"2019-02-16T11:24:59Z","messageCount":3,"participants":["Nguyễn Thái Ngọc Duy","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"367940","messageId":"20190129102111.15333-1-pclouds@gmail.com","threadId":"50347","inReplyTo":null,"subject":"[PATCH] completion: add more parameter value completion","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-01-29T10:21:11Z","receivedAt":"2019-01-29T10:21:21Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This adds value completion for a couple more paramters. To make it\neasier to maintain these hard coded lists, add a comment at the original\nlist/code to remind people to update git-completion.bash too.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n This 6 month old patch was part of the attempt to automate value\n completion. That might never come, but at least this is still good.\n\n apply.c                                |  4 +++\n builtin/am.c                           |  4 +++\n builtin/commit.c                       |  8 +++++\n builtin/help.c                         |  4 +++\n builtin/log.c                          |  8 +++++\n builtin/pull.c                         |  4 +++\n builtin/replace.c                      |  4 +++\n contrib/completion/git-completion.bash | 43 ++++++++++++++++++++++++--\n date.c                                 |  4 +++\n diff.c                                 |  8 +++++\n git-send-email.perl                    |  6 ++++\n list-objects-filter-options.c          |  4 +++\n merge-recursive.c                      |  4 +++\n pretty.c                               |  4 +++\n ref-filter.c                           |  4 +++\n submodule-config.c                     |  9 +++++-\n submodule.c                            |  4 +++\n xdiff-interface.c                      |  4 +++\n 18 files changed, 126 insertions(+), 4 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex 3703bfc8d0..1d09cd30bf 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -56,6 +56,10 @@ static int parse_whitespace_option(struct apply_state *state, const char *option\n \t\tstate->ws_error_action = correct_ws_error;\n \t\treturn 0;\n \t}\n+\t/*\n+\t * Please update $__git_whitespacelist in git-completion.bash\n+\t * when you add new options.\n+\t */\n \treturn error(_(\"unrecognized whitespace option '%s'\"), option);\n }\n \ndiff --git a/builtin/am.c b/builtin/am.c\nindex 95370313b6..b8fda67df0 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -2125,6 +2125,10 @@ static int parse_opt_patchformat(const struct option *opt, const char *arg, int\n \t\t*opt_value = PATCH_FORMAT_HG;\n \telse if (!strcmp(arg, \"mboxrd\"))\n \t\t*opt_value = PATCH_FORMAT_MBOXRD;\n+\t/*\n+\t * Please update $__git_patchformat in git-completion.bash\n+\t * when you add new options\n+\t */\n \telse\n \t\treturn error(_(\"Invalid value for --patch-format: %s\"), arg);\n \treturn 0;\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 004b816635..11cd807f0c 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1036,6 +1036,10 @@ static void handle_untracked_files_arg(struct wt_status *s)\n \t\ts->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;\n \telse if (!strcmp(untracked_files_arg, \"all\"))\n \t\ts->show_untracked_files = SHOW_ALL_UNTRACKED_FILES;\n+\t/*\n+\t * Please update $__git_untracked_file_modes in\n+\t * git-completion.bash when add new options\n+\t */\n \telse\n \t\tdie(_(\"Invalid untracked files mode '%s'\"), untracked_files_arg);\n }\n@@ -1177,6 +1181,10 @@ static int parse_and_validate_options(int argc, const char *argv[],\n \telse if (!strcmp(cleanup_arg, \"scissors\"))\n \t\tcleanup_mode = use_editor ? COMMIT_MSG_CLEANUP_SCISSORS :\n \t\t\t\t\t    COMMIT_MSG_CLEANUP_SPACE;\n+\t/*\n+\t * Please update _git_commit() in git-completion.bash when you\n+\t * add new options.\n+\t */\n \telse\n \t\tdie(_(\"Invalid cleanup mode %s\"), cleanup_arg);\n \ndiff --git a/builtin/help.c b/builtin/help.c\nindex 7739a5c155..eef8b7c802 100644\n--- a/builtin/help.c\n+++ b/builtin/help.c\n@@ -70,6 +70,10 @@ static enum help_format parse_help_format(const char *format)\n \t\treturn HELP_FORMAT_INFO;\n \tif (!strcmp(format, \"web\") || !strcmp(format, \"html\"))\n \t\treturn HELP_FORMAT_WEB;\n+\t/*\n+\t * Please update _git_config() in git-completion.bash when you\n+\t * add new rebase modes.\n+\t */\n \tdie(_(\"unrecognized help format '%s'\"), format);\n }\n \ndiff --git a/builtin/log.c b/builtin/log.c\nindex 3e145fe502..68a2411b2f 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -83,6 +83,10 @@ static int parse_decoration_style(const char *value)\n \t\treturn DECORATE_SHORT_REFS;\n \telse if (!strcmp(value, \"auto\"))\n \t\treturn auto_decoration_style();\n+\t/*\n+\t * Please update _git_log() in git-completion.bash when you\n+\t * add new decoration styles.\n+\t */\n \treturn -1;\n }\n \n@@ -1225,6 +1229,10 @@ static int thread_callback(const struct option *opt, const char *arg, int unset)\n \t\t*thread = THREAD_SHALLOW;\n \telse if (!strcmp(arg, \"deep\"))\n \t\t*thread = THREAD_DEEP;\n+\t/*\n+\t * Please update _git_formatpatch() in git-completion.bash\n+\t * when you add new options.\n+\t */\n \telse\n \t\treturn 1;\n \treturn 0;\ndiff --git a/builtin/pull.c b/builtin/pull.c\nindex 74808b9455..ab8da063b4 100644\n--- a/builtin/pull.c\n+++ b/builtin/pull.c\n@@ -55,6 +55,10 @@ static enum rebase_type parse_config_rebase(const char *key, const char *value,\n \t\treturn REBASE_MERGES;\n \telse if (!strcmp(value, \"interactive\") || !strcmp(value, \"i\"))\n \t\treturn REBASE_INTERACTIVE;\n+\t/*\n+\t * Please update _git_config() in git-completion.bash when you\n+\t * add new rebase modes.\n+\t */\n \n \tif (fatal)\n \t\tdie(_(\"Invalid value for %s: %s\"), key, value);\ndiff --git a/builtin/replace.c b/builtin/replace.c\nindex affcdfb416..1c312725d1 100644\n--- a/builtin/replace.c\n+++ b/builtin/replace.c\n@@ -82,6 +82,10 @@ static int list_replace_refs(const char *pattern, const char *format)\n \t\tdata.format = REPLACE_FORMAT_MEDIUM;\n \telse if (!strcmp(format, \"long\"))\n \t\tdata.format = REPLACE_FORMAT_LONG;\n+\t/*\n+\t * Please update _git_replace() in git-completion.bash when\n+\t * you add ne format\n+\t */\n \telse\n \t\treturn error(_(\"invalid replace format '%s'\\n\"\n \t\t\t       \"valid formats are 'short', 'medium' and 'long'\"),\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 499e56f83d..907855184c 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -853,6 +853,11 @@ __git_compute_merge_strategies ()\n \t__git_merge_strategies=$(__git_list_merge_strategies)\n }\n \n+__git_merge_strategy_options=\"ours theirs subtree subtree= patience\n+\thistogram diff-algorithm= ignore-space-change ignore-all-space\n+\tignore-space-at-eol renormalize no-renormalize no-renames\n+\tfind-renames find-renames= rename-threshold=\"\n+\n __git_complete_revlist_file ()\n {\n \tlocal dequoted_word pfx ls ref cur_=\"$cur\"\n@@ -996,12 +1001,21 @@ __git_complete_strategy ()\n \t-s|--strategy)\n \t\t__gitcomp \"$__git_merge_strategies\"\n \t\treturn 0\n+\t\t;;\n+\t-X)\n+\t\t__gitcomp \"$__git_merge_strategy_options\"\n+\t\treturn 0\n+\t\t;;\n \tesac\n \tcase \"$cur\" in\n \t--strategy=*)\n \t\t__gitcomp \"$__git_merge_strategies\" \"\" \"${cur##--strategy=}\"\n \t\treturn 0\n \t\t;;\n+\t--strategy-option=*)\n+\t\t__gitcomp \"$__git_merge_strategy_options\" \"\" \"${cur##--strategy-option=}\"\n+\t\treturn 0\n+\t\t;;\n \tesac\n \treturn 1\n }\n@@ -1163,6 +1177,7 @@ __git_count_arguments ()\n }\n \n __git_whitespacelist=\"nowarn warn error error-all fix\"\n+__git_patchformat=\"mbox stgit stgit-series hg mboxrd\"\n __git_am_inprogress_options=\"--skip --continue --resolved --abort --quit --show-current-patch\"\n \n _git_am ()\n@@ -1177,6 +1192,10 @@ _git_am ()\n \t\t__gitcomp \"$__git_whitespacelist\" \"\" \"${cur##--whitespace=}\"\n \t\treturn\n \t\t;;\n+\t--patch-format=*)\n+\t\t__gitcomp \"$__git_patchformat\" \"\" \"${cur##--patch-format=}\"\n+\t\treturn\n+\t\t;;\n \t--*)\n \t\t__gitcomp_builtin am \"\" \\\n \t\t\t\"$__git_am_inprogress_options\"\n@@ -1200,6 +1219,10 @@ _git_apply ()\n _git_add ()\n {\n \tcase \"$cur\" in\n+\t--chmod=*)\n+\t\t__gitcomp \"+x -x\" \"\" \"${cur##--chmod=}\"\n+\t\treturn\n+\t\t;;\n \t--*)\n \t\t__gitcomp_builtin add\n \t\treturn\n@@ -1260,6 +1283,8 @@ _git_bisect ()\n \tesac\n }\n \n+__git_ref_fieldlist=\"refname objecttype objectsize objectname upstream push HEAD symref\"\n+\n _git_branch ()\n {\n \tlocal i c=1 only_local_ref=\"n\" has_r=\"n\"\n@@ -1343,6 +1368,9 @@ _git_cherry_pick ()\n \t\t__gitcomp \"$__git_cherry_pick_inprogress_options\"\n \t\treturn\n \tfi\n+\n+\t__git_complete_strategy && return\n+\n \tcase \"$cur\" in\n \t--*)\n \t\t__gitcomp_builtin cherry-pick \"\" \\\n@@ -1506,6 +1534,10 @@ _git_fetch ()\n \t\t__gitcomp \"$__git_fetch_recurse_submodules\" \"\" \"${cur##--recurse-submodules=}\"\n \t\treturn\n \t\t;;\n+\t--filter=*)\n+\t\t__gitcomp \"blob:none blob:limit= sparse:oid= sparse:path=\" \"\" \"${cur##--filter=}\"\n+\t\treturn\n+\t\t;;\n \t--*)\n \t\t__gitcomp_builtin fetch\n \t\treturn\n@@ -1702,8 +1734,8 @@ __git_log_shortlog_options=\"\n \t--all-match --invert-grep\n \"\n \n-__git_log_pretty_formats=\"oneline short medium full fuller email raw format:\"\n-__git_log_date_formats=\"relative iso8601 rfc2822 short local default raw\"\n+__git_log_pretty_formats=\"oneline short medium full fuller email raw format: mboxrd\"\n+__git_log_date_formats=\"relative iso8601 iso8601-strict rfc2822 short local default raw unix format:\"\n \n _git_log ()\n {\n@@ -2221,7 +2253,7 @@ _git_config ()\n \t\treturn\n \t\t;;\n \tdiff.submodule)\n-\t\t__gitcomp \"log short\"\n+\t\t__gitcomp \"$__git_diff_submodule_formats\"\n \t\treturn\n \t\t;;\n \thelp.format)\n@@ -2388,6 +2420,10 @@ _git_remote ()\n _git_replace ()\n {\n \tcase \"$cur\" in\n+\t--format=*)\n+\t\t__gitcomp \"short medium long\" \"\" \"${cur##--format=}\"\n+\t\treturn\n+\t\t;;\n \t--*)\n \t\t__gitcomp_builtin replace\n \t\treturn\n@@ -2429,6 +2465,7 @@ _git_revert ()\n \t\t__gitcomp \"$__git_revert_inprogress_options\"\n \t\treturn\n \tfi\n+\t__git_complete_strategy && return\n \tcase \"$cur\" in\n \t--*)\n \t\t__gitcomp_builtin revert \"\" \\\ndiff --git a/date.c b/date.c\nindex 9bc15df6f9..6d517871f4 100644\n--- a/date.c\n+++ b/date.c\n@@ -825,6 +825,10 @@ static enum date_mode_type parse_date_type(const char *format, const char **end)\n \t\treturn DATE_UNIX;\n \tif (skip_prefix(format, \"format\", end))\n \t\treturn DATE_STRFTIME;\n+\t/*\n+\t * Please update $__git_log_date_formats in\n+\t * git-completion.bash when you add new formats.\n+\t */\n \n \tdie(\"unknown date format %s\", format);\n }\ndiff --git a/diff.c b/diff.c\nindex 1b5f276360..ffa497b203 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -178,6 +178,10 @@ static int parse_submodule_params(struct diff_options *options, const char *valu\n \t\toptions->submodule_format = DIFF_SUBMODULE_SHORT;\n \telse if (!strcmp(value, \"diff\"))\n \t\toptions->submodule_format = DIFF_SUBMODULE_INLINE_DIFF;\n+\t/*\n+\t * Please update $__git_diff_submodule_formats in\n+\t * git-completion.bash when you add new formats.\n+\t */\n \telse\n \t\treturn -1;\n \treturn 0;\n@@ -204,6 +208,10 @@ long parse_algorithm_value(const char *value)\n \t\treturn XDF_PATIENCE_DIFF;\n \telse if (!strcasecmp(value, \"histogram\"))\n \t\treturn XDF_HISTOGRAM_DIFF;\n+\t/*\n+\t * Please update $__git_diff_algorithms in git-completion.bash\n+\t * when you add new algorithms.\n+\t */\n \treturn -1;\n }\n \ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 8eb63b5a2f..8200d58cdc 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -465,6 +465,8 @@ sub read_config {\n my(%suppress_cc);\n if (@suppress_cc) {\n \tforeach my $entry (@suppress_cc) {\n+\t\t# Please update $__git_send_email_suppresscc_options\n+\t\t# in git-completion.bash when you add new options.\n \t\tdie sprintf(__(\"Unknown --suppress-cc field: '%s'\\n\"), $entry)\n \t\t\tunless $entry =~ /^(?:all|cccmd|cc|author|self|sob|body|bodycc|misc-by)$/;\n \t\t$suppress_cc{$entry} = 1;\n@@ -494,6 +496,8 @@ sub read_config {\n if ($confirm_unconfigured) {\n \t$confirm = scalar %suppress_cc ? 'compose' : 'auto';\n };\n+# Please update $__git_send_email_confirm_options in\n+# git-completion.bash when you add new options.\n die sprintf(__(\"Unknown --confirm setting: '%s'\\n\"), $confirm)\n \tunless $confirm =~ /^(?:auto|cc|compose|always|never)/;\n \n@@ -587,6 +591,8 @@ sub parse_sendmail_aliases {\n \t\tif (/\\(define-mail-alias\\s+\"(\\S+?)\"\\s+\"(\\S+?)\"\\)/) {\n \t\t\t$aliases{$1} = [ $2 ];\n \t\t}}}\n+\t# Please update _git_config() in git-completion.bash when you\n+\t# add new MUAs.\n );\n \n if (@alias_files and $aliasfiletype and defined $parse_alias{$aliasfiletype}) {\ndiff --git a/list-objects-filter-options.c b/list-objects-filter-options.c\nindex e8da2e8581..24f1c95560 100644\n--- a/list-objects-filter-options.c\n+++ b/list-objects-filter-options.c\n@@ -82,6 +82,10 @@ static int gently_parse_list_objects_filter(\n \t\tfilter_options->sparse_path_value = strdup(v0);\n \t\treturn 0;\n \t}\n+\t/*\n+\t * Please update _git_fetch() in git-completion.bash when you\n+\t * add new filter\n+\t */\n \n \tif (errbuf)\n \t\tstrbuf_addf(errbuf, \"invalid filter-spec '%s'\", arg);\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 59ba4b4a1a..be08f74ea4 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -3749,6 +3749,10 @@ int parse_merge_opt(struct merge_options *o, const char *s)\n \t\t\treturn -1;\n \t\to->merge_detect_rename = 1;\n \t}\n+\t/*\n+\t * Please update $__git_merge_strategy_options in\n+\t * git-completion.bash when you add new options\n+\t */\n \telse\n \t\treturn -1;\n \treturn 0;\ndiff --git a/pretty.c b/pretty.c\nindex b83a3ecd23..876c1195f5 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -98,6 +98,10 @@ static void setup_commit_formats(void)\n \t\t{ \"fuller\",\tCMIT_FMT_FULLER,\t0,\t8 },\n \t\t{ \"full\",\tCMIT_FMT_FULL,\t\t0,\t8 },\n \t\t{ \"oneline\",\tCMIT_FMT_ONELINE,\t1,\t0 }\n+\t\t/*\n+\t\t * Please update $__git_log_pretty_formats in\n+\t\t * git-completion.bash when you add new formats.\n+\t\t */\n \t};\n \tcommit_formats_len = ARRAY_SIZE(builtin_formats);\n \tbuiltin_formats_len = commit_formats_len;\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 422a9c9ae3..cf80d4d69b 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -485,6 +485,10 @@ static struct {\n \t{ \"if\", SOURCE_NONE, FIELD_STR, if_atom_parser },\n \t{ \"then\", SOURCE_NONE },\n \t{ \"else\", SOURCE_NONE },\n+\t/*\n+\t * Please update $__git_ref_fieldlist in git-completion.bash\n+\t * when you add new atoms\n+\t */\n };\n \n #define REF_FORMATTING_STATE_INIT  { 0, NULL }\ndiff --git a/submodule-config.c b/submodule-config.c\nindex 52702c62d9..66653e86b9 100644\n--- a/submodule-config.c\n+++ b/submodule-config.c\n@@ -281,7 +281,10 @@ static int parse_fetch_recurse(const char *opt, const char *arg,\n \tdefault:\n \t\tif (!strcmp(arg, \"on-demand\"))\n \t\t\treturn RECURSE_SUBMODULES_ON_DEMAND;\n-\n+\t\t/*\n+\t\t * Please update $__git_fetch_recurse_submodules in\n+\t\t * git-completion.bash when you add new options.\n+\t\t */\n \t\tif (die_on_error)\n \t\t\tdie(\"bad %s argument: %s\", opt, arg);\n \t\telse\n@@ -362,6 +365,10 @@ static int parse_push_recurse(const char *opt, const char *arg,\n \t\t\treturn RECURSE_SUBMODULES_CHECK;\n \t\telse if (!strcmp(arg, \"only\"))\n \t\t\treturn RECURSE_SUBMODULES_ONLY;\n+\t\t/*\n+\t\t * Please update $__git_push_recurse_submodules in\n+\t\t * git-completion.bash when you add new modes.\n+\t\t */\n \t\telse if (die_on_error)\n \t\t\tdie(\"bad %s argument: %s\", opt, arg);\n \t\telse\ndiff --git a/submodule.c b/submodule.c\nindex d393e947e6..f8c6ac11be 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -434,6 +434,10 @@ void handle_ignore_submodules_arg(struct diff_options *diffopt,\n \t\tdiffopt->flags.ignore_dirty_submodules = 1;\n \telse if (strcmp(arg, \"none\"))\n \t\tdie(\"bad --ignore-submodules argument: %s\", arg);\n+\t/*\n+\t * Please update _git_status() in git-completion.bash when you\n+\t * add new options\n+\t */\n }\n \n static int prepare_submodule_summary(struct rev_info *rev, const char *path,\ndiff --git a/xdiff-interface.c b/xdiff-interface.c\nindex 80f060d278..8509f9ea22 100644\n--- a/xdiff-interface.c\n+++ b/xdiff-interface.c\n@@ -306,6 +306,10 @@ int git_xmerge_config(const char *var, const char *value, void *cb)\n \t\t\tgit_xmerge_style = XDL_MERGE_DIFF3;\n \t\telse if (!strcmp(value, \"merge\"))\n \t\t\tgit_xmerge_style = 0;\n+\t\t/*\n+\t\t * Please update _git_checkout() in\n+\t\t * git-completion.bash when you add new merge config\n+\t\t */\n \t\telse\n \t\t\tdie(\"unknown style '%s' given for '%s'\",\n \t\t\t    value, var);\n-- \n2.20.1.560.g70ca8b83ee\n\n"},{"id":"369021","messageId":"xmqqbm3ii2ek.fsf@gitster-ct.c.googlers.com","threadId":"50347","inReplyTo":"20190129102111.15333-1-pclouds@gmail.com","subject":"Re: [PATCH] completion: add more parameter value completion","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-02-11T18:52:03Z","receivedAt":"2019-02-11T18:52:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n\nNguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n\n> This adds value completion for a couple more paramters. To make it\n> easier to maintain these hard coded lists, add a comment at the original\n> list/code to remind people to update git-completion.bash too.\n>\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  This 6 month old patch was part of the attempt to automate value\n>  completion. That might never come, but at least this is still good.\n\nPerhaps this is not yet good without proofreading.\n\n> diff --git a/builtin/help.c b/builtin/help.c\n> index 7739a5c155..eef8b7c802 100644\n> --- a/builtin/help.c\n> +++ b/builtin/help.c\n> @@ -70,6 +70,10 @@ static enum help_format parse_help_format(const char *format)\n>  \t\treturn HELP_FORMAT_INFO;\n>  \tif (!strcmp(format, \"web\") || !strcmp(format, \"html\"))\n>  \t\treturn HELP_FORMAT_WEB;\n> +\t/*\n> +\t * Please update _git_config() in git-completion.bash when you\n> +\t * add new rebase modes.\n> +\t */\n\nHuh?  s/rebase modes/help formats/, I guess.\n\n>  \tdie(_(\"unrecognized help format '%s'\"), format);\n>  }\n\n> diff --git a/builtin/replace.c b/builtin/replace.c\n> index affcdfb416..1c312725d1 100644\n> --- a/builtin/replace.c\n> +++ b/builtin/replace.c\n> @@ -82,6 +82,10 @@ static int list_replace_refs(const char *pattern, const char *format)\n>  \t\tdata.format = REPLACE_FORMAT_MEDIUM;\n>  \telse if (!strcmp(format, \"long\"))\n>  \t\tdata.format = REPLACE_FORMAT_LONG;\n> +\t/*\n> +\t * Please update _git_replace() in git-completion.bash when\n> +\t * you add ne format\n\ns/ne/&w/;\n"},{"id":"369435","messageId":"20190216112441.22361-1-pclouds@gmail.com","threadId":"50347","inReplyTo":"20190129102111.15333-1-pclouds@gmail.com","subject":"[PATCH v2] completion: add more parameter value completion","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-02-16T11:24:41Z","receivedAt":"2019-02-16T11:24:59Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This adds value completion for a couple more paramters. To make it\neasier to maintain these hard coded lists, add a comment at the original\nlist/code to remind people to update git-completion.bash too.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n apply.c                                |  4 +++\n builtin/am.c                           |  4 +++\n builtin/commit.c                       |  8 +++++\n builtin/help.c                         |  4 +++\n builtin/log.c                          |  8 +++++\n builtin/pull.c                         |  4 +++\n builtin/replace.c                      |  4 +++\n contrib/completion/git-completion.bash | 43 ++++++++++++++++++++++++--\n date.c                                 |  4 +++\n diff.c                                 |  8 +++++\n git-send-email.perl                    |  6 ++++\n list-objects-filter-options.c          |  4 +++\n merge-recursive.c                      |  4 +++\n pretty.c                               |  4 +++\n ref-filter.c                           |  4 +++\n submodule-config.c                     |  9 +++++-\n submodule.c                            |  4 +++\n xdiff-interface.c                      |  4 +++\n 18 files changed, 126 insertions(+), 4 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex 892ede5a31..f15afa9f6a 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -56,6 +56,10 @@ static int parse_whitespace_option(struct apply_state *state, const char *option\n \t\tstate->ws_error_action = correct_ws_error;\n \t\treturn 0;\n \t}\n+\t/*\n+\t * Please update $__git_whitespacelist in git-completion.bash\n+\t * when you add new options.\n+\t */\n \treturn error(_(\"unrecognized whitespace option '%s'\"), option);\n }\n \ndiff --git a/builtin/am.c b/builtin/am.c\nindex 58a2aef28b..e8522450cb 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -2119,6 +2119,10 @@ static int parse_opt_patchformat(const struct option *opt, const char *arg, int\n \t\t*opt_value = PATCH_FORMAT_HG;\n \telse if (!strcmp(arg, \"mboxrd\"))\n \t\t*opt_value = PATCH_FORMAT_MBOXRD;\n+\t/*\n+\t * Please update $__git_patchformat in git-completion.bash\n+\t * when you add new options\n+\t */\n \telse\n \t\treturn error(_(\"Invalid value for --patch-format: %s\"), arg);\n \treturn 0;\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 2986553d5f..b9e396f5e3 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1038,6 +1038,10 @@ static void handle_untracked_files_arg(struct wt_status *s)\n \t\ts->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;\n \telse if (!strcmp(untracked_files_arg, \"all\"))\n \t\ts->show_untracked_files = SHOW_ALL_UNTRACKED_FILES;\n+\t/*\n+\t * Please update $__git_untracked_file_modes in\n+\t * git-completion.bash when you add new options\n+\t */\n \telse\n \t\tdie(_(\"Invalid untracked files mode '%s'\"), untracked_files_arg);\n }\n@@ -1179,6 +1183,10 @@ static int parse_and_validate_options(int argc, const char *argv[],\n \telse if (!strcmp(cleanup_arg, \"scissors\"))\n \t\tcleanup_mode = use_editor ? COMMIT_MSG_CLEANUP_SCISSORS :\n \t\t\t\t\t    COMMIT_MSG_CLEANUP_SPACE;\n+\t/*\n+\t * Please update _git_commit() in git-completion.bash when you\n+\t * add new options.\n+\t */\n \telse\n \t\tdie(_(\"Invalid cleanup mode %s\"), cleanup_arg);\n \ndiff --git a/builtin/help.c b/builtin/help.c\nindex 7739a5c155..e5590d7787 100644\n--- a/builtin/help.c\n+++ b/builtin/help.c\n@@ -70,6 +70,10 @@ static enum help_format parse_help_format(const char *format)\n \t\treturn HELP_FORMAT_INFO;\n \tif (!strcmp(format, \"web\") || !strcmp(format, \"html\"))\n \t\treturn HELP_FORMAT_WEB;\n+\t/*\n+\t * Please update _git_config() in git-completion.bash when you\n+\t * add new help formats.\n+\t */\n \tdie(_(\"unrecognized help format '%s'\"), format);\n }\n \ndiff --git a/builtin/log.c b/builtin/log.c\nindex 57869267d8..ab859f5904 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -84,6 +84,10 @@ static int parse_decoration_style(const char *value)\n \t\treturn DECORATE_SHORT_REFS;\n \telse if (!strcmp(value, \"auto\"))\n \t\treturn auto_decoration_style();\n+\t/*\n+\t * Please update _git_log() in git-completion.bash when you\n+\t * add new decoration styles.\n+\t */\n \treturn -1;\n }\n \n@@ -1228,6 +1232,10 @@ static int thread_callback(const struct option *opt, const char *arg, int unset)\n \t\t*thread = THREAD_SHALLOW;\n \telse if (!strcmp(arg, \"deep\"))\n \t\t*thread = THREAD_DEEP;\n+\t/*\n+\t * Please update _git_formatpatch() in git-completion.bash\n+\t * when you add new options.\n+\t */\n \telse\n \t\treturn 1;\n \treturn 0;\ndiff --git a/builtin/pull.c b/builtin/pull.c\nindex 701d1473dc..33db889955 100644\n--- a/builtin/pull.c\n+++ b/builtin/pull.c\n@@ -56,6 +56,10 @@ static enum rebase_type parse_config_rebase(const char *key, const char *value,\n \t\treturn REBASE_MERGES;\n \telse if (!strcmp(value, \"interactive\") || !strcmp(value, \"i\"))\n \t\treturn REBASE_INTERACTIVE;\n+\t/*\n+\t * Please update _git_config() in git-completion.bash when you\n+\t * add new rebase modes.\n+\t */\n \n \tif (fatal)\n \t\tdie(_(\"Invalid value for %s: %s\"), key, value);\ndiff --git a/builtin/replace.c b/builtin/replace.c\nindex 5b80b7f211..f5701629a8 100644\n--- a/builtin/replace.c\n+++ b/builtin/replace.c\n@@ -82,6 +82,10 @@ static int list_replace_refs(const char *pattern, const char *format)\n \t\tdata.format = REPLACE_FORMAT_MEDIUM;\n \telse if (!strcmp(format, \"long\"))\n \t\tdata.format = REPLACE_FORMAT_LONG;\n+\t/*\n+\t * Please update _git_replace() in git-completion.bash when\n+\t * you add new format\n+\t */\n \telse\n \t\treturn error(_(\"invalid replace format '%s'\\n\"\n \t\t\t       \"valid formats are 'short', 'medium' and 'long'\"),\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 499e56f83d..907855184c 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -853,6 +853,11 @@ __git_compute_merge_strategies ()\n \t__git_merge_strategies=$(__git_list_merge_strategies)\n }\n \n+__git_merge_strategy_options=\"ours theirs subtree subtree= patience\n+\thistogram diff-algorithm= ignore-space-change ignore-all-space\n+\tignore-space-at-eol renormalize no-renormalize no-renames\n+\tfind-renames find-renames= rename-threshold=\"\n+\n __git_complete_revlist_file ()\n {\n \tlocal dequoted_word pfx ls ref cur_=\"$cur\"\n@@ -996,12 +1001,21 @@ __git_complete_strategy ()\n \t-s|--strategy)\n \t\t__gitcomp \"$__git_merge_strategies\"\n \t\treturn 0\n+\t\t;;\n+\t-X)\n+\t\t__gitcomp \"$__git_merge_strategy_options\"\n+\t\treturn 0\n+\t\t;;\n \tesac\n \tcase \"$cur\" in\n \t--strategy=*)\n \t\t__gitcomp \"$__git_merge_strategies\" \"\" \"${cur##--strategy=}\"\n \t\treturn 0\n \t\t;;\n+\t--strategy-option=*)\n+\t\t__gitcomp \"$__git_merge_strategy_options\" \"\" \"${cur##--strategy-option=}\"\n+\t\treturn 0\n+\t\t;;\n \tesac\n \treturn 1\n }\n@@ -1163,6 +1177,7 @@ __git_count_arguments ()\n }\n \n __git_whitespacelist=\"nowarn warn error error-all fix\"\n+__git_patchformat=\"mbox stgit stgit-series hg mboxrd\"\n __git_am_inprogress_options=\"--skip --continue --resolved --abort --quit --show-current-patch\"\n \n _git_am ()\n@@ -1177,6 +1192,10 @@ _git_am ()\n \t\t__gitcomp \"$__git_whitespacelist\" \"\" \"${cur##--whitespace=}\"\n \t\treturn\n \t\t;;\n+\t--patch-format=*)\n+\t\t__gitcomp \"$__git_patchformat\" \"\" \"${cur##--patch-format=}\"\n+\t\treturn\n+\t\t;;\n \t--*)\n \t\t__gitcomp_builtin am \"\" \\\n \t\t\t\"$__git_am_inprogress_options\"\n@@ -1200,6 +1219,10 @@ _git_apply ()\n _git_add ()\n {\n \tcase \"$cur\" in\n+\t--chmod=*)\n+\t\t__gitcomp \"+x -x\" \"\" \"${cur##--chmod=}\"\n+\t\treturn\n+\t\t;;\n \t--*)\n \t\t__gitcomp_builtin add\n \t\treturn\n@@ -1260,6 +1283,8 @@ _git_bisect ()\n \tesac\n }\n \n+__git_ref_fieldlist=\"refname objecttype objectsize objectname upstream push HEAD symref\"\n+\n _git_branch ()\n {\n \tlocal i c=1 only_local_ref=\"n\" has_r=\"n\"\n@@ -1343,6 +1368,9 @@ _git_cherry_pick ()\n \t\t__gitcomp \"$__git_cherry_pick_inprogress_options\"\n \t\treturn\n \tfi\n+\n+\t__git_complete_strategy && return\n+\n \tcase \"$cur\" in\n \t--*)\n \t\t__gitcomp_builtin cherry-pick \"\" \\\n@@ -1506,6 +1534,10 @@ _git_fetch ()\n \t\t__gitcomp \"$__git_fetch_recurse_submodules\" \"\" \"${cur##--recurse-submodules=}\"\n \t\treturn\n \t\t;;\n+\t--filter=*)\n+\t\t__gitcomp \"blob:none blob:limit= sparse:oid= sparse:path=\" \"\" \"${cur##--filter=}\"\n+\t\treturn\n+\t\t;;\n \t--*)\n \t\t__gitcomp_builtin fetch\n \t\treturn\n@@ -1702,8 +1734,8 @@ __git_log_shortlog_options=\"\n \t--all-match --invert-grep\n \"\n \n-__git_log_pretty_formats=\"oneline short medium full fuller email raw format:\"\n-__git_log_date_formats=\"relative iso8601 rfc2822 short local default raw\"\n+__git_log_pretty_formats=\"oneline short medium full fuller email raw format: mboxrd\"\n+__git_log_date_formats=\"relative iso8601 iso8601-strict rfc2822 short local default raw unix format:\"\n \n _git_log ()\n {\n@@ -2221,7 +2253,7 @@ _git_config ()\n \t\treturn\n \t\t;;\n \tdiff.submodule)\n-\t\t__gitcomp \"log short\"\n+\t\t__gitcomp \"$__git_diff_submodule_formats\"\n \t\treturn\n \t\t;;\n \thelp.format)\n@@ -2388,6 +2420,10 @@ _git_remote ()\n _git_replace ()\n {\n \tcase \"$cur\" in\n+\t--format=*)\n+\t\t__gitcomp \"short medium long\" \"\" \"${cur##--format=}\"\n+\t\treturn\n+\t\t;;\n \t--*)\n \t\t__gitcomp_builtin replace\n \t\treturn\n@@ -2429,6 +2465,7 @@ _git_revert ()\n \t\t__gitcomp \"$__git_revert_inprogress_options\"\n \t\treturn\n \tfi\n+\t__git_complete_strategy && return\n \tcase \"$cur\" in\n \t--*)\n \t\t__gitcomp_builtin revert \"\" \\\ndiff --git a/date.c b/date.c\nindex 9c5870e102..8126146c50 100644\n--- a/date.c\n+++ b/date.c\n@@ -921,6 +921,10 @@ static enum date_mode_type parse_date_type(const char *format, const char **end)\n \t\treturn DATE_UNIX;\n \tif (skip_prefix(format, \"format\", end))\n \t\treturn DATE_STRFTIME;\n+\t/*\n+\t * Please update $__git_log_date_formats in\n+\t * git-completion.bash when you add new formats.\n+\t */\n \n \tdie(\"unknown date format %s\", format);\n }\ndiff --git a/diff.c b/diff.c\nindex 5306c48652..a1f301b66c 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -178,6 +178,10 @@ static int parse_submodule_params(struct diff_options *options, const char *valu\n \t\toptions->submodule_format = DIFF_SUBMODULE_SHORT;\n \telse if (!strcmp(value, \"diff\"))\n \t\toptions->submodule_format = DIFF_SUBMODULE_INLINE_DIFF;\n+\t/*\n+\t * Please update $__git_diff_submodule_formats in\n+\t * git-completion.bash when you add new formats.\n+\t */\n \telse\n \t\treturn -1;\n \treturn 0;\n@@ -204,6 +208,10 @@ long parse_algorithm_value(const char *value)\n \t\treturn XDF_PATIENCE_DIFF;\n \telse if (!strcasecmp(value, \"histogram\"))\n \t\treturn XDF_HISTOGRAM_DIFF;\n+\t/*\n+\t * Please update $__git_diff_algorithms in git-completion.bash\n+\t * when you add new algorithms.\n+\t */\n \treturn -1;\n }\n \ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 8eb63b5a2f..8200d58cdc 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -465,6 +465,8 @@ sub read_config {\n my(%suppress_cc);\n if (@suppress_cc) {\n \tforeach my $entry (@suppress_cc) {\n+\t\t# Please update $__git_send_email_suppresscc_options\n+\t\t# in git-completion.bash when you add new options.\n \t\tdie sprintf(__(\"Unknown --suppress-cc field: '%s'\\n\"), $entry)\n \t\t\tunless $entry =~ /^(?:all|cccmd|cc|author|self|sob|body|bodycc|misc-by)$/;\n \t\t$suppress_cc{$entry} = 1;\n@@ -494,6 +496,8 @@ sub read_config {\n if ($confirm_unconfigured) {\n \t$confirm = scalar %suppress_cc ? 'compose' : 'auto';\n };\n+# Please update $__git_send_email_confirm_options in\n+# git-completion.bash when you add new options.\n die sprintf(__(\"Unknown --confirm setting: '%s'\\n\"), $confirm)\n \tunless $confirm =~ /^(?:auto|cc|compose|always|never)/;\n \n@@ -587,6 +591,8 @@ sub parse_sendmail_aliases {\n \t\tif (/\\(define-mail-alias\\s+\"(\\S+?)\"\\s+\"(\\S+?)\"\\)/) {\n \t\t\t$aliases{$1} = [ $2 ];\n \t\t}}}\n+\t# Please update _git_config() in git-completion.bash when you\n+\t# add new MUAs.\n );\n \n if (@alias_files and $aliasfiletype and defined $parse_alias{$aliasfiletype}) {\ndiff --git a/list-objects-filter-options.c b/list-objects-filter-options.c\nindex b71bd1fb65..c0036f7378 100644\n--- a/list-objects-filter-options.c\n+++ b/list-objects-filter-options.c\n@@ -82,6 +82,10 @@ static int gently_parse_list_objects_filter(\n \t\tfilter_options->sparse_path_value = strdup(v0);\n \t\treturn 0;\n \t}\n+\t/*\n+\t * Please update _git_fetch() in git-completion.bash when you\n+\t * add new filters\n+\t */\n \n \tif (errbuf)\n \t\tstrbuf_addf(errbuf, \"invalid filter-spec '%s'\", arg);\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 4851825aeb..28b36c08f2 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -3764,6 +3764,10 @@ int parse_merge_opt(struct merge_options *o, const char *s)\n \t\t\treturn -1;\n \t\to->merge_detect_rename = 1;\n \t}\n+\t/*\n+\t * Please update $__git_merge_strategy_options in\n+\t * git-completion.bash when you add new options\n+\t */\n \telse\n \t\treturn -1;\n \treturn 0;\ndiff --git a/pretty.c b/pretty.c\nindex 0ab45d10d7..55739a0337 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -98,6 +98,10 @@ static void setup_commit_formats(void)\n \t\t{ \"fuller\",\tCMIT_FMT_FULLER,\t0,\t8 },\n \t\t{ \"full\",\tCMIT_FMT_FULL,\t\t0,\t8 },\n \t\t{ \"oneline\",\tCMIT_FMT_ONELINE,\t1,\t0 }\n+\t\t/*\n+\t\t * Please update $__git_log_pretty_formats in\n+\t\t * git-completion.bash when you add new formats.\n+\t\t */\n \t};\n \tcommit_formats_len = ARRAY_SIZE(builtin_formats);\n \tbuiltin_formats_len = commit_formats_len;\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 422a9c9ae3..cf80d4d69b 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -485,6 +485,10 @@ static struct {\n \t{ \"if\", SOURCE_NONE, FIELD_STR, if_atom_parser },\n \t{ \"then\", SOURCE_NONE },\n \t{ \"else\", SOURCE_NONE },\n+\t/*\n+\t * Please update $__git_ref_fieldlist in git-completion.bash\n+\t * when you add new atoms\n+\t */\n };\n \n #define REF_FORMATTING_STATE_INIT  { 0, NULL }\ndiff --git a/submodule-config.c b/submodule-config.c\nindex 52702c62d9..66653e86b9 100644\n--- a/submodule-config.c\n+++ b/submodule-config.c\n@@ -281,7 +281,10 @@ static int parse_fetch_recurse(const char *opt, const char *arg,\n \tdefault:\n \t\tif (!strcmp(arg, \"on-demand\"))\n \t\t\treturn RECURSE_SUBMODULES_ON_DEMAND;\n-\n+\t\t/*\n+\t\t * Please update $__git_fetch_recurse_submodules in\n+\t\t * git-completion.bash when you add new options.\n+\t\t */\n \t\tif (die_on_error)\n \t\t\tdie(\"bad %s argument: %s\", opt, arg);\n \t\telse\n@@ -362,6 +365,10 @@ static int parse_push_recurse(const char *opt, const char *arg,\n \t\t\treturn RECURSE_SUBMODULES_CHECK;\n \t\telse if (!strcmp(arg, \"only\"))\n \t\t\treturn RECURSE_SUBMODULES_ONLY;\n+\t\t/*\n+\t\t * Please update $__git_push_recurse_submodules in\n+\t\t * git-completion.bash when you add new modes.\n+\t\t */\n \t\telse if (die_on_error)\n \t\t\tdie(\"bad %s argument: %s\", opt, arg);\n \t\telse\ndiff --git a/submodule.c b/submodule.c\nindex 934ecfa294..b251a81f8e 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -432,6 +432,10 @@ void handle_ignore_submodules_arg(struct diff_options *diffopt,\n \t\tdiffopt->flags.ignore_dirty_submodules = 1;\n \telse if (strcmp(arg, \"none\"))\n \t\tdie(\"bad --ignore-submodules argument: %s\", arg);\n+\t/*\n+\t * Please update _git_status() in git-completion.bash when you\n+\t * add new options\n+\t */\n }\n \n static int prepare_submodule_summary(struct rev_info *rev, const char *path,\ndiff --git a/xdiff-interface.c b/xdiff-interface.c\nindex 80f060d278..8509f9ea22 100644\n--- a/xdiff-interface.c\n+++ b/xdiff-interface.c\n@@ -306,6 +306,10 @@ int git_xmerge_config(const char *var, const char *value, void *cb)\n \t\t\tgit_xmerge_style = XDL_MERGE_DIFF3;\n \t\telse if (!strcmp(value, \"merge\"))\n \t\t\tgit_xmerge_style = 0;\n+\t\t/*\n+\t\t * Please update _git_checkout() in\n+\t\t * git-completion.bash when you add new merge config\n+\t\t */\n \t\telse\n \t\t\tdie(\"unknown style '%s' given for '%s'\",\n \t\t\t    value, var);\n-- \n2.21.0.rc0.328.g0e39304f8d\n\n"}]}