From 69290551b9a4fa22e76612926e131f926c6c9f11 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 23 Aug 2021 12:43:59 +0200 Subject: advice: add enum variants for missing advice variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In daef1b300b0 (Merge branch 'hw/advice-add-nothing', 2020-02-14), two advice settings were introduced into the `advice_config` array. Subsequently, c4a09cc9ccb (Merge branch 'hw/advise-ng', 2020-03-25) started to deprecate `advice_config` in favor of a new array, `advice_setting`. However, the latter branch did not include the former branch, and therefore `advice_setting` is missing the two entries added by the `hw/advice-add-nothing` branch. These are currently the only entries in `advice_config` missing from `advice_setting`. Signed-off-by: Ben Boeckel Signed-off-by: Ævar Arnfjörð Bjarmason 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 0b9c89c48a..6da51be63c 100644 --- a/advice.c +++ b/advice.c @@ -106,6 +106,8 @@ static struct { int enabled; } advice_setting[] = { [ADVICE_ADD_EMBEDDED_REPO] = { "addEmbeddedRepo", 1 }, + [ADVICE_ADD_EMPTY_PATHSPEC] = { "addEmptyPathspec", 1 }, + [ADVICE_ADD_IGNORED_FILE] = { "addIgnoredFile", 1 }, [ADVICE_AM_WORK_DIR] = { "amWorkDir", 1 }, [ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] = { "checkoutAmbiguousRemoteBranchName", 1 }, [ADVICE_COMMIT_BEFORE_MERGE] = { "commitBeforeMerge", 1 }, -- cgit v1.2.3 From ed9bff0817d5a7500b50a39c1c35b44aa3e72578 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 23 Aug 2021 12:44:00 +0200 Subject: advice: remove read uses of most global `advice_` variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In c4a09cc9ccb (Merge branch 'hw/advise-ng', 2020-03-25), a new API for accessing advice variables was introduced and deprecated `advice_config` in favor of a new array, `advice_setting`. This patch ports all but two uses which read the status of the global `advice_` variables over to the new `advice_enabled` API. We'll deal with advice_add_embedded_repo and advice_graft_file_deprecated separately. Signed-off-by: Ben Boeckel Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- advice.c | 63 ++------------------------------------------------------------- 1 file changed, 2 insertions(+), 61 deletions(-) (limited to 'advice.c') diff --git a/advice.c b/advice.c index 6da51be63c..b18833bc80 100644 --- a/advice.c +++ b/advice.c @@ -4,36 +4,8 @@ #include "help.h" #include "string-list.h" -int advice_fetch_show_forced_updates = 1; -int advice_push_update_rejected = 1; -int advice_push_non_ff_current = 1; -int advice_push_non_ff_matching = 1; -int advice_push_already_exists = 1; -int advice_push_fetch_first = 1; -int advice_push_needs_force = 1; -int advice_push_unqualified_ref_name = 1; -int advice_push_ref_needs_update = 1; -int advice_status_hints = 1; -int advice_status_u_option = 1; -int advice_status_ahead_behind_warning = 1; -int advice_commit_before_merge = 1; -int advice_reset_quiet_warning = 1; -int advice_resolve_conflict = 1; -int advice_sequencer_in_use = 1; -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; -int advice_waiting_for_editor = 1; int advice_graft_file_deprecated = 1; -int advice_checkout_ambiguous_remote_branch_name = 1; -int advice_submodule_alternate_error_strategy_die = 1; -int advice_add_ignored_file = 1; -int advice_add_empty_pathspec = 1; static int advice_use_color = -1; static char advice_colors[][COLOR_MAXLEN] = { @@ -66,39 +38,8 @@ static struct { const char *name; int *preference; } advice_config[] = { - { "fetchShowForcedUpdates", &advice_fetch_show_forced_updates }, - { "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 }, - { "pushUnqualifiedRefName", &advice_push_unqualified_ref_name }, - { "pushRefNeedsUpdate", &advice_push_ref_needs_update }, - { "statusHints", &advice_status_hints }, - { "statusUoption", &advice_status_u_option }, - { "statusAheadBehindWarning", &advice_status_ahead_behind_warning }, - { "commitBeforeMerge", &advice_commit_before_merge }, - { "resetQuiet", &advice_reset_quiet_warning }, - { "resolveConflict", &advice_resolve_conflict }, - { "sequencerInUse", &advice_sequencer_in_use }, - { "implicitIdentity", &advice_implicit_identity }, - { "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 }, - { "waitingForEditor", &advice_waiting_for_editor }, { "graftFileDeprecated", &advice_graft_file_deprecated }, - { "checkoutAmbiguousRemoteBranchName", &advice_checkout_ambiguous_remote_branch_name }, - { "submoduleAlternateErrorStrategyDie", &advice_submodule_alternate_error_strategy_die }, - { "addIgnoredFile", &advice_add_ignored_file }, - { "addEmptyPathspec", &advice_add_empty_pathspec }, - - /* make this an alias for backward compatibility */ - { "pushNonFastForward", &advice_push_update_rejected } }; static struct { @@ -264,7 +205,7 @@ int error_resolve_conflict(const char *me) error(_("It is not possible to %s because you have unmerged files."), me); - if (advice_resolve_conflict) + if (advice_enabled(ADVICE_RESOLVE_CONFLICT)) /* * Message used both when 'git commit' fails and when * other commands doing a merge do. @@ -283,7 +224,7 @@ void NORETURN die_resolve_conflict(const char *me) void NORETURN die_conclude_merge(void) { error(_("You have not concluded your merge (MERGE_HEAD exists).")); - if (advice_resolve_conflict) + if (advice_enabled(ADVICE_RESOLVE_CONFLICT)) advise(_("Please, commit your changes before merging.")); die(_("Exiting because of unfinished merge.")); } -- cgit v1.2.3 From c2a4b6d4ee4f7f52521c1c36d63744f1a3c08d50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Mon, 23 Aug 2021 12:44:01 +0200 Subject: advice: remove use of global advice_add_embedded_repo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The external use of this variable was added in 532139940c9 (add: warn when adding an embedded repository, 2017-06-14). For the use-case it's more straightforward to track whether we've shown advice in check_embedded_repo() than setting the global variable. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- advice.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'advice.c') diff --git a/advice.c b/advice.c index b18833bc80..41cfea82d0 100644 --- a/advice.c +++ b/advice.c @@ -4,7 +4,6 @@ #include "help.h" #include "string-list.h" -int advice_add_embedded_repo = 1; int advice_graft_file_deprecated = 1; static int advice_use_color = -1; @@ -38,7 +37,6 @@ static struct { const char *name; int *preference; } advice_config[] = { - { "addEmbeddedRepo", &advice_add_embedded_repo }, { "graftFileDeprecated", &advice_graft_file_deprecated }, }; -- cgit v1.2.3 From ab628588f80e8dd889b700515c41548c1a356dcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Mon, 23 Aug 2021 12:44:02 +0200 Subject: advice: move advice.graftFileDeprecated squashing to commit.[ch] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move the squashing of the advice.graftFileDeprecated advice over to an external variable in commit.[ch], allowing advice() to purely use the new-style API of invoking advice() with an enum. See 8821e90a09a (advice: don't pointlessly suggest --convert-graft-file, 2018-11-27) for why quieting this advice was needed. It's more straightforward to move this code to commit.[ch] and use it builtin/replace.c, than to go through the indirection of advice.[ch]. Because this was the last advice_config variable we can remove that old facility from advice.c. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- advice.c | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'advice.c') diff --git a/advice.c b/advice.c index 41cfea82d0..e716ddebff 100644 --- a/advice.c +++ b/advice.c @@ -4,8 +4,6 @@ #include "help.h" #include "string-list.h" -int advice_graft_file_deprecated = 1; - static int advice_use_color = -1; static char advice_colors[][COLOR_MAXLEN] = { GIT_COLOR_RESET, @@ -33,13 +31,6 @@ static const char *advise_get_color(enum color_advice ix) return ""; } -static struct { - const char *name; - int *preference; -} advice_config[] = { - { "graftFileDeprecated", &advice_graft_file_deprecated }, -}; - static struct { const char *key; int enabled; @@ -162,13 +153,6 @@ int git_default_advice_config(const char *var, const char *value) if (!skip_prefix(var, "advice.", &k)) return 0; - for (i = 0; i < ARRAY_SIZE(advice_config); i++) { - if (strcasecmp(k, advice_config[i].name)) - continue; - *advice_config[i].preference = git_config_bool(var, value); - break; - } - for (i = 0; i < ARRAY_SIZE(advice_setting); i++) { if (strcasecmp(k, advice_setting[i].key)) continue; -- cgit v1.2.3