Skip to content

Commit ed9bff0

Browse files
mathstufgitster
authored andcommitted
advice: remove read uses of most global advice_ variables
In c4a09cc (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 <[email protected]> Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6929055 commit ed9bff0

22 files changed

+50
-137
lines changed

advice.c

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,8 @@
44
#include "help.h"
55
#include "string-list.h"
66

7-
int advice_fetch_show_forced_updates = 1;
8-
int advice_push_update_rejected = 1;
9-
int advice_push_non_ff_current = 1;
10-
int advice_push_non_ff_matching = 1;
11-
int advice_push_already_exists = 1;
12-
int advice_push_fetch_first = 1;
13-
int advice_push_needs_force = 1;
14-
int advice_push_unqualified_ref_name = 1;
15-
int advice_push_ref_needs_update = 1;
16-
int advice_status_hints = 1;
17-
int advice_status_u_option = 1;
18-
int advice_status_ahead_behind_warning = 1;
19-
int advice_commit_before_merge = 1;
20-
int advice_reset_quiet_warning = 1;
21-
int advice_resolve_conflict = 1;
22-
int advice_sequencer_in_use = 1;
23-
int advice_implicit_identity = 1;
24-
int advice_detached_head = 1;
25-
int advice_set_upstream_failure = 1;
26-
int advice_object_name_warning = 1;
27-
int advice_amworkdir = 1;
28-
int advice_rm_hints = 1;
297
int advice_add_embedded_repo = 1;
30-
int advice_ignored_hook = 1;
31-
int advice_waiting_for_editor = 1;
328
int advice_graft_file_deprecated = 1;
33-
int advice_checkout_ambiguous_remote_branch_name = 1;
34-
int advice_submodule_alternate_error_strategy_die = 1;
35-
int advice_add_ignored_file = 1;
36-
int advice_add_empty_pathspec = 1;
379

3810
static int advice_use_color = -1;
3911
static char advice_colors[][COLOR_MAXLEN] = {
@@ -66,39 +38,8 @@ static struct {
6638
const char *name;
6739
int *preference;
6840
} advice_config[] = {
69-
{ "fetchShowForcedUpdates", &advice_fetch_show_forced_updates },
70-
{ "pushUpdateRejected", &advice_push_update_rejected },
71-
{ "pushNonFFCurrent", &advice_push_non_ff_current },
72-
{ "pushNonFFMatching", &advice_push_non_ff_matching },
73-
{ "pushAlreadyExists", &advice_push_already_exists },
74-
{ "pushFetchFirst", &advice_push_fetch_first },
75-
{ "pushNeedsForce", &advice_push_needs_force },
76-
{ "pushUnqualifiedRefName", &advice_push_unqualified_ref_name },
77-
{ "pushRefNeedsUpdate", &advice_push_ref_needs_update },
78-
{ "statusHints", &advice_status_hints },
79-
{ "statusUoption", &advice_status_u_option },
80-
{ "statusAheadBehindWarning", &advice_status_ahead_behind_warning },
81-
{ "commitBeforeMerge", &advice_commit_before_merge },
82-
{ "resetQuiet", &advice_reset_quiet_warning },
83-
{ "resolveConflict", &advice_resolve_conflict },
84-
{ "sequencerInUse", &advice_sequencer_in_use },
85-
{ "implicitIdentity", &advice_implicit_identity },
86-
{ "detachedHead", &advice_detached_head },
87-
{ "setUpstreamFailure", &advice_set_upstream_failure },
88-
{ "objectNameWarning", &advice_object_name_warning },
89-
{ "amWorkDir", &advice_amworkdir },
90-
{ "rmHints", &advice_rm_hints },
9141
{ "addEmbeddedRepo", &advice_add_embedded_repo },
92-
{ "ignoredHook", &advice_ignored_hook },
93-
{ "waitingForEditor", &advice_waiting_for_editor },
9442
{ "graftFileDeprecated", &advice_graft_file_deprecated },
95-
{ "checkoutAmbiguousRemoteBranchName", &advice_checkout_ambiguous_remote_branch_name },
96-
{ "submoduleAlternateErrorStrategyDie", &advice_submodule_alternate_error_strategy_die },
97-
{ "addIgnoredFile", &advice_add_ignored_file },
98-
{ "addEmptyPathspec", &advice_add_empty_pathspec },
99-
100-
/* make this an alias for backward compatibility */
101-
{ "pushNonFastForward", &advice_push_update_rejected }
10243
};
10344

10445
static struct {
@@ -264,7 +205,7 @@ int error_resolve_conflict(const char *me)
264205
error(_("It is not possible to %s because you have unmerged files."),
265206
me);
266207

267-
if (advice_resolve_conflict)
208+
if (advice_enabled(ADVICE_RESOLVE_CONFLICT))
268209
/*
269210
* Message used both when 'git commit' fails and when
270211
* other commands doing a merge do.
@@ -283,7 +224,7 @@ void NORETURN die_resolve_conflict(const char *me)
283224
void NORETURN die_conclude_merge(void)
284225
{
285226
error(_("You have not concluded your merge (MERGE_HEAD exists)."));
286-
if (advice_resolve_conflict)
227+
if (advice_enabled(ADVICE_RESOLVE_CONFLICT))
287228
advise(_("Please, commit your changes before merging."));
288229
die(_("Exiting because of unfinished merge."));
289230
}

advice.h

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,8 @@
55

66
struct string_list;
77

8-
extern int advice_fetch_show_forced_updates;
9-
extern int advice_push_update_rejected;
10-
extern int advice_push_non_ff_current;
11-
extern int advice_push_non_ff_matching;
12-
extern int advice_push_already_exists;
13-
extern int advice_push_fetch_first;
14-
extern int advice_push_needs_force;
15-
extern int advice_push_unqualified_ref_name;
16-
extern int advice_push_ref_needs_update;
17-
extern int advice_status_hints;
18-
extern int advice_status_u_option;
19-
extern int advice_status_ahead_behind_warning;
20-
extern int advice_commit_before_merge;
21-
extern int advice_reset_quiet_warning;
22-
extern int advice_resolve_conflict;
23-
extern int advice_sequencer_in_use;
24-
extern int advice_implicit_identity;
25-
extern int advice_detached_head;
26-
extern int advice_set_upstream_failure;
27-
extern int advice_object_name_warning;
28-
extern int advice_amworkdir;
29-
extern int advice_rm_hints;
308
extern int advice_add_embedded_repo;
31-
extern int advice_ignored_hook;
32-
extern int advice_waiting_for_editor;
339
extern int advice_graft_file_deprecated;
34-
extern int advice_checkout_ambiguous_remote_branch_name;
35-
extern int advice_submodule_alternate_error_strategy_die;
36-
extern int advice_add_ignored_file;
37-
extern int advice_add_empty_pathspec;
3810

3911
/*
4012
* To add a new advice, you need to:

branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ void create_branch(struct repository *r,
271271
real_ref = NULL;
272272
if (get_oid_mb(start_name, &oid)) {
273273
if (explicit_tracking) {
274-
if (advice_set_upstream_failure) {
274+
if (advice_enabled(ADVICE_SET_UPSTREAM_FAILURE)) {
275275
error(_(upstream_missing), start_name);
276276
advise(_(upstream_advice));
277277
exit(1);

builtin/add.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ static int add_files(struct dir_struct *dir, int flags)
447447
fprintf(stderr, _(ignore_error));
448448
for (i = 0; i < dir->ignored_nr; i++)
449449
fprintf(stderr, "%s\n", dir->ignored[i]->name);
450-
if (advice_add_ignored_file)
450+
if (advice_enabled(ADVICE_ADD_IGNORED_FILE))
451451
advise(_("Use -f if you really want to add them.\n"
452452
"Turn this message off by running\n"
453453
"\"git config advice.addIgnoredFile false\""));
@@ -553,7 +553,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
553553

554554
if (require_pathspec && pathspec.nr == 0) {
555555
fprintf(stderr, _("Nothing specified, nothing added.\n"));
556-
if (advice_add_empty_pathspec)
556+
if (advice_enabled(ADVICE_ADD_EMPTY_PATHSPEC))
557557
advise( _("Maybe you wanted to say 'git add .'?\n"
558558
"Turn this message off by running\n"
559559
"\"git config advice.addEmptyPathspec false\""));

builtin/am.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,7 @@ static void am_run(struct am_state *state, int resume)
18201820
printf_ln(_("Patch failed at %s %.*s"), msgnum(state),
18211821
linelen(state->msg), state->msg);
18221822

1823-
if (advice_amworkdir)
1823+
if (advice_enabled(ADVICE_AM_WORK_DIR))
18241824
advise(_("Use 'git am --show-current-patch=diff' to see the failed patch"));
18251825

18261826
die_user_resolve(state);

builtin/checkout.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
918918
REF_NO_DEREF, UPDATE_REFS_DIE_ON_ERR);
919919
if (!opts->quiet) {
920920
if (old_branch_info->path &&
921-
advice_detached_head && !opts->force_detach)
921+
advice_enabled(ADVICE_DETACHED_HEAD) && !opts->force_detach)
922922
detach_advice(new_branch_info->name);
923923
describe_detached_head(_("HEAD is now at"), new_branch_info->commit);
924924
}
@@ -1011,7 +1011,7 @@ static void suggest_reattach(struct commit *commit, struct rev_info *revs)
10111011
sb.buf);
10121012
strbuf_release(&sb);
10131013

1014-
if (advice_detached_head)
1014+
if (advice_enabled(ADVICE_DETACHED_HEAD))
10151015
fprintf(stderr,
10161016
Q_(
10171017
/* The singular version */
@@ -1182,7 +1182,7 @@ static const char *parse_remote_branch(const char *arg,
11821182
}
11831183

11841184
if (!remote && num_matches > 1) {
1185-
if (advice_checkout_ambiguous_remote_branch_name) {
1185+
if (advice_enabled(ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME)) {
11861186
advise(_("If you meant to check out a remote tracking branch on, e.g. 'origin',\n"
11871187
"you can do so by fully qualifying the name with the --track option:\n"
11881188
"\n"

builtin/clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ static int checkout(int submodule_progress)
786786
return 0;
787787
}
788788
if (!strcmp(head, "HEAD")) {
789-
if (advice_detached_head)
789+
if (advice_enabled(ADVICE_DETACHED_HEAD))
790790
detach_advice(oid_to_hex(&oid));
791791
FREE_AND_NULL(head);
792792
} else {

builtin/commit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ static void status_init_config(struct wt_status *s, config_fn_t fn)
203203
init_diff_ui_defaults();
204204
git_config(fn, s);
205205
determine_whence(s);
206-
s->hints = advice_status_hints; /* must come after git_config() */
206+
s->hints = advice_enabled(ADVICE_STATUS_HINTS); /* must come after git_config() */
207207
}
208208

209209
static void rollback_index_files(void)
@@ -1033,7 +1033,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
10331033
*/
10341034
if (!committable && whence != FROM_MERGE && !allow_empty &&
10351035
!(amend && is_a_merge(current_head))) {
1036-
s->hints = advice_status_hints;
1036+
s->hints = advice_enabled(ADVICE_STATUS_HINTS);
10371037
s->display_comment_prefix = old_display_comment_prefix;
10381038
run_status(stdout, index_file, prefix, 0, s);
10391039
if (amend)

builtin/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
12291229
" 'git remote prune %s' to remove any old, conflicting "
12301230
"branches"), remote_name);
12311231

1232-
if (advice_fetch_show_forced_updates) {
1232+
if (advice_enabled(ADVICE_FETCH_SHOW_FORCED_UPDATES)) {
12331233
if (!fetch_show_forced_updates) {
12341234
warning(_(warn_show_forced_updates));
12351235
} else if (forced_updates_ms > FORCED_UPDATES_DELAY_WARNING_IN_MS) {

builtin/merge.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,14 +1368,14 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
13681368
* There is no unmerged entry, don't advise 'git
13691369
* add/rm <file>', just 'git commit'.
13701370
*/
1371-
if (advice_resolve_conflict)
1371+
if (advice_enabled(ADVICE_RESOLVE_CONFLICT))
13721372
die(_("You have not concluded your merge (MERGE_HEAD exists).\n"
13731373
"Please, commit your changes before you merge."));
13741374
else
13751375
die(_("You have not concluded your merge (MERGE_HEAD exists)."));
13761376
}
13771377
if (ref_exists("CHERRY_PICK_HEAD")) {
1378-
if (advice_resolve_conflict)
1378+
if (advice_enabled(ADVICE_RESOLVE_CONFLICT))
13791379
die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).\n"
13801380
"Please, commit your changes before you merge."));
13811381
else

0 commit comments

Comments
 (0)