{"thread":{"id":"30204","subject":"[PATCH 0/2] Dynamic long options for bash completion","startedAt":"2012-04-11T10:29:23Z","lastAt":"2012-04-17T10:44:48Z","messageCount":14,"participants":["Stephen Boyd","Felipe Contreras","Jonathan Nieder","SZEDER Gábor","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"188937","messageId":"1334140165-24958-1-git-send-email-bebarino@gmail.com","threadId":"30204","inReplyTo":null,"subject":"[PATCH 0/2] Dynamic long options for bash completion","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2012-04-11T10:29:23Z","receivedAt":"2012-04-11T10:29:23Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"I've been meaning to do this for a while. I realize we gain some more\nlines but it seems better to just generate these lists automatically\ninstead of managing them by hand.\n\nStephen Boyd (2):\n  parse-options: Add support for dumping out long options\n  completion: Use parse-options raw output for simple long options\n\n contrib/completion/git-completion.bash |  298 +++++++++++++++++++-------------\n parse-options.c                        |   41 +++++\n 2 files changed, 217 insertions(+), 122 deletions(-)\n\n-- \n1.7.10.128.g7945c.dirty\n"},{"id":"188939","messageId":"1334140165-24958-2-git-send-email-bebarino@gmail.com","threadId":"30204","inReplyTo":"1334140165-24958-1-git-send-email-bebarino@gmail.com","subject":"[PATCH 1/2] parse-options: Add support for dumping out long options","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2012-04-11T10:29:24Z","receivedAt":"2012-04-11T10:29:24Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"The bash completion script wants to know what the long options are for a\ncertain command at runtime. Add a magical long option that nobody could\npossibly ever use (--dump-raw-long-options) to get this information.\n\nSome example output:\n\n $ git clone --dump-raw-long-options\n --no-verbose --no-quiet --progress --no-progress --no-checkout\n --checkout --bare --no-bare --mirror --no-mirror --local --no-local\n --no-hardlinks --hardlinks --shared --no-shared --recursive\n --no-recursive --recurse-submodules --no-recurse-submodules --template=\n --no-template --reference= --no-reference --origin= --no-origin\n --branch= --no-branch --upload-pack= --no-upload-pack --depth=\n --no-depth --single-branch --no-single-branch --separate-git-dir=\n --no-separate-git-dir --config= --no-config\n\nSigned-off-by: Stephen Boyd <bebarino@gmail.com>\n---\n\nThe name can be anything. This seemed sufficiently obscure.\n\n parse-options.c |   41 +++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 41 insertions(+)\n\ndiff --git a/parse-options.c b/parse-options.c\nindex 850cfa7..6c37497 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -364,6 +364,45 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *,\n \t\t\t\t       const char * const *,\n \t\t\t\t       const struct option *, int, int);\n \n+static int parse_options_raw(const struct option *opts)\n+{\n+\tfor (; opts->type != OPTION_END; opts++) {\n+\t\tif (opts->flags & PARSE_OPT_HIDDEN)\n+\t\t\tcontinue;\n+\t\tif (!opts->long_name)\n+\t\t\tcontinue;\n+\t\tswitch (opts->type) {\n+\t\tcase OPTION_BIT:\n+\t\tcase OPTION_NEGBIT:\n+\t\tcase OPTION_COUNTUP:\n+\t\tcase OPTION_SET_INT:\n+\t\tcase OPTION_SET_PTR:\n+\t\t\tfprintf(stdout, \"--%s \", opts->long_name);\n+\t\t\tbreak;\n+\t\tcase OPTION_LOWLEVEL_CALLBACK:\n+\t\tcase OPTION_STRING:\n+\t\tcase OPTION_FILENAME:\n+\t\tcase OPTION_INTEGER:\n+\t\tcase OPTION_CALLBACK:\n+\t\t\tif (opts->flags & PARSE_OPT_OPTARG)\n+\t\t\t\tfprintf(stdout, \"--%s \", opts->long_name);\n+\t\t\telse if (!(opts->flags & PARSE_OPT_NOARG))\n+\t\t\t\tfprintf(stdout, \"--%s= \", opts->long_name);\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tcontinue;\n+\t\t}\n+\t\tif (!(opts->flags & PARSE_OPT_NONEG)) {\n+\t\t\tif (!prefixcmp(opts->long_name, \"no-\"))\n+\t\t\t\tfprintf(stdout, \"--%s \", opts->long_name + 3);\n+\t\t\telse\n+\t\t\t\tfprintf(stdout, \"--no-%s \", opts->long_name);\n+\t\t}\n+\t}\n+\n+\treturn PARSE_OPT_HELP;\n+}\n+\n int parse_options_step(struct parse_opt_ctx_t *ctx,\n \t\t       const struct option *options,\n \t\t       const char * const usagestr[])\n@@ -431,6 +470,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,\n \t\t\treturn usage_with_options_internal(ctx, usagestr, options, 1, 0);\n \t\tif (internal_help && !strcmp(arg + 2, \"help\"))\n \t\t\treturn parse_options_usage(ctx, usagestr, options, 0);\n+\t\tif (!strcmp(arg + 2, \"dump-raw-long-options\"))\n+\t\t\treturn parse_options_raw(options);\n \t\tswitch (parse_long_opt(ctx, arg + 2, options)) {\n \t\tcase -1:\n \t\t\treturn parse_options_usage(ctx, usagestr, options, 1);\n-- \n1.7.10.128.g7945c.dirty\n"},{"id":"188938","messageId":"1334140165-24958-3-git-send-email-bebarino@gmail.com","threadId":"30204","inReplyTo":"1334140165-24958-1-git-send-email-bebarino@gmail.com","subject":"[PATCH 2/2] completion: Use parse-options raw output for simple long options","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2012-04-11T10:29:25Z","receivedAt":"2012-04-11T10:29:25Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"Now that parse-options supports generating lists of long options for any\nparse-optified git program we can remove the hand-coded lists in the\ncompletion script. Replace these lists with code to generate the lists\nlazily when a user tab completes that specific command. Unforunately,\ndoing lazy evalution takes more lines than before, but the benefit is we\nreduce the amount of trivial patches to update the script for new and/or\nremoved options. It also mildly encourages the migration of git commands\nto the parse-options API.\n\nSigned-off-by: Stephen Boyd <bebarino@gmail.com>\n---\n\nIs there some way to compute these lists with some magical function instead\nof duplicating that logic over and over?\n\n contrib/completion/git-completion.bash |  298 +++++++++++++++++++-------------\n 1 file changed, 176 insertions(+), 122 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 31f714d..69abbe5 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -917,6 +917,11 @@ __git_list_porcelain_commands ()\n \tdone\n }\n \n+__git_list_command_options ()\n+{\n+\tgit $@ --dump-raw-long-options\n+}\n+\n __git_porcelain_commands=\n __git_compute_porcelain_commands ()\n {\n@@ -1027,43 +1032,45 @@ _git_am ()\n \tCOMPREPLY=()\n }\n \n+__git_apply_options=\n _git_apply ()\n {\n+\ttest -n \"$__git_apply_options\" ||\n+\t__git_apply_options=$(__git_list_command_options apply)\n+\n \tcase \"$cur\" in\n \t--whitespace=*)\n \t\t__gitcomp \"$__git_whitespacelist\" \"\" \"${cur##--whitespace=}\"\n \t\treturn\n \t\t;;\n \t--*)\n-\t\t__gitcomp \"\n-\t\t\t--stat --numstat --summary --check --index\n-\t\t\t--cached --index-info --reverse --reject --unidiff-zero\n-\t\t\t--apply --no-add --exclude=\n-\t\t\t--ignore-whitespace --ignore-space-change\n-\t\t\t--whitespace= --inaccurate-eof --verbose\n-\t\t\t\"\n+\t\t__gitcomp \"$__git_apply_options\"\n \t\treturn\n \tesac\n \tCOMPREPLY=()\n }\n \n+__git_add_options=\n _git_add ()\n {\n \t__git_has_doubledash && return\n+\ttest -n \"$__git_add_options\" ||\n+\t__git_add_options=$(__git_list_command_options add)\n \n \tcase \"$cur\" in\n \t--*)\n-\t\t__gitcomp \"\n-\t\t\t--interactive --refresh --patch --update --dry-run\n-\t\t\t--ignore-errors --intent-to-add\n-\t\t\t\"\n+\t\t__gitcomp \"$__git_add_options\"\n \t\treturn\n \tesac\n \tCOMPREPLY=()\n }\n \n+__git_archive_options=\n _git_archive ()\n {\n+\ttest -n \"$__git_archive_options\" ||\n+\t__git_archive_options=$(__git_list_command_options archive)\n+\n \tcase \"$cur\" in\n \t--format=*)\n \t\t__gitcomp \"$(git archive --list)\" \"\" \"${cur##--format=}\"\n@@ -1074,10 +1081,7 @@ _git_archive ()\n \t\treturn\n \t\t;;\n \t--*)\n-\t\t__gitcomp \"\n-\t\t\t--format= --list --verbose\n-\t\t\t--prefix= --remote= --exec=\n-\t\t\t\"\n+\t\t__gitcomp \"$__git_archive_options\"\n \t\treturn\n \t\t;;\n \tesac\n@@ -1109,6 +1113,7 @@ _git_bisect ()\n \tesac\n }\n \n+__git_branch_options=\n _git_branch ()\n {\n \tlocal i c=1 only_local_ref=\"n\" has_r=\"n\"\n@@ -1122,13 +1127,12 @@ _git_branch ()\n \t\t((c++))\n \tdone\n \n+\ttest -n \"$__git_branch_options\" ||\n+\t__git_branch_options=$(__git_list_command_options branch)\n+\n \tcase \"$cur\" in\n \t--*)\n-\t\t__gitcomp \"\n-\t\t\t--color --no-color --verbose --abbrev= --no-abbrev\n-\t\t\t--track --no-track --contains --merged --no-merged\n-\t\t\t--set-upstream --edit-description --list\n-\t\t\t\"\n+\t\t__gitcomp \"$__git_branch_options\"\n \t\t;;\n \t*)\n \t\tif [ $only_local_ref = \"y\" -a $has_r = \"n\" ]; then\n@@ -1160,19 +1164,19 @@ _git_bundle ()\n \tesac\n }\n \n+__git_checkout_options=\n _git_checkout ()\n {\n \t__git_has_doubledash && return\n+\ttest -n \"$__git_checkout_options\" ||\n+\t__git_checkout_options=$(__git_list_command_options checkout)\n \n \tcase \"$cur\" in\n \t--conflict=*)\n \t\t__gitcomp \"diff3 merge\" \"\" \"${cur##--conflict=}\"\n \t\t;;\n \t--*)\n-\t\t__gitcomp \"\n-\t\t\t--quiet --ours --theirs --track --no-track --merge\n-\t\t\t--conflict= --orphan --patch\n-\t\t\t\"\n+\t\t__gitcomp \"$__git_checkout_options\"\n \t\t;;\n \t*)\n \t\t# check if --track, --no-track, or --no-guess was specified\n@@ -1191,11 +1195,15 @@ _git_cherry ()\n \t__gitcomp \"$(__git_refs)\"\n }\n \n+__git_cherry_pick_options=\n _git_cherry_pick ()\n {\n+\ttest -n \"$__git_cherry_pick_options\" ||\n+\t__git_cherry_pick_options=$(__git_list_command_options cherry-pick)\n+\n \tcase \"$cur\" in\n \t--*)\n-\t\t__gitcomp \"--edit --no-commit\"\n+\t\t__gitcomp \"$__git_cherry_pick_options\"\n \t\t;;\n \t*)\n \t\t__gitcomp_nl \"$(__git_refs)\"\n@@ -1203,46 +1211,44 @@ _git_cherry_pick ()\n \tesac\n }\n \n+__git_clean_options=\n _git_clean ()\n {\n \t__git_has_doubledash && return\n \n+\ttest -n \"$__git_clean_options\" ||\n+\t__git_clean_options=$(__git_list_command_options clean)\n+\n \tcase \"$cur\" in\n \t--*)\n-\t\t__gitcomp \"--dry-run --quiet\"\n+\t\t__gitcomp \"$__git_clean_options\"\n \t\treturn\n \t\t;;\n \tesac\n \tCOMPREPLY=()\n }\n \n+__git_clone_options=\n _git_clone ()\n {\n+\ttest -n \"$__git_clone_options\" ||\n+\t__git_clone_options=$(__git_list_command_options clone)\n+\n \tcase \"$cur\" in\n \t--*)\n-\t\t__gitcomp \"\n-\t\t\t--local\n-\t\t\t--no-hardlinks\n-\t\t\t--shared\n-\t\t\t--reference\n-\t\t\t--quiet\n-\t\t\t--no-checkout\n-\t\t\t--bare\n-\t\t\t--mirror\n-\t\t\t--origin\n-\t\t\t--upload-pack\n-\t\t\t--template=\n-\t\t\t--depth\n-\t\t\t\"\n+\t\t__gitcomp \"$__git_clone_options\"\n \t\treturn\n \t\t;;\n \tesac\n \tCOMPREPLY=()\n }\n \n+__git_commit_options=\n _git_commit ()\n {\n \t__git_has_doubledash && return\n+\ttest -n \"$__git_commit_options\" ||\n+\t__git_commit_options=$(__git_list_command_options commit)\n \n \tcase \"$cur\" in\n \t--cleanup=*)\n@@ -1260,27 +1266,21 @@ _git_commit ()\n \t\treturn\n \t\t;;\n \t--*)\n-\t\t__gitcomp \"\n-\t\t\t--all --author= --signoff --verify --no-verify\n-\t\t\t--edit --amend --include --only --interactive\n-\t\t\t--dry-run --reuse-message= --reedit-message=\n-\t\t\t--reset-author --file= --message= --template=\n-\t\t\t--cleanup= --untracked-files --untracked-files=\n-\t\t\t--verbose --quiet --fixup= --squash=\n-\t\t\t\"\n+\t\t__gitcomp \"$__git_commit_options\"\n \t\treturn\n \tesac\n \tCOMPREPLY=()\n }\n \n+__git_describe_options=\n _git_describe ()\n {\n+\ttest -n \"$__git_describe_options\" ||\n+\t__git_describe_options=$(__git_list_command_options describe)\n+\n \tcase \"$cur\" in\n \t--*)\n-\t\t__gitcomp \"\n-\t\t\t--all --tags --contains --abbrev= --candidates=\n-\t\t\t--exact-match --debug --long --match --always\n-\t\t\t\"\n+\t\t__gitcomp \"$__git_describe_options\"\n \t\treturn\n \tesac\n \t__gitcomp_nl \"$(__git_refs)\"\n@@ -1343,13 +1343,16 @@ _git_difftool ()\n \t__git_complete_file\n }\n \n-__git_fetch_options=\"\n-\t--quiet --verbose --append --upload-pack --force --keep --depth=\n-\t--tags --no-tags --all --prune --dry-run\n-\"\n+__git_fetch_options=\n+__git_compute_fetch_options ()\n+{\n+\ttest -n \"$__git_fetch_options\" ||\n+\t__git_fetch_options=$(__git_list_command_options fetch)\n+}\n \n _git_fetch ()\n {\n+\t__git_compute_fetch_options\n \tcase \"$cur\" in\n \t--*)\n \t\t__gitcomp \"$__git_fetch_options\"\n@@ -1359,8 +1362,12 @@ _git_fetch ()\n \t__git_complete_remote_or_refspec\n }\n \n+__git_format_patch_options=\n _git_format_patch ()\n {\n+\ttest -n \"$__git_format_patch_options\" ||\n+\t__git_format_patch_options=$(__git_list_command_options format-patch)\n+\n \tcase \"$cur\" in\n \t--thread=*)\n \t\t__gitcomp \"\n@@ -1369,46 +1376,37 @@ _git_format_patch ()\n \t\treturn\n \t\t;;\n \t--*)\n-\t\t__gitcomp \"\n-\t\t\t--stdout --attach --no-attach --thread --thread=\n-\t\t\t--output-directory\n-\t\t\t--numbered --start-number\n-\t\t\t--numbered-files\n-\t\t\t--keep-subject\n-\t\t\t--signoff --signature --no-signature\n-\t\t\t--in-reply-to= --cc=\n-\t\t\t--full-index --binary\n-\t\t\t--not --all\n-\t\t\t--cover-letter\n-\t\t\t--no-prefix --src-prefix= --dst-prefix=\n-\t\t\t--inline --suffix= --ignore-if-in-upstream\n-\t\t\t--subject-prefix=\n-\t\t\t\"\n+\t\t__gitcomp \"$__git_format_patch_options\"\n \t\treturn\n \t\t;;\n \tesac\n \t__git_complete_revlist\n }\n \n+__git_fsck_options=\n _git_fsck ()\n {\n+\ttest -n \"$__git_fsck_options\" ||\n+\t__git_fsck_options=$(__git_list_command_options fsck)\n+\n \tcase \"$cur\" in\n \t--*)\n-\t\t__gitcomp \"\n-\t\t\t--tags --root --unreachable --cache --no-reflogs --full\n-\t\t\t--strict --verbose --lost-found\n-\t\t\t\"\n+\t\t__gitcomp \"$__git_fsck_options\"\n \t\treturn\n \t\t;;\n \tesac\n \tCOMPREPLY=()\n }\n \n+__git_gc_options=\n _git_gc ()\n {\n+\ttest -n \"$__git_gc_options\" ||\n+\t__git_gc_options=$(__git_list_command_options gc)\n+\n \tcase \"$cur\" in\n \t--*)\n-\t\t__gitcomp \"--prune --aggressive\"\n+\t\t__gitcomp \"$__git_gc_options\"\n \t\treturn\n \t\t;;\n \tesac\n@@ -1424,24 +1422,17 @@ __git_match_ctag() {\n \tawk \"/^${1////\\\\/}/ { print \\$1 }\" \"$2\"\n }\n \n+__git_grep_options=\n _git_grep ()\n {\n \t__git_has_doubledash && return\n \n+\ttest -n \"$__git_grep_options\" ||\n+\t__git_grep_options=$(__git_list_command_options grep)\n+\n \tcase \"$cur\" in\n \t--*)\n-\t\t__gitcomp \"\n-\t\t\t--cached\n-\t\t\t--text --ignore-case --word-regexp --invert-match\n-\t\t\t--full-name --line-number\n-\t\t\t--extended-regexp --basic-regexp --fixed-strings\n-\t\t\t--perl-regexp\n-\t\t\t--files-with-matches --name-only\n-\t\t\t--files-without-match\n-\t\t\t--max-depth\n-\t\t\t--count\n-\t\t\t--and --or --not --all-match\n-\t\t\t\"\n+\t\t__gitcomp \"$__git_grep_options\"\n \t\treturn\n \t\t;;\n \tesac\n@@ -1458,11 +1449,15 @@ _git_grep ()\n \t__gitcomp_nl \"$(__git_refs)\"\n }\n \n+__git_help_options=\n _git_help ()\n {\n+\ttest -n \"$__git_help_options\" ||\n+\t__git_help_options=$(__git_list_command_options help)\n+\n \tcase \"$cur\" in\n \t--*)\n-\t\t__gitcomp \"--all --info --man --web\"\n+\t\t__gitcomp \"$__git_help_options\"\n \t\treturn\n \t\t;;\n \tesac\n@@ -1475,8 +1470,12 @@ _git_help ()\n \t\t\"\n }\n \n+__git_init_options=\n _git_init ()\n {\n+\ttest -n \"$__git_init_options\" ||\n+\t__git_init_options=$(__git_list_command_options init)\n+\n \tcase \"$cur\" in\n \t--shared=*)\n \t\t__gitcomp \"\n@@ -1485,26 +1484,24 @@ _git_init ()\n \t\treturn\n \t\t;;\n \t--*)\n-\t\t__gitcomp \"--quiet --bare --template= --shared --shared=\"\n+\t\t__gitcomp \"$__git_init_options\"\n \t\treturn\n \t\t;;\n \tesac\n \tCOMPREPLY=()\n }\n \n+__git_ls_files_options=\n _git_ls_files ()\n {\n \t__git_has_doubledash && return\n \n+\ttest -n \"$__git_ls_files_options\" ||\n+\t__git_ls_files_options=$(__git_list_command_options ls-files)\n+\n \tcase \"$cur\" in\n \t--*)\n-\t\t__gitcomp \"--cached --deleted --modified --others --ignored\n-\t\t\t--stage --directory --no-empty-directory --unmerged\n-\t\t\t--killed --exclude= --exclude-from=\n-\t\t\t--exclude-per-directory= --exclude-standard\n-\t\t\t--error-unmatch --with-tree= --full-name\n-\t\t\t--abbrev --ignored --exclude-per-directory\n-\t\t\t\"\n+\t\t__gitcomp \"$__git_ls_files_options\"\n \t\treturn\n \t\t;;\n \tesac\n@@ -1516,8 +1513,18 @@ _git_ls_remote ()\n \t__gitcomp_nl \"$(__git_remotes)\"\n }\n \n+__git_ls_tree_options=\n _git_ls_tree ()\n {\n+\ttest -n \"$__git_ls_tree_options\" ||\n+\t__git_ls_tree_options=$(__git_list_command_options ls-tree)\n+\n+\tcase \"$cur\" in\n+\t--*)\n+\t\t__gitcomp \"$__git_ls_tree_options\"\n+\t\treturn\n+\t\t;;\n+\tesac\n \t__git_complete_file\n }\n \n@@ -1595,14 +1602,17 @@ _git_log ()\n \t__git_complete_revlist\n }\n \n-__git_merge_options=\"\n-\t--no-commit --no-stat --log --no-log --squash --strategy\n-\t--commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit\n-\"\n+__git_merge_options=\n+__git_compute_merge_options ()\n+{\n+\ttest -n \"$__git_merge_options\" ||\n+\t__git_merge_options=$(__git_list_command_options merge)\n+}\n \n _git_merge ()\n {\n \t__git_complete_strategy && return\n+\t__git_compute_merge_options\n \n \tcase \"$cur\" in\n \t--*)\n@@ -1632,30 +1642,50 @@ _git_merge_base ()\n \t__gitcomp_nl \"$(__git_refs)\"\n }\n \n+__git_mv_options=\n _git_mv ()\n {\n+\ttest -n \"$__git_mv_options\" ||\n+\t__git_mv_options=$(__git_list_command_options mv)\n+\n \tcase \"$cur\" in\n \t--*)\n-\t\t__gitcomp \"--dry-run\"\n+\t\t__gitcomp \"$__git_mv_options\"\n \t\treturn\n \t\t;;\n \tesac\n \tCOMPREPLY=()\n }\n \n+__git_name_rev_options=\n _git_name_rev ()\n {\n-\t__gitcomp \"--tags --all --stdin\"\n+\ttest -n \"$__git_name_rev_options\" ||\n+\t__git_name_rev_options=$(__git_list_command_options name-rev)\n+\n+\tcase \"$cur\" in\n+\t--*)\n+\t\t__gitcomp \"$__git_name_rev_options\"\n+\t\treturn\n+\t\t;;\n+\tesac\n }\n \n+__git_notes_options=\n+__git_notes_add_options=\n+__git_notes_copy_options=\n+__git_notes_prune_options=\n _git_notes ()\n {\n \tlocal subcommands='add append copy edit list prune remove show'\n \tlocal subcommand=\"$(__git_find_on_cmdline \"$subcommands\")\"\n \n+\ttest -n \"$__git_notes_options\" ||\n+\t__git_notes_options=$(__git_list_command_options notes)\n+\n \tcase \"$subcommand,$cur\" in\n \t,--*)\n-\t\t__gitcomp '--ref'\n+\t\t__gitcomp \"$__git_notes_options\"\n \t\t;;\n \t,*)\n \t\tcase \"${words[cword-1]}\" in\n@@ -1672,14 +1702,19 @@ _git_notes ()\n \t\t__gitcomp_nl \"$(__git_refs)\" \"\" \"${cur#*=}\"\n \t\t;;\n \tadd,--*|append,--*)\n-\t\t__gitcomp '--file= --message= --reedit-message=\n-\t\t\t\t--reuse-message='\n+\t\ttest -n \"$__git_notes_add_options\" ||\n+\t\t__git_notes_add_options=$(__git_list_command_options notes add)\n+\t\t__gitcomp \"$__git_notes_add_options\"\n \t\t;;\n \tcopy,--*)\n-\t\t__gitcomp '--stdin'\n+\t\ttest -n \"$__git_notes_copy_options\" ||\n+\t\t__git_notes_copy_options=$(__git_list_command_options notes copy)\n+\t\t__gitcomp \"$__git_notes_copy_options\"\n \t\t;;\n \tprune,--*)\n-\t\t__gitcomp '--dry-run --verbose'\n+\t\ttest -n \"$__git_notes_prune_options\" ||\n+\t\t__git_notes_prune_options=$(__git_list_command_options notes prune)\n+\t\t__gitcomp \"$__git_notes_prune_options\"\n \t\t;;\n \tprune,*)\n \t\t;;\n@@ -1699,6 +1734,9 @@ _git_pull ()\n {\n \t__git_complete_strategy && return\n \n+\t__git_compute_merge_options\n+\t__git_compute_fetch_options\n+\n \tcase \"$cur\" in\n \t--*)\n \t\t__gitcomp \"\n@@ -1712,8 +1750,12 @@ _git_pull ()\n \t__git_complete_remote_or_refspec\n }\n \n+__git_push_options=\n _git_push ()\n {\n+\ttest -n \"$__git_push_options\" ||\n+\t__git_push_options=$(__git_list_command_options push)\n+\n \tcase \"$prev\" in\n \t--repo)\n \t\t__gitcomp_nl \"$(__git_remotes)\"\n@@ -1725,10 +1767,7 @@ _git_push ()\n \t\treturn\n \t\t;;\n \t--*)\n-\t\t__gitcomp \"\n-\t\t\t--all --mirror --tags --dry-run --force --verbose\n-\t\t\t--receive-pack= --repo= --set-upstream\n-\t\t\"\n+\t\t__gitcomp \"$__git_push_options\"\n \t\treturn\n \t\t;;\n \tesac\n@@ -2313,37 +2352,49 @@ _git_replace ()\n \t__gitcomp_nl \"$(__git_refs)\"\n }\n \n+__git_reset_options=\n _git_reset ()\n {\n \t__git_has_doubledash && return\n \n+\ttest -n \"$__git_reset_options\" ||\n+\t__git_reset_options=$(__git_list_command_options reset)\n+\n \tcase \"$cur\" in\n \t--*)\n-\t\t__gitcomp \"--merge --mixed --hard --soft --patch\"\n+\t\t__gitcomp \"$__git_reset_options\"\n \t\treturn\n \t\t;;\n \tesac\n \t__gitcomp_nl \"$(__git_refs)\"\n }\n \n+__git_revert_options=\n _git_revert ()\n {\n+\ttest -n \"$__git_revert_options\" ||\n+\t__git_revert_options=$(__git_list_command_options revert)\n+\n \tcase \"$cur\" in\n \t--*)\n-\t\t__gitcomp \"--edit --mainline --no-edit --no-commit --signoff\"\n+\t\t__gitcomp \"$__git_revert_options\"\n \t\treturn\n \t\t;;\n \tesac\n \t__gitcomp_nl \"$(__git_refs)\"\n }\n \n+__git_rm_options=\n _git_rm ()\n {\n \t__git_has_doubledash && return\n \n+\ttest -n \"$__git_rm_options\" ||\n+\t__git_rm_options=$(__git_list_command_options rm)\n+\n \tcase \"$cur\" in\n \t--*)\n-\t\t__gitcomp \"--cached --dry-run --ignore-unmatch --quiet\"\n+\t\t__gitcomp \"$__git_rm_options\"\n \t\treturn\n \t\t;;\n \tesac\n@@ -2367,10 +2418,14 @@ _git_shortlog ()\n \t__git_complete_revlist\n }\n \n+__git_show_options=\n _git_show ()\n {\n \t__git_has_doubledash && return\n \n+\ttest -n \"$__git_show_options\" ||\n+\t__git_show_options=$(__git_list_command_options show)\n+\n \tcase \"$cur\" in\n \t--pretty=*|--format=*)\n \t\t__gitcomp \"$__git_log_pretty_formats $(__git_pretty_aliases)\n@@ -2378,7 +2433,7 @@ _git_show ()\n \t\treturn\n \t\t;;\n \t--*)\n-\t\t__gitcomp \"--pretty= --format= --abbrev-commit --oneline\n+\t\t__gitcomp \"$__git_show_options\n \t\t\t$__git_diff_common_options\n \t\t\t\"\n \t\treturn\n@@ -2387,16 +2442,15 @@ _git_show ()\n \t__git_complete_file\n }\n \n+__git_show_branch_options=\n _git_show_branch ()\n {\n+\ttest -n \"$__git_show_branch_options\" ||\n+\t__git_show_branch_options=$(__git_list_command_options show-branch)\n+\n \tcase \"$cur\" in\n \t--*)\n-\t\t__gitcomp \"\n-\t\t\t--all --remotes --topo-order --current --more=\n-\t\t\t--list --independent --merge-base --no-name\n-\t\t\t--color --no-color\n-\t\t\t--sha1-name --sparse --topics --reflog\n-\t\t\t\"\n+\t\t__gitcomp \"$__git_show_branch_options\"\n \t\treturn\n \t\t;;\n \tesac\n-- \n1.7.10.128.g7945c.dirty\n"},{"id":"188941","messageId":"CAMP44s37wm2G0vSmtND83ghrjHHfbyCbsKEoaUew-YxE73T=6A@mail.gmail.com","threadId":"30204","inReplyTo":"1334140165-24958-2-git-send-email-bebarino@gmail.com","subject":"Re: [PATCH 1/2] parse-options: Add support for dumping out long options","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-04-11T10:51:43Z","receivedAt":"2012-04-11T10:51:43Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Wed, Apr 11, 2012 at 1:29 PM, Stephen Boyd <bebarino@gmail.com> wrote:\n> The bash completion script wants to know what the long options are for a\n> certain command at runtime. Add a magical long option that nobody could\n> possibly ever use (--dump-raw-long-options) to get this information.\n\nI thought about doing this, but I would like more than just dumping\nthe options. In zsh one can show more than just the options; each\noption can have a description.\n\nI was thinking on something like 'git help --raw'. We also need\nsomething like that to list all the plumbing commands, and options for\ncertain options, like merge strategies, and so on. Perhaps it would\neven make sense to have a new 'git raw-help' command.\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"188957","messageId":"20120411125921.GC3161@burratino","threadId":"30204","inReplyTo":"1334140165-24958-2-git-send-email-bebarino@gmail.com","subject":"Re: [PATCH 1/2] parse-options: Add support for dumping out long options","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2012-04-11T12:59:21Z","receivedAt":"2012-04-11T12:59:21Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Stephen Boyd wrote:\n\n> The bash completion script wants to know what the long options are for a\n> certain command at runtime. Add a magical long option that nobody could\n> possibly ever use (--dump-raw-long-options) to get this information.\n\nNeat.  Probably should be documented:\n\ndiff --git i/Documentation/gitcli.txt w/Documentation/gitcli.txt\nindex f734f97b..0de074ec 100644\n--- i/Documentation/gitcli.txt\n+++ w/Documentation/gitcli.txt\n@@ -96,6 +96,11 @@ usage: git describe [options] <committish>*\n \tare deprecated, and such options are hidden from the default usage. This\n \toption gives the full list of options.\n \n+--dump-raw-long-options::\n+\tprints a space-separated list of supported options, including\n+\tnegated `--no-<foo>` forms.  Long options taking an argument are\n+\tprinted with a trailing equal sign, as in \"`--depth=`\".\n+\n \n Negating options\n ~~~~~~~~~~~~~~~~\n"},{"id":"188958","messageId":"20120411130924.GD3161@burratino","threadId":"30204","inReplyTo":"1334140165-24958-3-git-send-email-bebarino@gmail.com","subject":"Re: [PATCH 2/2] completion: Use parse-options raw output for simple long options","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2012-04-11T13:09:24Z","receivedAt":"2012-04-11T13:09:24Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Stephen Boyd wrote:\n\n> Is there some way to compute these lists with some magical function instead\n> of duplicating that logic over and over?\n\nMaybe roughly like this.\n\n\tfor command in $porcelain\n\tdo\n\t\teval \"__git_${command//-/_}_options=\"\n\tdone\n\t__git_complete_for_command ()\n\t{\n\t\tlocal options\n\t\tlocal options_var=\"__git_${command//-/_}_options\"\n\n\t\teval \"options=\\$$options_var\"\n\t\tif test -z \"$options\"\n\t\tthen\n\t\t\teval \"$options_var=\\$(__git_list_command_options \\$command)\"\n\t\t\teval \"options=\\$$options_var\"\n\t\tfi\n\n\t\t...\n\t}\n\n\t_git () {\n\t\t...\n\t\t__git_complete_for_command \"$command\"\n\t}\n\nJonathan\n"},{"id":"188959","messageId":"20120411135614.GQ2289@goldbirke","threadId":"30204","inReplyTo":"1334140165-24958-3-git-send-email-bebarino@gmail.com","subject":"Re: [PATCH 2/2] completion: Use parse-options raw output for simple long options","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2012-04-11T13:56:14Z","receivedAt":"2012-04-11T13:56:14Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi,\n\n\nOn Wed, Apr 11, 2012 at 03:29:25AM -0700, Stephen Boyd wrote:\n> Now that parse-options supports generating lists of long options for any\n> parse-optified git program we can remove the hand-coded lists in the\n> completion script. Replace these lists with code to generate the lists\n> lazily when a user tab completes that specific command. Unforunately,\n> doing lazy evalution takes more lines than before, but the benefit is we\n> reduce the amount of trivial patches to update the script for new and/or\n> removed options. It also mildly encourages the migration of git commands\n> to the parse-options API.\n> \n> Signed-off-by: Stephen Boyd <bebarino@gmail.com>\n> ---\n> \n> Is there some way to compute these lists with some magical function instead\n> of duplicating that logic over and over?\n\nMaybe a function like this:\n\n__git_compute_command_options ()\n{\n        local varname=\"__git_${@//[ -]/_}_options\"\n        eval \"test -n \\\"\\$$varname\\\" || $varname=\\\"$(git $@ --dump-raw-long-options)\\\"\"\n}\n\nAnd then in each completion function just need to call this function\nwith the command (and possibly subcommand) as parameter:\n\n__git_compute_command_options add\n\n\nBest,\nGábor\n"},{"id":"188960","messageId":"20120411140651.GR2289@goldbirke","threadId":"30204","inReplyTo":"1334140165-24958-2-git-send-email-bebarino@gmail.com","subject":"Re: [PATCH 1/2] parse-options: Add support for dumping out long options","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2012-04-11T14:06:51Z","receivedAt":"2012-04-11T14:06:51Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi,\n\n\nOn Wed, Apr 11, 2012 at 03:29:24AM -0700, Stephen Boyd wrote:\n> The bash completion script wants to know what the long options are for a\n> certain command at runtime. Add a magical long option that nobody could\n> possibly ever use (--dump-raw-long-options) to get this information.\n> \n> Some example output:\n> \n>  $ git clone --dump-raw-long-options\n>  --no-verbose --no-quiet --progress --no-progress --no-checkout\n>  --checkout --bare --no-bare --mirror --no-mirror --local --no-local\n>  --no-hardlinks --hardlinks --shared --no-shared --recursive\n>  --no-recursive --recurse-submodules --no-recurse-submodules --template=\n>  --no-template --reference= --no-reference --origin= --no-origin\n>  --branch= --no-branch --upload-pack= --no-upload-pack --depth=\n>  --no-depth --single-branch --no-single-branch --separate-git-dir=\n>  --no-separate-git-dir --config= --no-config\n> \n\nI think this is a good idea; there are many completion functions that\nfell behind and lack an option or two.\n\nHowever, in the completion script we deliberately miss options like\n'--force', but with your series such options will be offered, too.\n\n\nBest,\nGábor\n"},{"id":"189081","messageId":"4F867E04.8000501@gmail.com","threadId":"30204","inReplyTo":"20120411125921.GC3161@burratino","subject":"Re: [PATCH 1/2] parse-options: Add support for dumping out long options","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2012-04-12T07:02:28Z","receivedAt":"2012-04-12T07:02:28Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"On 04/11/2012 05:59 AM, Jonathan Nieder wrote:\n> Stephen Boyd wrote:\n> \n>> The bash completion script wants to know what the long options are for a\n>> certain command at runtime. Add a magical long option that nobody could\n>> possibly ever use (--dump-raw-long-options) to get this information.\n> \n> Neat.  Probably should be documented:\n> \n> diff --git i/Documentation/gitcli.txt w/Documentation/gitcli.txt\n> index f734f97b..0de074ec 100644\n> --- i/Documentation/gitcli.txt\n> +++ w/Documentation/gitcli.txt\n> @@ -96,6 +96,11 @@ usage: git describe [options] <committish>*\n>  \tare deprecated, and such options are hidden from the default usage. This\n>  \toption gives the full list of options.\n>  \n> +--dump-raw-long-options::\n> +\tprints a space-separated list of supported options, including\n> +\tnegated `--no-<foo>` forms.  Long options taking an argument are\n> +\tprinted with a trailing equal sign, as in \"`--depth=`\".\n> +\n>  \n>  Negating options\n>  ~~~~~~~~~~~~~~~~\n\nThanks. Squashed in.\n"},{"id":"189084","messageId":"4F868060.1000709@gmail.com","threadId":"30204","inReplyTo":"20120411140651.GR2289@goldbirke","subject":"Re: [PATCH 1/2] parse-options: Add support for dumping out long options","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2012-04-12T07:12:32Z","receivedAt":"2012-04-12T07:12:32Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"On 04/11/2012 07:06 AM, SZEDER Gábor wrote:\n> On Wed, Apr 11, 2012 at 03:29:24AM -0700, Stephen Boyd wrote:\n>> The bash completion script wants to know what the long options are for a\n>> certain command at runtime. Add a magical long option that nobody could\n>> possibly ever use (--dump-raw-long-options) to get this information.\n>>\n>> Some example output:\n>>\n>>  $ git clone --dump-raw-long-options\n>>  --no-verbose --no-quiet --progress --no-progress --no-checkout\n>>  --checkout --bare --no-bare --mirror --no-mirror --local --no-local\n>>  --no-hardlinks --hardlinks --shared --no-shared --recursive\n>>  --no-recursive --recurse-submodules --no-recurse-submodules --template=\n>>  --no-template --reference= --no-reference --origin= --no-origin\n>>  --branch= --no-branch --upload-pack= --no-upload-pack --depth=\n>>  --no-depth --single-branch --no-single-branch --separate-git-dir=\n>>  --no-separate-git-dir --config= --no-config\n>>\n> \n> I think this is a good idea; there are many completion functions that\n> fell behind and lack an option or two.\n> \n> However, in the completion script we deliberately miss options like\n> '--force', but with your series such options will be offered, too.\n> \n\nHm.. I meant to say something about that in the commit text. I'm willing\nto live with wading through some more options when I tab complete if it\nmeans the script never falls out of date with my git installation.\n\nI can envision us putting more smarts into the parse options code to\nhide certain options from the raw dump but I'm not sure how useful that\nis. Do we need that?\n"},{"id":"189085","messageId":"4F86877A.9020703@gmail.com","threadId":"30204","inReplyTo":"CAMP44s37wm2G0vSmtND83ghrjHHfbyCbsKEoaUew-YxE73T=6A@mail.gmail.com","subject":"Re: [PATCH 1/2] parse-options: Add support for dumping out long options","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2012-04-12T07:42:50Z","receivedAt":"2012-04-12T07:42:50Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"On 04/11/2012 03:51 AM, Felipe Contreras wrote:\n> On Wed, Apr 11, 2012 at 1:29 PM, Stephen Boyd <bebarino@gmail.com> wrote:\n>> The bash completion script wants to know what the long options are for a\n>> certain command at runtime. Add a magical long option that nobody could\n>> possibly ever use (--dump-raw-long-options) to get this information.\n> \n> I thought about doing this, but I would like more than just dumping\n> the options. In zsh one can show more than just the options; each\n> option can have a description.\n\nCool. I don't use zsh but it sounds interesting. Perhaps the magical\nlong option should grow an optional argument? i.e.\n\n\t--dump-raw-long-option=zsh\n\nwhich would dump the options in a format that zsh would like?\n\nAlternatively, we can make a tiny option description grammar that's\neasily parsed. I probably won't have time for this any time soon though.\n\n> \n> I was thinking on something like 'git help --raw'. We also need\n> something like that to list all the plumbing commands, and options for\n> certain options, like merge strategies, and so on. Perhaps it would\n> even make sense to have a new 'git raw-help' command.\n> \n\nI'd like to avoid tying the long option stuff to git help so that other\nusers of parse-options besides git (perhaps perf?) get the dumping\nsupport for free. Actually it works well for 'git notes <subcommand>'\nright now so it probably has to stay tied to each git command. Plus I\nthink we've covered merge strategies and command lists already so I\ndon't know how useful 'git help --raw' would be.\n\nI have been pondering ways to get all the possible config keys\ndynamically. That would remove a huge list (~2000 lines) in the\ncompletion script that always needs updating. Doing that would probably\nrequire some sort of grep over all the source files and a special key\ncomparison function to look for (#define CONFIG_MATCH strcmp might\nwork). Even then I don't know how we would handle color.branch.* and\nsimilar things. Maybe we would just do those by hand.\n"},{"id":"189335","messageId":"20120415124919.GD2900@goldbirke","threadId":"30204","inReplyTo":"4F868060.1000709@gmail.com","subject":"Re: [PATCH 1/2] parse-options: Add support for dumping out long options","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2012-04-15T12:49:19Z","receivedAt":"2012-04-15T12:49:19Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi,\n\n\nOn Thu, Apr 12, 2012 at 12:12:32AM -0700, Stephen Boyd wrote:\n> On 04/11/2012 07:06 AM, SZEDER Gábor wrote:\n> > On Wed, Apr 11, 2012 at 03:29:24AM -0700, Stephen Boyd wrote:\n> >> The bash completion script wants to know what the long options are for a\n> >> certain command at runtime. Add a magical long option that nobody could\n> >> possibly ever use (--dump-raw-long-options) to get this information.\n> >>\n> >> Some example output:\n> >>\n> >>  $ git clone --dump-raw-long-options\n> >>  --no-verbose --no-quiet --progress --no-progress --no-checkout\n> >>  --checkout --bare --no-bare --mirror --no-mirror --local --no-local\n> >>  --no-hardlinks --hardlinks --shared --no-shared --recursive\n> >>  --no-recursive --recurse-submodules --no-recurse-submodules --template=\n> >>  --no-template --reference= --no-reference --origin= --no-origin\n> >>  --branch= --no-branch --upload-pack= --no-upload-pack --depth=\n> >>  --no-depth --single-branch --no-single-branch --separate-git-dir=\n> >>  --no-separate-git-dir --config= --no-config\n> >>\n> > \n> > I think this is a good idea; there are many completion functions that\n> > fell behind and lack an option or two.\n> > \n> > However, in the completion script we deliberately miss options like\n> > '--force', but with your series such options will be offered, too.\n> > \n> \n> Hm.. I meant to say something about that in the commit text. I'm willing\n> to live with wading through some more options when I tab complete if it\n> means the script never falls out of date with my git installation.\n> \n> I can envision us putting more smarts into the parse options code to\n> hide certain options from the raw dump but I'm not sure how useful that\n> is. Do we need that?\n\nIt's not just about wading through some more options.\n\nParse options already has the PARSE_OPT_HIDDEN flag to omit an option\nfrom the default usage.  Your patch already respects that option, so\ne.g. 'git commit --<TAB>' won't offer '--allow-empty', which is meant\nfor foreign SCM interface scripts.  This is good.\n\nHowever, '--force' is different, because it should be shown in the\ndefault usage, but since it's a \"dangerous\" option it should be use\nwith great care.  That's the reason the completion script doesn't\noffer it for any of the commands.\n\nI'm not sure whether there are any such options besides '--force',\nthough.  If that is the only one, then maybe this is all we need:\n\n\ndiff --git a/parse-options.c b/parse-options.c\nindex 6c37497c..1a2b0328 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -371,6 +371,8 @@ static int parse_options_raw(const struct option *opts)\n \t\t\tcontinue;\n \t\tif (!opts->long_name)\n \t\t\tcontinue;\n+\t\tif (!strcmp(opts->long_name, \"force\"))\n+\t\t\tcontinue;\n \t\tswitch (opts->type) {\n \t\tcase OPTION_BIT:\n \t\tcase OPTION_NEGBIT:\n\n\nBest,\nGábor\n"},{"id":"189345","messageId":"7v39842416.fsf@alter.siamese.dyndns.org","threadId":"30204","inReplyTo":"20120415124919.GD2900@goldbirke","subject":"Re: [PATCH 1/2] parse-options: Add support for dumping out long options","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-04-15T19:23:01Z","receivedAt":"2012-04-15T19:23:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"SZEDER Gábor <szeder@ira.uka.de> writes:\n\n> Parse options already has the PARSE_OPT_HIDDEN flag to omit an option\n> from the default usage.  Your patch already respects that option, so\n> e.g. 'git commit --<TAB>' won't offer '--allow-empty', which is meant\n> for foreign SCM interface scripts.  This is good.\n>\n> However, '--force' is different,...\n\nDon't we have enough bits in PARSE_OPT_* namespace so that we can spare\none for PARSE_OPT_OMIT_FROM_COMPLETION?\n"},{"id":"189516","messageId":"20120417104448.GE2299@goldbirke","threadId":"30204","inReplyTo":"1334140165-24958-3-git-send-email-bebarino@gmail.com","subject":"Re: [PATCH 2/2] completion: Use parse-options raw output for simple long options","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2012-04-17T10:44:48Z","receivedAt":"2012-04-17T10:44:48Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi Stephen,\n\nOn Wed, Apr 11, 2012 at 03:29:25AM -0700, Stephen Boyd wrote:\n> Now that parse-options supports generating lists of long options for any\n> parse-optified git program we can remove the hand-coded lists in the\n> completion script. Replace these lists with code to generate the lists\n> lazily when a user tab completes that specific command.\n\n> +__git_list_command_options ()\n> +{\n> +\tgit $@ --dump-raw-long-options\n> +}\n\nAttempting option completion for the first time for commands requiring\na repository to work (e.g. 'add', 'branch', 'checkout', etc.) outside\nof a git repository produces a 'fatal: not a git repository' error.\nThese commands require a repository for '--dump-raw-long-options',\ntoo, otherwise they error out in __git_list_command_options().  So at\nleast we'll need\n\n  git $@ --dump-raw-long-options 2> /dev/null\n\nto silence that error, but even then the user won't get any options.\nNow, I don't think that getting a list of options is that useful at\nthat point, because the command will error out anyway (except when the\nuser explicitly specifies the paths to the repo and work tree), but\nit's a side effect nonetheless, because it worked before.\n\nComputing the long options for commands not requiring a repository\n(e.g. 'clone', 'archive', 'help', etc.) works properly even for the\nfirst time and outside of a repository.\n\n\nBest,\nGábor\n"}]}