summaryrefslogtreecommitdiff
path: root/help.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2018-05-26 13:55:28 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-05-29 05:51:28 (GMT)
commite17ca926371dc96967f556f41c18410eea8c7d32 (patch)
treef02e9bc9f6c9b7e6fe8f55a702e802e469abfaba /help.c
parent431bb23a271ef45e22ad4a2def2e0ba0a1954e98 (diff)
downloadgit-e17ca926371dc96967f556f41c18410eea8c7d32.zip
git-e17ca926371dc96967f556f41c18410eea8c7d32.tar.gz
git-e17ca926371dc96967f556f41c18410eea8c7d32.tar.bz2
completion: drop the hard coded list of config vars
The new help option --config-for-completion is a machine friendlier version of --config where all the placeholders and wildcards are dropped, leaving only the good, completable prefixes for git-completion.bash to consume. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'help.c')
-rw-r--r--help.c34
1 files changed, 31 insertions, 3 deletions
diff --git a/help.c b/help.c
index f078dfe..3ebf056 100644
--- a/help.c
+++ b/help.c
@@ -416,7 +416,7 @@ struct slot_expansion {
int found;
};
-void list_config_help(void)
+void list_config_help(int for_human)
{
struct slot_expansion slot_expansions[] = {
{ "advice", "*", list_config_advices },
@@ -460,8 +460,36 @@ void list_config_help(void)
e->prefix, e->placeholder);
string_list_sort(&keys);
- for (i = 0; i < keys.nr; i++)
- puts(keys.items[i].string);
+ for (i = 0; i < keys.nr; i++) {
+ const char *var = keys.items[i].string;
+ const char *wildcard, *tag, *cut;
+
+ if (for_human) {
+ puts(var);
+ continue;
+ }
+
+ wildcard = strchr(var, '*');
+ tag = strchr(var, '<');
+
+ if (!wildcard && !tag) {
+ puts(var);
+ continue;
+ }
+
+ if (wildcard && !tag)
+ cut = wildcard;
+ else if (!wildcard && tag)
+ cut = tag;
+ else
+ cut = wildcard < tag ? wildcard : tag;
+
+ /*
+ * We may produce duplicates, but that's up to
+ * git-completion.bash to handle
+ */
+ printf("%.*s\n", (int)(cut - var), var);
+ }
string_list_clear(&keys, 0);
}