From 3ac68a93fd2b984e2a7e570217d2646a208ffcc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sat, 26 May 2018 15:55:24 +0200 Subject: help: add --config to list all available config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sometimes it helps to list all available config vars so the user can search for something they want. The config man page can also be used but it's harder to search if you want to focus on the variable name, for example. This is not the best way to collect the available config since it's not precise. Ideally we should have a centralized list of config in C code (pretty much like 'struct option'), but that's a lot more work. This will do for now. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- advice.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'advice.c') diff --git a/advice.c b/advice.c index 370a56d054..cf6c673ed7 100644 --- a/advice.c +++ b/advice.c @@ -1,6 +1,7 @@ #include "cache.h" #include "config.h" #include "color.h" +#include "help.h" int advice_push_update_rejected = 1; int advice_push_non_ff_current = 1; @@ -131,6 +132,14 @@ int git_default_advice_config(const char *var, const char *value) return 0; } +void list_config_advices(struct string_list *list, const char *prefix) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(advice_config); i++) + list_config_item(list, prefix, advice_config[i].name); +} + int error_resolve_conflict(const char *me) { if (!strcmp(me, "cherry-pick")) -- cgit v1.2.1 From fb6fbffbdae719805fbf7a39ca268dad17696f82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sat, 26 May 2018 15:55:26 +0200 Subject: advice: keep config name in camelCase in advice_config[] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For parsing, we don't really need this because the main config parser will lowercase everything so we can do exact matching. But this array now is also used for printing in `git help --config`. Keep camelCase so we have a nice printout. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- advice.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'advice.c') diff --git a/advice.c b/advice.c index cf6c673ed7..2aca11f45e 100644 --- a/advice.c +++ b/advice.c @@ -54,28 +54,28 @@ static struct { const char *name; int *preference; } advice_config[] = { - { "pushupdaterejected", &advice_push_update_rejected }, - { "pushnonffcurrent", &advice_push_non_ff_current }, - { "pushnonffmatching", &advice_push_non_ff_matching }, - { "pushalreadyexists", &advice_push_already_exists }, - { "pushfetchfirst", &advice_push_fetch_first }, - { "pushneedsforce", &advice_push_needs_force }, - { "statushints", &advice_status_hints }, - { "statusuoption", &advice_status_u_option }, - { "commitbeforemerge", &advice_commit_before_merge }, - { "resolveconflict", &advice_resolve_conflict }, - { "implicitidentity", &advice_implicit_identity }, - { "detachedhead", &advice_detached_head }, - { "setupstreamfailure", &advice_set_upstream_failure }, - { "objectnamewarning", &advice_object_name_warning }, - { "rmhints", &advice_rm_hints }, - { "addembeddedrepo", &advice_add_embedded_repo }, - { "ignoredhook", &advice_ignored_hook }, - { "waitingforeditor", &advice_waiting_for_editor }, - { "graftfiledeprecated", &advice_graft_file_deprecated }, + { "pushUpdateRejected", &advice_push_update_rejected }, + { "pushNonFFCurrent", &advice_push_non_ff_current }, + { "pushNonFFMatching", &advice_push_non_ff_matching }, + { "pushAlreadyExists", &advice_push_already_exists }, + { "pushFetchFirst", &advice_push_fetch_first }, + { "pushNeedsForce", &advice_push_needs_force }, + { "statusHints", &advice_status_hints }, + { "statusUoption", &advice_status_u_option }, + { "commitBeforeMerge", &advice_commit_before_merge }, + { "resolveConflict", &advice_resolve_conflict }, + { "implicitIdentity", &advice_implicit_identity }, + { "detachedHead", &advice_detached_head }, + { "setupStreamFailure", &advice_set_upstream_failure }, + { "objectNameWarning", &advice_object_name_warning }, + { "rmHints", &advice_rm_hints }, + { "addEmbeddedRepo", &advice_add_embedded_repo }, + { "ignoredHook", &advice_ignored_hook }, + { "waitingForEditor", &advice_waiting_for_editor }, + { "graftFileDeprecated", &advice_graft_file_deprecated }, /* make this an alias for backward compatibility */ - { "pushnonfastforward", &advice_push_update_rejected } + { "pushNonFastForward", &advice_push_update_rejected } }; void advise(const char *advice, ...) @@ -123,7 +123,7 @@ int git_default_advice_config(const char *var, const char *value) return 0; for (i = 0; i < ARRAY_SIZE(advice_config); i++) { - if (strcmp(k, advice_config[i].name)) + if (strcasecmp(k, advice_config[i].name)) continue; *advice_config[i].preference = git_config_bool(var, value); return 0; -- cgit v1.2.1 From 431bb23a271ef45e22ad4a2def2e0ba0a1954e98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sat, 26 May 2018 15:55:27 +0200 Subject: am: move advice.amWorkDir parsing back to advice.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The only benefit from this move (apart from cleaner code) is that advice.amWorkDir should now show up in `git help --config`. There should be no regression since advice config is always read by the git_default_config(). While at there, use advise() like other code. We now get "hint: " prefix and the output is stderr instead of stdout (which is also the reason for the test update because stderr is checked in a following test and the extra advice can fail it). Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- advice.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'advice.c') diff --git a/advice.c b/advice.c index 2aca11f45e..52aa85bdfd 100644 --- a/advice.c +++ b/advice.c @@ -17,6 +17,7 @@ int advice_implicit_identity = 1; int advice_detached_head = 1; int advice_set_upstream_failure = 1; int advice_object_name_warning = 1; +int advice_amworkdir = 1; int advice_rm_hints = 1; int advice_add_embedded_repo = 1; int advice_ignored_hook = 1; @@ -68,6 +69,7 @@ static struct { { "detachedHead", &advice_detached_head }, { "setupStreamFailure", &advice_set_upstream_failure }, { "objectNameWarning", &advice_object_name_warning }, + { "amWorkDir", &advice_amworkdir }, { "rmHints", &advice_rm_hints }, { "addEmbeddedRepo", &advice_add_embedded_repo }, { "ignoredHook", &advice_ignored_hook }, -- cgit v1.2.1