{"thread":{"id":"39440","subject":"[PATCH 2/2] completion: use new 'git config' options to reliably list variable names","startedAt":"2015-05-27T20:07:19Z","lastAt":"2015-05-29T11:39:43Z","messageCount":17,"participants":["SZEDER Gábor","Jeff King","Junio C Hamano","Christian Couder"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"262258","messageId":"1432757240-4445-1-git-send-email-szeder@ira.uka.de","threadId":"39440","inReplyTo":null,"subject":"[PATCH 1/2] config: add options to list only variable names","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2015-05-27T20:07:19Z","receivedAt":"2015-05-27T20:07:19Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Recenty I created a multi-line branch description with '.' and '='\ncharacters on one of the lines, and noticed that fragments of that line\nshow up when completing set variable names for 'git config', e.g.:\n\n  $ git config --get branch.b.description\n  Branch description to fool the completion script with a\n  second line containing dot . and equals = characters.\n  $ git config --unset <TAB>\n  ...\n  second line containing dot . and equals\n  ...\n\nThe completion script runs 'git config --list' and processes its output to\nstrip the values and keep only the variable names.  It does so by looking\nfor lines containing '.' and '=' and outputting everything before the '=',\nwhich was fooled by my multi-line branch description.\n\nA similar issue exists with aliases and pretty format aliases with\nmulti-line values, but in that case 'git config --get-regexp' is run and\nsubsequent lines don't have to contain either '.' or '=' to fool the\ncompletion script.\n\nThough 'git config' can produce null-terminated output for newline-safe\nparsing, that's of no use in this case, becase we can't cope with nulls in\nthe shell.\n\nHelp the completion script by introducing the '--list-names' and\n'--get-names-regexp' options, the \"names-only\" equivalents of '--list' and\n'--get-regexp', so it doesn't have to separate variable names from their\nvalues anymore.\n\nSigned-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\n Documentation/git-config.txt           | 10 +++++++++-\n builtin/config.c                       | 22 ++++++++++++++++++----\n contrib/completion/git-completion.bash |  4 ++--\n t/t1300-repo-config.sh                 | 22 ++++++++++++++++++++++\n 4 files changed, 51 insertions(+), 7 deletions(-)\n\ndiff --git a/Documentation/git-config.txt b/Documentation/git-config.txt\nindex 02ec096..e0d27d5 100644\n--- a/Documentation/git-config.txt\n+++ b/Documentation/git-config.txt\n@@ -16,11 +16,12 @@ SYNOPSIS\n 'git config' [<file-option>] [type] [-z|--null] --get-all name [value_regex]\n 'git config' [<file-option>] [type] [-z|--null] --get-regexp name_regex [value_regex]\n 'git config' [<file-option>] [type] [-z|--null] --get-urlmatch name URL\n+'git config' [<file-option>] [-z|--null] --get-name-regexp name_regex\n 'git config' [<file-option>] --unset name [value_regex]\n 'git config' [<file-option>] --unset-all name [value_regex]\n 'git config' [<file-option>] --rename-section old_name new_name\n 'git config' [<file-option>] --remove-section name\n-'git config' [<file-option>] [-z|--null] -l | --list\n+'git config' [<file-option>] [-z|--null] -l | --list | --list-name\n 'git config' [<file-option>] --get-color name [default]\n 'git config' [<file-option>] --get-colorbool name [stdout-is-tty]\n 'git config' [<file-option>] -e | --edit\n@@ -96,6 +97,10 @@ OPTIONS\n \tin which section and variable names are lowercased, but subsection\n \tnames are not.\n \n+--get-name-regexp::\n+\tLike --get-regexp, but shows only matching variable names, not its\n+\tvalues.\n+\n --get-urlmatch name URL::\n \tWhen given a two-part name section.key, the value for\n \tsection.<url>.key whose <url> part matches the best to the\n@@ -161,6 +166,9 @@ See also <<FILES>>.\n --list::\n \tList all variables set in config file.\n \n+--list-name::\n+\tList the names of all variables set in config file.\n+\n --bool::\n \t'git config' will ensure that the output is \"true\" or \"false\"\n \ndiff --git a/builtin/config.c b/builtin/config.c\nindex 7188405..38bcf83 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -13,6 +13,7 @@ static char *key;\n static regex_t *key_regexp;\n static regex_t *regexp;\n static int show_keys;\n+static int show_only_keys;\n static int use_key_regexp;\n static int do_all;\n static int do_not_match;\n@@ -43,6 +44,8 @@ static int respect_includes = -1;\n #define ACTION_GET_COLOR (1<<13)\n #define ACTION_GET_COLORBOOL (1<<14)\n #define ACTION_GET_URLMATCH (1<<15)\n+#define ACTION_LIST_NAMES (1<<16)\n+#define ACTION_GET_NAME_REGEXP (1<<17)\n \n #define TYPE_BOOL (1<<0)\n #define TYPE_INT (1<<1)\n@@ -60,6 +63,7 @@ static struct option builtin_config_options[] = {\n \tOPT_BIT(0, \"get\", &actions, N_(\"get value: name [value-regex]\"), ACTION_GET),\n \tOPT_BIT(0, \"get-all\", &actions, N_(\"get all values: key [value-regex]\"), ACTION_GET_ALL),\n \tOPT_BIT(0, \"get-regexp\", &actions, N_(\"get values for regexp: name-regex [value-regex]\"), ACTION_GET_REGEXP),\n+\tOPT_BIT(0, \"get-name-regexp\", &actions, N_(\"get names for regexp: name-regex\"), ACTION_GET_NAME_REGEXP),\n \tOPT_BIT(0, \"get-urlmatch\", &actions, N_(\"get value specific for the URL: section[.var] URL\"), ACTION_GET_URLMATCH),\n \tOPT_BIT(0, \"replace-all\", &actions, N_(\"replace all matching variables: name value [value_regex]\"), ACTION_REPLACE_ALL),\n \tOPT_BIT(0, \"add\", &actions, N_(\"add a new variable: name value\"), ACTION_ADD),\n@@ -68,6 +72,7 @@ static struct option builtin_config_options[] = {\n \tOPT_BIT(0, \"rename-section\", &actions, N_(\"rename section: old-name new-name\"), ACTION_RENAME_SECTION),\n \tOPT_BIT(0, \"remove-section\", &actions, N_(\"remove a section: name\"), ACTION_REMOVE_SECTION),\n \tOPT_BIT('l', \"list\", &actions, N_(\"list all\"), ACTION_LIST),\n+\tOPT_BIT(0, \"list-names\", &actions, N_(\"list all variable names\"), ACTION_LIST_NAMES),\n \tOPT_BIT('e', \"edit\", &actions, N_(\"open an editor\"), ACTION_EDIT),\n \tOPT_BIT(0, \"get-color\", &actions, N_(\"find the color configured: slot [default]\"), ACTION_GET_COLOR),\n \tOPT_BIT(0, \"get-colorbool\", &actions, N_(\"find the color setting: slot [stdout-is-tty]\"), ACTION_GET_COLORBOOL),\n@@ -91,7 +96,7 @@ static void check_argc(int argc, int min, int max) {\n \n static int show_all_config(const char *key_, const char *value_, void *cb)\n {\n-\tif (value_)\n+\tif (!show_only_keys && value_)\n \t\tprintf(\"%s%c%s%c\", key_, delim, value_, term);\n \telse\n \t\tprintf(\"%s%c\", key_, term);\n@@ -165,7 +170,14 @@ static int collect_config(const char *key_, const char *value_, void *cb)\n \n \tALLOC_GROW(values->items, values->nr + 1, values->alloc);\n \n-\treturn format_config(&values->items[values->nr++], key_, value_);\n+\tif (show_only_keys) {\n+\t\tstruct strbuf *buf = &values->items[values->nr++];\n+\t\tstrbuf_init(buf, 0);\n+\t\tstrbuf_addstr(buf, key_);\n+\t\tstrbuf_addch(buf, term);\n+\t\treturn 0;\n+\t} else\n+\t\treturn format_config(&values->items[values->nr++], key_, value_);\n }\n \n static int get_value(const char *key_, const char *regex_)\n@@ -550,7 +562,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n \t\t\tusage_with_options(builtin_config_usage, builtin_config_options);\n \t\t}\n \n-\tif (actions == ACTION_LIST) {\n+\tif (actions == ACTION_LIST || actions == ACTION_LIST_NAMES) {\n+\t\tshow_only_keys = (actions == ACTION_LIST_NAMES);\n \t\tcheck_argc(argc, 0, 0);\n \t\tif (git_config_with_options(show_all_config, NULL,\n \t\t\t\t\t    &given_config_source,\n@@ -631,8 +644,9 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n \t\tcheck_argc(argc, 1, 2);\n \t\treturn get_value(argv[0], argv[1]);\n \t}\n-\telse if (actions == ACTION_GET_REGEXP) {\n+\telse if (actions == ACTION_GET_REGEXP || actions == ACTION_GET_NAME_REGEXP) {\n \t\tshow_keys = 1;\n+\t\tshow_only_keys = (actions == ACTION_GET_NAME_REGEXP);\n \t\tuse_key_regexp = 1;\n \t\tdo_all = 1;\n \t\tcheck_argc(argc, 1, 2);\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex bfc74e9..6abbd56 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1883,8 +1883,8 @@ _git_config ()\n \t--*)\n \t\t__gitcomp \"\n \t\t\t--system --global --local --file=\n-\t\t\t--list --replace-all\n-\t\t\t--get --get-all --get-regexp\n+\t\t\t--list --list-names --replace-all\n+\t\t\t--get --get-all --get-regexp --get-name-regexp\n \t\t\t--add --unset --unset-all\n \t\t\t--remove-section --rename-section\n \t\t\t\"\ndiff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh\nindex 66dd286..fa83944 100755\n--- a/t/t1300-repo-config.sh\n+++ b/t/t1300-repo-config.sh\n@@ -353,6 +353,18 @@ test_expect_success '--list without repo produces empty output' '\n '\n \n cat > expect << EOF\n+beta.noindent\n+nextsection.nonewline\n+123456.a123\n+version.1.2.3eX.alpha\n+EOF\n+\n+test_expect_success 'working --list-names' '\n+\tgit config --list-names > output &&\n+\ttest_cmp expect output\n+'\n+\n+cat > expect << EOF\n beta.noindent sillyValue\n nextsection.nonewline wow2 for me\n EOF\n@@ -363,6 +375,16 @@ test_expect_success '--get-regexp' '\n '\n \n cat > expect << EOF\n+beta.noindent\n+nextsection.nonewline\n+EOF\n+\n+test_expect_success '--get-name-regexp' '\n+\tgit config --get-name-regexp in >output &&\n+\ttest_cmp expect output\n+'\n+\n+cat > expect << EOF\n wow2 for me\n wow4 for you\n EOF\n-- \n2.4.2.347.ge926c0d\n"},{"id":"262257","messageId":"1432757240-4445-2-git-send-email-szeder@ira.uka.de","threadId":"39440","inReplyTo":"1432757240-4445-1-git-send-email-szeder@ira.uka.de","subject":"[PATCH 2/2] completion: use new 'git config' options to reliably list variable names","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2015-05-27T20:07:20Z","receivedAt":"2015-05-27T20:07:20Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"List all set config variable names with 'git config --list-names' instead\nof '--list' post processing.  Similarly, use 'git config\n--get-name-regexp' instead of '--get-regexp' to get config variables in a\ngiven section.\n\nSigned-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\n contrib/completion/git-completion.bash | 15 +++------------\n 1 file changed, 3 insertions(+), 12 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 6abbd56..121aa31 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -744,9 +744,8 @@ __git_compute_porcelain_commands ()\n __git_get_config_variables ()\n {\n \tlocal section=\"$1\" i IFS=$'\\n'\n-\tfor i in $(git --git-dir=\"$(__gitdir)\" config --get-regexp \"^$section\\..*\" 2>/dev/null); do\n-\t\ti=\"${i#$section.}\"\n-\t\techo \"${i/ */}\"\n+\tfor i in $(git --git-dir=\"$(__gitdir)\" config --get-name-regexp \"^$section\\..*\" 2>/dev/null); do\n+\t\techo \"${i#$section.}\"\n \tdone\n }\n \n@@ -1774,15 +1773,7 @@ __git_config_get_set_variables ()\n \t\tc=$((--c))\n \tdone\n \n-\tgit --git-dir=\"$(__gitdir)\" config $config_file --list 2>/dev/null |\n-\twhile read -r line\n-\tdo\n-\t\tcase \"$line\" in\n-\t\t*.*=*)\n-\t\t\techo \"${line/=*/}\"\n-\t\t\t;;\n-\t\tesac\n-\tdone\n+\tgit --git-dir=\"$(__gitdir)\" config $config_file --list-names 2>/dev/null\n }\n \n _git_config ()\n-- \n2.4.2.347.ge926c0d\n"},{"id":"262261","messageId":"1432757503-5787-1-git-send-email-szeder@ira.uka.de","threadId":"39440","inReplyTo":"1432757240-4445-2-git-send-email-szeder@ira.uka.de","subject":"[PATCH 1.5/2] config: add options to list only variable names","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2015-05-27T20:11:43Z","receivedAt":"2015-05-27T20:11:43Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Recenty I created a multi-line branch description with '.' and '='\ncharacters on one of the lines, and noticed that fragments of that line\nshow up when completing set variable names for 'git config', e.g.:\n\n  $ git config --get branch.b.description\n  Branch description to fool the completion script with a\n  second line containing dot . and equals = characters.\n  $ git config --unset <TAB>\n  ...\n  second line containing dot . and equals\n  ...\n\nThe completion script runs 'git config --list' and processes its output to\nstrip the values and keep only the variable names.  It does so by looking\nfor lines containing '.' and '=' and outputting everything before the '=',\nwhich was fooled by my multi-line branch description.\n\nA similar issue exists with aliases and pretty format aliases with\nmulti-line values, but in that case 'git config --get-regexp' is run and\nsubsequent lines don't have to contain either '.' or '=' to fool the\ncompletion script.\n\nThough 'git config' can produce null-terminated output for newline-safe\nparsing, that's of no use in this case, becase we can't cope with nulls in\nthe shell.\n\nHelp the completion script by introducing the '--list-names' and\n'--get-names-regexp' options, the \"names-only\" equivalents of '--list' and\n'--get-regexp', so it doesn't have to separate variable names from their\nvalues anymore.\n\nSigned-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\nD'oh, misspelled the option in the docs...\n\n Documentation/git-config.txt           | 10 +++++++++-\n builtin/config.c                       | 22 ++++++++++++++++++----\n contrib/completion/git-completion.bash |  4 ++--\n t/t1300-repo-config.sh                 | 22 ++++++++++++++++++++++\n 4 files changed, 51 insertions(+), 7 deletions(-)\n\ndiff --git a/Documentation/git-config.txt b/Documentation/git-config.txt\nindex 02ec096faa..fd519f81d8 100644\n--- a/Documentation/git-config.txt\n+++ b/Documentation/git-config.txt\n@@ -16,11 +16,12 @@ SYNOPSIS\n 'git config' [<file-option>] [type] [-z|--null] --get-all name [value_regex]\n 'git config' [<file-option>] [type] [-z|--null] --get-regexp name_regex [value_regex]\n 'git config' [<file-option>] [type] [-z|--null] --get-urlmatch name URL\n+'git config' [<file-option>] [-z|--null] --get-name-regexp name_regex\n 'git config' [<file-option>] --unset name [value_regex]\n 'git config' [<file-option>] --unset-all name [value_regex]\n 'git config' [<file-option>] --rename-section old_name new_name\n 'git config' [<file-option>] --remove-section name\n-'git config' [<file-option>] [-z|--null] -l | --list\n+'git config' [<file-option>] [-z|--null] -l | --list | --list-names\n 'git config' [<file-option>] --get-color name [default]\n 'git config' [<file-option>] --get-colorbool name [stdout-is-tty]\n 'git config' [<file-option>] -e | --edit\n@@ -96,6 +97,10 @@ OPTIONS\n \tin which section and variable names are lowercased, but subsection\n \tnames are not.\n \n+--get-name-regexp::\n+\tLike --get-regexp, but shows only matching variable names, not its\n+\tvalues.\n+\n --get-urlmatch name URL::\n \tWhen given a two-part name section.key, the value for\n \tsection.<url>.key whose <url> part matches the best to the\n@@ -161,6 +166,9 @@ See also <<FILES>>.\n --list::\n \tList all variables set in config file.\n \n+--list-names::\n+\tList the names of all variables set in config file.\n+\n --bool::\n \t'git config' will ensure that the output is \"true\" or \"false\"\n \ndiff --git a/builtin/config.c b/builtin/config.c\nindex 7188405f7e..38bcf838c5 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -13,6 +13,7 @@ static char *key;\n static regex_t *key_regexp;\n static regex_t *regexp;\n static int show_keys;\n+static int show_only_keys;\n static int use_key_regexp;\n static int do_all;\n static int do_not_match;\n@@ -43,6 +44,8 @@ static int respect_includes = -1;\n #define ACTION_GET_COLOR (1<<13)\n #define ACTION_GET_COLORBOOL (1<<14)\n #define ACTION_GET_URLMATCH (1<<15)\n+#define ACTION_LIST_NAMES (1<<16)\n+#define ACTION_GET_NAME_REGEXP (1<<17)\n \n #define TYPE_BOOL (1<<0)\n #define TYPE_INT (1<<1)\n@@ -60,6 +63,7 @@ static struct option builtin_config_options[] = {\n \tOPT_BIT(0, \"get\", &actions, N_(\"get value: name [value-regex]\"), ACTION_GET),\n \tOPT_BIT(0, \"get-all\", &actions, N_(\"get all values: key [value-regex]\"), ACTION_GET_ALL),\n \tOPT_BIT(0, \"get-regexp\", &actions, N_(\"get values for regexp: name-regex [value-regex]\"), ACTION_GET_REGEXP),\n+\tOPT_BIT(0, \"get-name-regexp\", &actions, N_(\"get names for regexp: name-regex\"), ACTION_GET_NAME_REGEXP),\n \tOPT_BIT(0, \"get-urlmatch\", &actions, N_(\"get value specific for the URL: section[.var] URL\"), ACTION_GET_URLMATCH),\n \tOPT_BIT(0, \"replace-all\", &actions, N_(\"replace all matching variables: name value [value_regex]\"), ACTION_REPLACE_ALL),\n \tOPT_BIT(0, \"add\", &actions, N_(\"add a new variable: name value\"), ACTION_ADD),\n@@ -68,6 +72,7 @@ static struct option builtin_config_options[] = {\n \tOPT_BIT(0, \"rename-section\", &actions, N_(\"rename section: old-name new-name\"), ACTION_RENAME_SECTION),\n \tOPT_BIT(0, \"remove-section\", &actions, N_(\"remove a section: name\"), ACTION_REMOVE_SECTION),\n \tOPT_BIT('l', \"list\", &actions, N_(\"list all\"), ACTION_LIST),\n+\tOPT_BIT(0, \"list-names\", &actions, N_(\"list all variable names\"), ACTION_LIST_NAMES),\n \tOPT_BIT('e', \"edit\", &actions, N_(\"open an editor\"), ACTION_EDIT),\n \tOPT_BIT(0, \"get-color\", &actions, N_(\"find the color configured: slot [default]\"), ACTION_GET_COLOR),\n \tOPT_BIT(0, \"get-colorbool\", &actions, N_(\"find the color setting: slot [stdout-is-tty]\"), ACTION_GET_COLORBOOL),\n@@ -91,7 +96,7 @@ static void check_argc(int argc, int min, int max) {\n \n static int show_all_config(const char *key_, const char *value_, void *cb)\n {\n-\tif (value_)\n+\tif (!show_only_keys && value_)\n \t\tprintf(\"%s%c%s%c\", key_, delim, value_, term);\n \telse\n \t\tprintf(\"%s%c\", key_, term);\n@@ -165,7 +170,14 @@ static int collect_config(const char *key_, const char *value_, void *cb)\n \n \tALLOC_GROW(values->items, values->nr + 1, values->alloc);\n \n-\treturn format_config(&values->items[values->nr++], key_, value_);\n+\tif (show_only_keys) {\n+\t\tstruct strbuf *buf = &values->items[values->nr++];\n+\t\tstrbuf_init(buf, 0);\n+\t\tstrbuf_addstr(buf, key_);\n+\t\tstrbuf_addch(buf, term);\n+\t\treturn 0;\n+\t} else\n+\t\treturn format_config(&values->items[values->nr++], key_, value_);\n }\n \n static int get_value(const char *key_, const char *regex_)\n@@ -550,7 +562,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n \t\t\tusage_with_options(builtin_config_usage, builtin_config_options);\n \t\t}\n \n-\tif (actions == ACTION_LIST) {\n+\tif (actions == ACTION_LIST || actions == ACTION_LIST_NAMES) {\n+\t\tshow_only_keys = (actions == ACTION_LIST_NAMES);\n \t\tcheck_argc(argc, 0, 0);\n \t\tif (git_config_with_options(show_all_config, NULL,\n \t\t\t\t\t    &given_config_source,\n@@ -631,8 +644,9 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n \t\tcheck_argc(argc, 1, 2);\n \t\treturn get_value(argv[0], argv[1]);\n \t}\n-\telse if (actions == ACTION_GET_REGEXP) {\n+\telse if (actions == ACTION_GET_REGEXP || actions == ACTION_GET_NAME_REGEXP) {\n \t\tshow_keys = 1;\n+\t\tshow_only_keys = (actions == ACTION_GET_NAME_REGEXP);\n \t\tuse_key_regexp = 1;\n \t\tdo_all = 1;\n \t\tcheck_argc(argc, 1, 2);\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex bfc74e9d57..6abbd564b6 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1883,8 +1883,8 @@ _git_config ()\n \t--*)\n \t\t__gitcomp \"\n \t\t\t--system --global --local --file=\n-\t\t\t--list --replace-all\n-\t\t\t--get --get-all --get-regexp\n+\t\t\t--list --list-names --replace-all\n+\t\t\t--get --get-all --get-regexp --get-name-regexp\n \t\t\t--add --unset --unset-all\n \t\t\t--remove-section --rename-section\n \t\t\t\"\ndiff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh\nindex 66dd28644f..fa83944ad9 100755\n--- a/t/t1300-repo-config.sh\n+++ b/t/t1300-repo-config.sh\n@@ -353,6 +353,18 @@ test_expect_success '--list without repo produces empty output' '\n '\n \n cat > expect << EOF\n+beta.noindent\n+nextsection.nonewline\n+123456.a123\n+version.1.2.3eX.alpha\n+EOF\n+\n+test_expect_success 'working --list-names' '\n+\tgit config --list-names > output &&\n+\ttest_cmp expect output\n+'\n+\n+cat > expect << EOF\n beta.noindent sillyValue\n nextsection.nonewline wow2 for me\n EOF\n@@ -363,6 +375,16 @@ test_expect_success '--get-regexp' '\n '\n \n cat > expect << EOF\n+beta.noindent\n+nextsection.nonewline\n+EOF\n+\n+test_expect_success '--get-name-regexp' '\n+\tgit config --get-name-regexp in >output &&\n+\ttest_cmp expect output\n+'\n+\n+cat > expect << EOF\n wow2 for me\n wow4 for you\n EOF\n-- \n2.4.2.347.ge926c0d\n"},{"id":"262276","messageId":"20150527210438.GB22815@peff.net","threadId":"39440","inReplyTo":"1432757240-4445-1-git-send-email-szeder@ira.uka.de","subject":"Re: [PATCH 1/2] config: add options to list only variable names","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-05-27T21:04:38Z","receivedAt":"2015-05-27T21:04:38Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, May 27, 2015 at 10:07:19PM +0200, SZEDER Gábor wrote:\n\n> Help the completion script by introducing the '--list-names' and\n> '--get-names-regexp' options, the \"names-only\" equivalents of '--list' and\n> '--get-regexp', so it doesn't have to separate variable names from their\n> values anymore.\n\nThanks, this sounds like the best solution. It should be a tiny bit more\nefficient, too, though I doubt it matters much in practice.\n\n> -'git config' [<file-option>] [-z|--null] -l | --list\n> +'git config' [<file-option>] [-z|--null] -l | --list | --list-name\n\ns/list-name/&s/, to match the code (and your commit message).\n\n> @@ -161,6 +166,9 @@ See also <<FILES>>.\n>  --list::\n>  \tList all variables set in config file.\n>  \n> +--list-name::\n> +\tList the names of all variables set in config file.\n\nDitto here. Also, now that we have two similar modes, perhaps the\n\"--list\" description above should become:\n\n  List all variables set in config file, along with their values.\n\n> @@ -165,7 +170,14 @@ static int collect_config(const char *key_, const char *value_, void *cb)\n>  \n>  \tALLOC_GROW(values->items, values->nr + 1, values->alloc);\n>  \n> -\treturn format_config(&values->items[values->nr++], key_, value_);\n> +\tif (show_only_keys) {\n> +\t\tstruct strbuf *buf = &values->items[values->nr++];\n> +\t\tstrbuf_init(buf, 0);\n> +\t\tstrbuf_addstr(buf, key_);\n> +\t\tstrbuf_addch(buf, term);\n> +\t\treturn 0;\n> +\t} else\n> +\t\treturn format_config(&values->items[values->nr++], key_, value_);\n>  }\n\nMight it flow a little better to always enter format_config, and then\njust return early (before writing the value) when show_key_only is set?\n\n>  cat > expect << EOF\n> +beta.noindent\n> +nextsection.nonewline\n> +123456.a123\n> +version.1.2.3eX.alpha\n> +EOF\n> +\n> +test_expect_success 'working --list-names' '\n> +\tgit config --list-names > output &&\n> +\ttest_cmp expect output\n> +'\n> +\n> +cat > expect << EOF\n\nWe usually avoid the extra space after redirection operators. But we\nalso usually match existing code. I'm not sure which is more evil in\nthis case. ;)\n\n> +test_expect_success '--get-name-regexp' '\n> +\tgit config --get-name-regexp in >output &&\n> +\ttest_cmp expect output\n> +'\n\nThis one is the odd man out if you are following existing style,\nthough.\n\nThe rest of the patch looks good to me.\n\n-Peff\n"},{"id":"262277","messageId":"20150527210540.GC22815@peff.net","threadId":"39440","inReplyTo":"1432757240-4445-2-git-send-email-szeder@ira.uka.de","subject":"Re: [PATCH 2/2] completion: use new 'git config' options to reliably list variable names","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-05-27T21:05:40Z","receivedAt":"2015-05-27T21:05:40Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, May 27, 2015 at 10:07:20PM +0200, SZEDER Gábor wrote:\n\n> List all set config variable names with 'git config --list-names' instead\n> of '--list' post processing.  Similarly, use 'git config\n> --get-name-regexp' instead of '--get-regexp' to get config variables in a\n> given section.\n> \n> Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>\n> ---\n>  contrib/completion/git-completion.bash | 15 +++------------\n>  1 file changed, 3 insertions(+), 12 deletions(-)\n\nNice diffstat. The less hacky bash parsing we can do, the better.\n\n-Peff\n"},{"id":"262278","messageId":"20150527210826.GD22815@peff.net","threadId":"39440","inReplyTo":"20150527210438.GB22815@peff.net","subject":"Re: [PATCH 1/2] config: add options to list only variable names","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-05-27T21:08:26Z","receivedAt":"2015-05-27T21:08:26Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, May 27, 2015 at 05:04:38PM -0400, Jeff King wrote:\n\n> > -'git config' [<file-option>] [-z|--null] -l | --list\n> > +'git config' [<file-option>] [-z|--null] -l | --list | --list-name\n> \n> s/list-name/&s/, to match the code (and your commit message).\n\nDoh, just saw your \"1.5\".\n\nFWIW, I expected \"PATCH 1.5/2\" to be \"eh, I should have put this in\nbetween patches 1 and 2\". I expect a re-roll to be \"v1.5\" (or just\n\"v2\").\n\nThis was the only real error in the patch, so your 1.5 looks OK to me.\nThough I hope you will consider my other suggestions, too.\n\n-Peff\n"},{"id":"262281","messageId":"20150527233429.Horde.PBcL7R4evwj_kC7y78ZSIA2@webmail.informatik.kit.edu","threadId":"39440","inReplyTo":"20150527210438.GB22815@peff.net","subject":"Re: [PATCH 1/2] config: add options to list only variable names","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2015-05-27T21:34:29Z","receivedAt":"2015-05-27T21:34:29Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"\nQuoting Jeff King <peff@peff.net>:\n\n> On Wed, May 27, 2015 at 10:07:19PM +0200, SZEDER Gábor wrote:\n>\n>> Help the completion script by introducing the '--list-names' and\n>> '--get-names-regexp' options, the \"names-only\" equivalents of '--list' and\n>> '--get-regexp', so it doesn't have to separate variable names from their\n>> values anymore.\n>\n> Thanks, this sounds like the best solution. It should be a tiny bit more\n> efficient, too, though I doubt it matters much in practice.\n>\n>> -'git config' [<file-option>] [-z|--null] -l | --list\n>> +'git config' [<file-option>] [-z|--null] -l | --list | --list-name\n>\n> s/list-name/&s/, to match the code (and your commit message).\n\nAnd note how I added an extra 's' to the other option in the commit message!\n\n>>  cat > expect << EOF\n>> +beta.noindent\n>> +nextsection.nonewline\n>> +123456.a123\n>> +version.1.2.3eX.alpha\n>> +EOF\n>> +\n>> +test_expect_success 'working --list-names' '\n>> +\tgit config --list-names > output &&\n>> +\ttest_cmp expect output\n>> +'\n>> +\n>> +cat > expect << EOF\n>\n> We usually avoid the extra space after redirection operators. But we\n> also usually match existing code. I'm not sure which is more evil in\n> this case. ;)\n>\n>> +test_expect_success '--get-name-regexp' '\n>> +\tgit config --get-name-regexp in >output &&\n>> +\ttest_cmp expect output\n>> +'\n>\n> This one is the odd man out if you are following existing style,\n> though.\n\nHeh, in both cases I simply copied the existing \"name-less\" test, and  \nonly adjusted the expected output and the name of the option to test. :)\n\nWill reroll.\n\nGábor\n"},{"id":"262293","messageId":"xmqqd21lk6h2.fsf@gitster.dls.corp.google.com","threadId":"39440","inReplyTo":"1432757240-4445-1-git-send-email-szeder@ira.uka.de","subject":"Re: [PATCH 1/2] config: add options to list only variable names","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-27T22:20:41Z","receivedAt":"2015-05-27T22:20:41Z","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> diff --git a/builtin/config.c b/builtin/config.c\n> index 7188405..38bcf83 100644\n> --- a/builtin/config.c\n> +++ b/builtin/config.c\n> @@ -13,6 +13,7 @@ static char *key;\n>  static regex_t *key_regexp;\n>  static regex_t *regexp;\n>  static int show_keys;\n> +static int show_only_keys;\n\nIs it just me who thinks this is a strange phrase?  Somehow these\nwords do not roll well on my tongue.\n\nPerhaps \"static int omit_values\"?  Which would match what this part\ndoes pretty well:\n\n>  static int show_all_config(const char *key_, const char *value_, void *cb)\n>  {\n> -\tif (value_)\n> +\tif (!show_only_keys && value_)\n\nThat is, \"if not omitting values and there is a value, then do this\".\n\n> -\treturn format_config(&values->items[values->nr++], key_, value_);\n> +\tif (show_only_keys) {\n> +\t\tstruct strbuf *buf = &values->items[values->nr++];\n> +\t\tstrbuf_init(buf, 0);\n> +\t\tstrbuf_addstr(buf, key_);\n> +\t\tstrbuf_addch(buf, term);\n> +\t\treturn 0;\n\nxstrfmt()?\n"},{"id":"262320","messageId":"CAP8UFD32erihiEqkwaR6B09rEW7WJJ=Aq955KqErr3MdfQ3S_w@mail.gmail.com","threadId":"39440","inReplyTo":"1432757503-5787-1-git-send-email-szeder@ira.uka.de","subject":"Re: [PATCH 1.5/2] config: add options to list only variable names","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2015-05-28T12:06:40Z","receivedAt":"2015-05-28T12:06:40Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Wed, May 27, 2015 at 10:11 PM, SZEDER Gábor <szeder@ira.uka.de> wrote:\n> Recenty I created a multi-line branch description with '.' and '='\n> characters on one of the lines, and noticed that fragments of that line\n> show up when completing set variable names for 'git config', e.g.:\n>\n>   $ git config --get branch.b.description\n>   Branch description to fool the completion script with a\n>   second line containing dot . and equals = characters.\n>   $ git config --unset <TAB>\n>   ...\n>   second line containing dot . and equals\n>   ...\n>\n> The completion script runs 'git config --list' and processes its output to\n> strip the values and keep only the variable names.  It does so by looking\n> for lines containing '.' and '=' and outputting everything before the '=',\n> which was fooled by my multi-line branch description.\n>\n> A similar issue exists with aliases and pretty format aliases with\n> multi-line values, but in that case 'git config --get-regexp' is run and\n> subsequent lines don't have to contain either '.' or '=' to fool the\n> completion script.\n>\n> Though 'git config' can produce null-terminated output for newline-safe\n> parsing, that's of no use in this case, becase we can't cope with nulls in\n> the shell.\n>\n> Help the completion script by introducing the '--list-names' and\n> '--get-names-regexp' options, the \"names-only\" equivalents of '--list' and\n> '--get-regexp', so it doesn't have to separate variable names from their\n> values anymore.\n\nWhy don't you just add a '--name-only' option that can be used only\nwith '--list' and '--get-regexp'?\n\nLike:\n\n'git config' [<file-option>] [-z|--null] [--name-only] --get-regexp name_regex\n\nand\n\n'git config' [<file-option>] [-z|--null] [--name-only] -l | --list\n\n?\n\nIt seems to me that it would reduce the number of options, and later\nif we want to pass a format we could have maybe:\n\n'git config' [<file-option>] [-z|--null] [--name-only |\n--format=<format>] --get-regexp name_regex\n\nand\n\n'git config' [<file-option>] [-z|--null] [--name-only |\n--format=<format>] -l | --list\n\nThanks,\nChristian.\n"},{"id":"262324","messageId":"1432816175-18988-1-git-send-email-szeder@ira.uka.de","threadId":"39440","inReplyTo":"1432757240-4445-1-git-send-email-szeder@ira.uka.de","subject":"[PATCH v2 0/2] config: list only variable names for completion","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2015-05-28T12:29:33Z","receivedAt":"2015-05-28T12:29:33Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Fixed misspelled option names in docs and in commit message, incorporated\nPeff's suggestions, and renamed 'show_only_keys' to 'omit_values' in 1/2.\n\nOnly minor tweaking in 2/2's commit message.\n\nSZEDER Gábor (2):\n  config: add options to list only variable names\n  completion: use new 'git config' options to reliably list variable\n    names\n\n Documentation/git-config.txt           | 12 ++++++++++--\n builtin/config.c                       | 17 ++++++++++++++---\n contrib/completion/git-completion.bash | 19 +++++--------------\n t/t1300-repo-config.sh                 | 22 ++++++++++++++++++++++\n 4 files changed, 51 insertions(+), 19 deletions(-)\n\n-- \n2.4.2.349.g6883b65\n"},{"id":"262322","messageId":"1432816175-18988-2-git-send-email-szeder@ira.uka.de","threadId":"39440","inReplyTo":"1432816175-18988-1-git-send-email-szeder@ira.uka.de","subject":"[PATCH v2 1/2] config: add options to list only variable names","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2015-05-28T12:29:34Z","receivedAt":"2015-05-28T12:29:34Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Recenty I created a multi-line branch description with '.' and '='\ncharacters on one of the lines, and noticed that fragments of that line\nshow up when completing set variable names for 'git config', e.g.:\n\n  $ git config --get branch.b.description\n  Branch description to fool the completion script with a\n  second line containing dot . and equals = characters.\n  $ git config --unset <TAB>\n  ...\n  second line containing dot . and equals\n  ...\n\nThe completion script runs 'git config --list' and processes its output to\nstrip the values and keep only the variable names.  It does so by looking\nfor lines containing '.' and '=' and outputting everything before the '=',\nwhich was fooled by my multi-line branch description.\n\nA similar issue exists with aliases and pretty format aliases with\nmulti-line values, but in that case 'git config --get-regexp' is run and\nsubsequent lines don't have to contain either '.' or '=' to fool the\ncompletion script.\n\nThough 'git config' can produce null-terminated output for newline-safe\nparsing, that's of no use in this case, becase we can't cope with nulls in\nthe shell.\n\nHelp the completion script by introducing the '--list-names' and\n'--get-name-regexp' options, the \"names-only\" equivalents of '--list' and\n'--get-regexp', so it doesn't have to separate variable names from their\nvalues anymore.\n\nSigned-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\n Documentation/git-config.txt           | 12 ++++++++++--\n builtin/config.c                       | 17 ++++++++++++++---\n contrib/completion/git-completion.bash |  4 ++--\n t/t1300-repo-config.sh                 | 22 ++++++++++++++++++++++\n 4 files changed, 48 insertions(+), 7 deletions(-)\n\ndiff --git a/Documentation/git-config.txt b/Documentation/git-config.txt\nindex 02ec096faa..b69c8592ac 100644\n--- a/Documentation/git-config.txt\n+++ b/Documentation/git-config.txt\n@@ -16,11 +16,12 @@ SYNOPSIS\n 'git config' [<file-option>] [type] [-z|--null] --get-all name [value_regex]\n 'git config' [<file-option>] [type] [-z|--null] --get-regexp name_regex [value_regex]\n 'git config' [<file-option>] [type] [-z|--null] --get-urlmatch name URL\n+'git config' [<file-option>] [-z|--null] --get-name-regexp name_regex\n 'git config' [<file-option>] --unset name [value_regex]\n 'git config' [<file-option>] --unset-all name [value_regex]\n 'git config' [<file-option>] --rename-section old_name new_name\n 'git config' [<file-option>] --remove-section name\n-'git config' [<file-option>] [-z|--null] -l | --list\n+'git config' [<file-option>] [-z|--null] -l | --list | --list-names\n 'git config' [<file-option>] --get-color name [default]\n 'git config' [<file-option>] --get-colorbool name [stdout-is-tty]\n 'git config' [<file-option>] -e | --edit\n@@ -96,6 +97,10 @@ OPTIONS\n \tin which section and variable names are lowercased, but subsection\n \tnames are not.\n \n+--get-name-regexp::\n+\tLike --get-regexp, but shows only matching variable names, not its\n+\tvalues.\n+\n --get-urlmatch name URL::\n \tWhen given a two-part name section.key, the value for\n \tsection.<url>.key whose <url> part matches the best to the\n@@ -159,7 +164,10 @@ See also <<FILES>>.\n \n -l::\n --list::\n-\tList all variables set in config file.\n+\tList all variables set in config file, along with their values.\n+\n+--list-names::\n+\tList the names of all variables set in config file.\n \n --bool::\n \t'git config' will ensure that the output is \"true\" or \"false\"\ndiff --git a/builtin/config.c b/builtin/config.c\nindex 7188405f7e..c23f329b00 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -13,6 +13,7 @@ static char *key;\n static regex_t *key_regexp;\n static regex_t *regexp;\n static int show_keys;\n+static int omit_values;\n static int use_key_regexp;\n static int do_all;\n static int do_not_match;\n@@ -43,6 +44,8 @@ static int respect_includes = -1;\n #define ACTION_GET_COLOR (1<<13)\n #define ACTION_GET_COLORBOOL (1<<14)\n #define ACTION_GET_URLMATCH (1<<15)\n+#define ACTION_LIST_NAMES (1<<16)\n+#define ACTION_GET_NAME_REGEXP (1<<17)\n \n #define TYPE_BOOL (1<<0)\n #define TYPE_INT (1<<1)\n@@ -60,6 +63,7 @@ static struct option builtin_config_options[] = {\n \tOPT_BIT(0, \"get\", &actions, N_(\"get value: name [value-regex]\"), ACTION_GET),\n \tOPT_BIT(0, \"get-all\", &actions, N_(\"get all values: key [value-regex]\"), ACTION_GET_ALL),\n \tOPT_BIT(0, \"get-regexp\", &actions, N_(\"get values for regexp: name-regex [value-regex]\"), ACTION_GET_REGEXP),\n+\tOPT_BIT(0, \"get-name-regexp\", &actions, N_(\"get names for regexp: name-regex\"), ACTION_GET_NAME_REGEXP),\n \tOPT_BIT(0, \"get-urlmatch\", &actions, N_(\"get value specific for the URL: section[.var] URL\"), ACTION_GET_URLMATCH),\n \tOPT_BIT(0, \"replace-all\", &actions, N_(\"replace all matching variables: name value [value_regex]\"), ACTION_REPLACE_ALL),\n \tOPT_BIT(0, \"add\", &actions, N_(\"add a new variable: name value\"), ACTION_ADD),\n@@ -68,6 +72,7 @@ static struct option builtin_config_options[] = {\n \tOPT_BIT(0, \"rename-section\", &actions, N_(\"rename section: old-name new-name\"), ACTION_RENAME_SECTION),\n \tOPT_BIT(0, \"remove-section\", &actions, N_(\"remove a section: name\"), ACTION_REMOVE_SECTION),\n \tOPT_BIT('l', \"list\", &actions, N_(\"list all\"), ACTION_LIST),\n+\tOPT_BIT(0, \"list-names\", &actions, N_(\"list all variable names\"), ACTION_LIST_NAMES),\n \tOPT_BIT('e', \"edit\", &actions, N_(\"open an editor\"), ACTION_EDIT),\n \tOPT_BIT(0, \"get-color\", &actions, N_(\"find the color configured: slot [default]\"), ACTION_GET_COLOR),\n \tOPT_BIT(0, \"get-colorbool\", &actions, N_(\"find the color setting: slot [stdout-is-tty]\"), ACTION_GET_COLORBOOL),\n@@ -91,7 +96,7 @@ static void check_argc(int argc, int min, int max) {\n \n static int show_all_config(const char *key_, const char *value_, void *cb)\n {\n-\tif (value_)\n+\tif (!omit_values && value_)\n \t\tprintf(\"%s%c%s%c\", key_, delim, value_, term);\n \telse\n \t\tprintf(\"%s%c\", key_, term);\n@@ -117,6 +122,10 @@ static int format_config(struct strbuf *buf, const char *key_, const char *value\n \t\tstrbuf_addstr(buf, key_);\n \t\tmust_print_delim = 1;\n \t}\n+\tif (omit_values) {\n+\t\tstrbuf_addch(buf, term);\n+\t\treturn 0;\n+\t}\n \tif (types == TYPE_INT)\n \t\tsprintf(value, \"%\"PRId64,\n \t\t\tgit_config_int64(key_, value_ ? value_ : \"\"));\n@@ -550,7 +559,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n \t\t\tusage_with_options(builtin_config_usage, builtin_config_options);\n \t\t}\n \n-\tif (actions == ACTION_LIST) {\n+\tif (actions == ACTION_LIST || actions == ACTION_LIST_NAMES) {\n+\t\tomit_values = (actions == ACTION_LIST_NAMES);\n \t\tcheck_argc(argc, 0, 0);\n \t\tif (git_config_with_options(show_all_config, NULL,\n \t\t\t\t\t    &given_config_source,\n@@ -631,8 +641,9 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n \t\tcheck_argc(argc, 1, 2);\n \t\treturn get_value(argv[0], argv[1]);\n \t}\n-\telse if (actions == ACTION_GET_REGEXP) {\n+\telse if (actions == ACTION_GET_REGEXP || actions == ACTION_GET_NAME_REGEXP) {\n \t\tshow_keys = 1;\n+\t\tomit_values = (actions == ACTION_GET_NAME_REGEXP);\n \t\tuse_key_regexp = 1;\n \t\tdo_all = 1;\n \t\tcheck_argc(argc, 1, 2);\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex bfc74e9d57..6abbd564b6 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1883,8 +1883,8 @@ _git_config ()\n \t--*)\n \t\t__gitcomp \"\n \t\t\t--system --global --local --file=\n-\t\t\t--list --replace-all\n-\t\t\t--get --get-all --get-regexp\n+\t\t\t--list --list-names --replace-all\n+\t\t\t--get --get-all --get-regexp --get-name-regexp\n \t\t\t--add --unset --unset-all\n \t\t\t--remove-section --rename-section\n \t\t\t\"\ndiff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh\nindex 66dd28644f..525b093c59 100755\n--- a/t/t1300-repo-config.sh\n+++ b/t/t1300-repo-config.sh\n@@ -353,6 +353,18 @@ test_expect_success '--list without repo produces empty output' '\n '\n \n cat > expect << EOF\n+beta.noindent\n+nextsection.nonewline\n+123456.a123\n+version.1.2.3eX.alpha\n+EOF\n+\n+test_expect_success 'working --list-names' '\n+\tgit config --list-names >output &&\n+\ttest_cmp expect output\n+'\n+\n+cat > expect << EOF\n beta.noindent sillyValue\n nextsection.nonewline wow2 for me\n EOF\n@@ -363,6 +375,16 @@ test_expect_success '--get-regexp' '\n '\n \n cat > expect << EOF\n+beta.noindent\n+nextsection.nonewline\n+EOF\n+\n+test_expect_success '--get-name-regexp' '\n+\tgit config --get-name-regexp in >output &&\n+\ttest_cmp expect output\n+'\n+\n+cat > expect << EOF\n wow2 for me\n wow4 for you\n EOF\n-- \n2.4.2.349.g6883b65\n"},{"id":"262323","messageId":"1432816175-18988-3-git-send-email-szeder@ira.uka.de","threadId":"39440","inReplyTo":"1432816175-18988-1-git-send-email-szeder@ira.uka.de","subject":"[PATCH v2 2/2] completion: use new 'git config' options to reliably list variable names","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2015-05-28T12:29:35Z","receivedAt":"2015-05-28T12:29:35Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"List all set config variable names with 'git config --list-names' instead\nof '--list' and post processing.  Similarly, use 'git config\n--get-name-regexp' instead of '--get-regexp' to get config variables in a\ngiven section.\n\nSigned-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\n contrib/completion/git-completion.bash | 15 +++------------\n 1 file changed, 3 insertions(+), 12 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 6abbd564b6..121aa31342 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -744,9 +744,8 @@ __git_compute_porcelain_commands ()\n __git_get_config_variables ()\n {\n \tlocal section=\"$1\" i IFS=$'\\n'\n-\tfor i in $(git --git-dir=\"$(__gitdir)\" config --get-regexp \"^$section\\..*\" 2>/dev/null); do\n-\t\ti=\"${i#$section.}\"\n-\t\techo \"${i/ */}\"\n+\tfor i in $(git --git-dir=\"$(__gitdir)\" config --get-name-regexp \"^$section\\..*\" 2>/dev/null); do\n+\t\techo \"${i#$section.}\"\n \tdone\n }\n \n@@ -1774,15 +1773,7 @@ __git_config_get_set_variables ()\n \t\tc=$((--c))\n \tdone\n \n-\tgit --git-dir=\"$(__gitdir)\" config $config_file --list 2>/dev/null |\n-\twhile read -r line\n-\tdo\n-\t\tcase \"$line\" in\n-\t\t*.*=*)\n-\t\t\techo \"${line/=*/}\"\n-\t\t\t;;\n-\t\tesac\n-\tdone\n+\tgit --git-dir=\"$(__gitdir)\" config $config_file --list-names 2>/dev/null\n }\n \n _git_config ()\n-- \n2.4.2.349.g6883b65\n"},{"id":"262364","messageId":"xmqqbnh4h5k4.fsf@gitster.dls.corp.google.com","threadId":"39440","inReplyTo":"1432816175-18988-2-git-send-email-szeder@ira.uka.de","subject":"Re: [PATCH v2 1/2] config: add options to list only variable names","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-28T19:20:59Z","receivedAt":"2015-05-28T19:20:59Z","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> @@ -16,11 +16,12 @@ SYNOPSIS\n>  'git config' [<file-option>] [type] [-z|--null] --get-all name [value_regex]\n>  'git config' [<file-option>] [type] [-z|--null] --get-regexp name_regex [value_regex]\n>  'git config' [<file-option>] [type] [-z|--null] --get-urlmatch name URL\n> +'git config' [<file-option>] [-z|--null] --get-name-regexp name_regex\n> ...\n\nAt first I wondered why --get-name-regexp is needed, as (purely from\nthe syntactic level) it appeared at the first glance the existing\n'--get-regexp' without 'value_regex' may be sufficient, until I read\nthis:\n\n> +--get-name-regexp::\n> +\tLike --get-regexp, but shows only matching variable names, not its\n> +\tvalues.\n\nwhich makes it clear why it is needed.  The distinction is purely\nabout the output, i.e. the values are omitted.\n\nBut then it makes me wonder why --get-name-regexp shouldn't\noptionally accept value_regex like --get-regexp does, allowing you\nto say \"list the variables that match this pattern whose values\nmatch this other pattern\".  I know it may be a feature that is\nunnecessary for your purpose, but from a cursory look of the patch\ntext, you do not seem to be doing anything different between\nget-regexp and get-name-regexp codepaths other than flipping\nomit_values bit on, so it could be that the feature is already\nsupported but forgot to document it, perhaps?\n\nThe 'type' may also be shared between these two options, no?  It\nwould be logically consistent if you can say\n\n\tgit config --bool --get-name-regexp '.*' 'no'\n\nto find all configuration variables that are set to 'false' in\ndifferent spellings like '0', 'false', 'no', etc.  And I suspect\nthat the code already supports that.\n\nTangentially related to the above issue, but\n\n\tgit config --bool --get-regexp '.*' 'no'\n\nseems to be broken from that point of view.  Instead of ignoring a\nnon-bool string valued variables, it seems to barf upon seeing the\nfirst such variable.  Interestingly, --get-name-regexp does not\nshare that breakage ;-)\n\nWhich we may want to fix, but not in the scope of this series.\n\nHint, hint...\n"},{"id":"262365","messageId":"xmqq7frsh4tw.fsf@gitster.dls.corp.google.com","threadId":"39440","inReplyTo":"xmqqbnh4h5k4.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH v2 1/2] config: add options to list only variable names","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-28T19:36:43Z","receivedAt":"2015-05-28T19:36:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> The 'type' may also be shared between these two options, no?  It\n> would be logically consistent if you can say\n>\n> \tgit config --bool --get-name-regexp '.*' 'no'\n>\n> to find all configuration variables that are set to 'false' in\n> different spellings like '0', 'false', 'no', etc.  And I suspect\n> that the code already supports that.\n\nNot really.  This of course inherits the same breakage from the\nexisting --get-regexp code in that the value part is still matched\nas string.  I am sure you could argue that \"but read the name of the\nlast optional argument; it says value_REGEX and it is clearly about\nmatching textually\", and it may technically not be incorrect per-se,\nbut I'd say it is merely a justification for a lazy implementation\nto defend the current less-than-useful behaviour.\n\nIn any case, because it is still a textual match, user.name='Junio\nHamano' matches with the above.  The only reason why it does not\nbarf is because it does not try to interpret and format that value\nas a boolean.\n\nSo I would say that the feature supports [type] and [value_regex]\nto exactly the same degree as --get-regexp, i.e. with breakage.\n\nWhich means we should document it the same way, even though both are\nequally broken.  So that other people can later visit it and correct\nthe issue for both options.\n\n-- >8 --\nSubject: [PATCH] SQUASH???\n\nThe new option --get-name-regexp is a variant of --get-regexp; show\nthem next to each other, and also document [type] and [value_regex]\nthat the option seems to support.\n---\n Documentation/git-config.txt | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-config.txt b/Documentation/git-config.txt\nindex b69c859..9fc78d8 100644\n--- a/Documentation/git-config.txt\n+++ b/Documentation/git-config.txt\n@@ -15,8 +15,8 @@ SYNOPSIS\n 'git config' [<file-option>] [type] [-z|--null] --get name [value_regex]\n 'git config' [<file-option>] [type] [-z|--null] --get-all name [value_regex]\n 'git config' [<file-option>] [type] [-z|--null] --get-regexp name_regex [value_regex]\n+'git config' [<file-option>] [type] [-z|--null] --get-name-regexp name_regex [value_regex]\n 'git config' [<file-option>] [type] [-z|--null] --get-urlmatch name URL\n-'git config' [<file-option>] [-z|--null] --get-name-regexp name_regex\n 'git config' [<file-option>] --unset name [value_regex]\n 'git config' [<file-option>] --unset-all name [value_regex]\n 'git config' [<file-option>] --rename-section old_name new_name\n-- \n2.4.2-521-g2db3d00\n"},{"id":"262375","messageId":"20150528203924.GA29148@peff.net","threadId":"39440","inReplyTo":"1432816175-18988-1-git-send-email-szeder@ira.uka.de","subject":"Re: [PATCH v2 0/2] config: list only variable names for completion","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-05-28T20:39:25Z","receivedAt":"2015-05-28T20:39:25Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, May 28, 2015 at 02:29:33PM +0200, SZEDER Gábor wrote:\n\n> Fixed misspelled option names in docs and in commit message, incorporated\n> Peff's suggestions, and renamed 'show_only_keys' to 'omit_values' in 1/2.\n> \n> Only minor tweaking in 2/2's commit message.\n\nThis version looks good to me (though I agree with Junio's proposed\nsquash about the '[value_regex]' documentation).\n\n-Peff\n"},{"id":"262407","messageId":"CAP8UFD2Zhomk+ryRfZFWAVs0yZeXUfpBXTo51Cm=Lj1QbkRbmA@mail.gmail.com","threadId":"39440","inReplyTo":"xmqqbnh4h5k4.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH v2 1/2] config: add options to list only variable names","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2015-05-29T11:34:50Z","receivedAt":"2015-05-29T11:34:50Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Thu, May 28, 2015 at 9:20 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> SZEDER Gábor <szeder@ira.uka.de> writes:\n>\n>> @@ -16,11 +16,12 @@ SYNOPSIS\n>>  'git config' [<file-option>] [type] [-z|--null] --get-all name [value_regex]\n>>  'git config' [<file-option>] [type] [-z|--null] --get-regexp name_regex [value_regex]\n>>  'git config' [<file-option>] [type] [-z|--null] --get-urlmatch name URL\n>> +'git config' [<file-option>] [-z|--null] --get-name-regexp name_regex\n>> ...\n>\n> At first I wondered why --get-name-regexp is needed, as (purely from\n> the syntactic level) it appeared at the first glance the existing\n> '--get-regexp' without 'value_regex' may be sufficient, until I read\n> this:\n>\n>> +--get-name-regexp::\n>> +     Like --get-regexp, but shows only matching variable names, not its\n>> +     values.\n>\n> which makes it clear why it is needed.  The distinction is purely\n> about the output, i.e. the values are omitted.\n\nIf the distinction is purely about the output, then it seems logical\nto add only an output related option, like the --name-only option I\nsuggested, and not 2 new modes (--get-name-regexp and --list-names).\n\nDoesn't it look like git config already has too many modes?\n\n> But then it makes me wonder why --get-name-regexp shouldn't\n> optionally accept value_regex like --get-regexp does, allowing you\n> to say \"list the variables that match this pattern whose values\n> match this other pattern\".  I know it may be a feature that is\n> unnecessary for your purpose, but from a cursory look of the patch\n> text, you do not seem to be doing anything different between\n> get-regexp and get-name-regexp codepaths other than flipping\n> omit_values bit on, so it could be that the feature is already\n> supported but forgot to document it, perhaps?\n\nThis also suggests that it might be more logical to only add an option\ncalled --name-only or --omit-values that would map directly to the\nomit_values bit in the code.\n"},{"id":"262408","messageId":"20150529113942.GA30503@peff.net","threadId":"39440","inReplyTo":"CAP8UFD2Zhomk+ryRfZFWAVs0yZeXUfpBXTo51Cm=Lj1QbkRbmA@mail.gmail.com","subject":"Re: [PATCH v2 1/2] config: add options to list only variable names","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-05-29T11:39:43Z","receivedAt":"2015-05-29T11:39:43Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, May 29, 2015 at 01:34:50PM +0200, Christian Couder wrote:\n\n> >> +--get-name-regexp::\n> >> +     Like --get-regexp, but shows only matching variable names, not its\n> >> +     values.\n> >\n> > which makes it clear why it is needed.  The distinction is purely\n> > about the output, i.e. the values are omitted.\n> \n> If the distinction is purely about the output, then it seems logical\n> to add only an output related option, like the --name-only option I\n> suggested, and not 2 new modes (--get-name-regexp and --list-names).\n> \n> Doesn't it look like git config already has too many modes?\n\nYeah, I'd agree that is a simpler way to look at it, and avoiding extra\nmodes is probably a good thing.\n\n-Peff\n"}]}