Skip to content

Commit fd0d703

Browse files
committed
Merge branch 'ab/retire-advice-config'
Code clean up to migrate callers from older advice_config[] based API to newer advice_if_enabled() and advice_enabled() API. * ab/retire-advice-config: advice: move advice.graftFileDeprecated squashing to commit.[ch] advice: remove use of global advice_add_embedded_repo advice: remove read uses of most global `advice_` variables advice: add enum variants for missing advice variables
2 parents 6d09fc5 + ab62858 commit fd0d703

25 files changed

+63
-166
lines changed

advice.c

Lines changed: 4 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,6 @@
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;
29-
int advice_add_embedded_repo = 1;
30-
int advice_ignored_hook = 1;
31-
int advice_waiting_for_editor = 1;
32-
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;
37-
int advice_skipped_cherry_picks = 1;
38-
397
static int advice_use_color = -1;
408
static char advice_colors[][COLOR_MAXLEN] = {
419
GIT_COLOR_RESET,
@@ -63,51 +31,13 @@ static const char *advise_get_color(enum color_advice ix)
6331
return "";
6432
}
6533

66-
static struct {
67-
const char *name;
68-
int *preference;
69-
} advice_config[] = {
70-
{ "fetchShowForcedUpdates", &advice_fetch_show_forced_updates },
71-
{ "pushUpdateRejected", &advice_push_update_rejected },
72-
{ "pushNonFFCurrent", &advice_push_non_ff_current },
73-
{ "pushNonFFMatching", &advice_push_non_ff_matching },
74-
{ "pushAlreadyExists", &advice_push_already_exists },
75-
{ "pushFetchFirst", &advice_push_fetch_first },
76-
{ "pushNeedsForce", &advice_push_needs_force },
77-
{ "pushUnqualifiedRefName", &advice_push_unqualified_ref_name },
78-
{ "pushRefNeedsUpdate", &advice_push_ref_needs_update },
79-
{ "statusHints", &advice_status_hints },
80-
{ "statusUoption", &advice_status_u_option },
81-
{ "statusAheadBehindWarning", &advice_status_ahead_behind_warning },
82-
{ "commitBeforeMerge", &advice_commit_before_merge },
83-
{ "resetQuiet", &advice_reset_quiet_warning },
84-
{ "resolveConflict", &advice_resolve_conflict },
85-
{ "sequencerInUse", &advice_sequencer_in_use },
86-
{ "implicitIdentity", &advice_implicit_identity },
87-
{ "detachedHead", &advice_detached_head },
88-
{ "setUpstreamFailure", &advice_set_upstream_failure },
89-
{ "objectNameWarning", &advice_object_name_warning },
90-
{ "amWorkDir", &advice_amworkdir },
91-
{ "rmHints", &advice_rm_hints },
92-
{ "addEmbeddedRepo", &advice_add_embedded_repo },
93-
{ "ignoredHook", &advice_ignored_hook },
94-
{ "waitingForEditor", &advice_waiting_for_editor },
95-
{ "graftFileDeprecated", &advice_graft_file_deprecated },
96-
{ "checkoutAmbiguousRemoteBranchName", &advice_checkout_ambiguous_remote_branch_name },
97-
{ "submoduleAlternateErrorStrategyDie", &advice_submodule_alternate_error_strategy_die },
98-
{ "addIgnoredFile", &advice_add_ignored_file },
99-
{ "addEmptyPathspec", &advice_add_empty_pathspec },
100-
{ "skippedCherryPicks", &advice_skipped_cherry_picks },
101-
102-
/* make this an alias for backward compatibility */
103-
{ "pushNonFastForward", &advice_push_update_rejected }
104-
};
105-
10634
static struct {
10735
const char *key;
10836
int enabled;
10937
} advice_setting[] = {
11038
[ADVICE_ADD_EMBEDDED_REPO] = { "addEmbeddedRepo", 1 },
39+
[ADVICE_ADD_EMPTY_PATHSPEC] = { "addEmptyPathspec", 1 },
40+
[ADVICE_ADD_IGNORED_FILE] = { "addIgnoredFile", 1 },
11141
[ADVICE_AM_WORK_DIR] = { "amWorkDir", 1 },
11242
[ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] = { "checkoutAmbiguousRemoteBranchName", 1 },
11343
[ADVICE_COMMIT_BEFORE_MERGE] = { "commitBeforeMerge", 1 },
@@ -224,13 +154,6 @@ int git_default_advice_config(const char *var, const char *value)
224154
if (!skip_prefix(var, "advice.", &k))
225155
return 0;
226156

227-
for (i = 0; i < ARRAY_SIZE(advice_config); i++) {
228-
if (strcasecmp(k, advice_config[i].name))
229-
continue;
230-
*advice_config[i].preference = git_config_bool(var, value);
231-
break;
232-
}
233-
234157
for (i = 0; i < ARRAY_SIZE(advice_setting); i++) {
235158
if (strcasecmp(k, advice_setting[i].key))
236159
continue;
@@ -265,7 +188,7 @@ int error_resolve_conflict(const char *me)
265188
error(_("It is not possible to %s because you have unmerged files."),
266189
me);
267190

268-
if (advice_resolve_conflict)
191+
if (advice_enabled(ADVICE_RESOLVE_CONFLICT))
269192
/*
270193
* Message used both when 'git commit' fails and when
271194
* other commands doing a merge do.
@@ -284,7 +207,7 @@ void NORETURN die_resolve_conflict(const char *me)
284207
void NORETURN die_conclude_merge(void)
285208
{
286209
error(_("You have not concluded your merge (MERGE_HEAD exists)."));
287-
if (advice_resolve_conflict)
210+
if (advice_enabled(ADVICE_RESOLVE_CONFLICT))
288211
advise(_("Please, commit your changes before merging."));
289212
die(_("Exiting because of unfinished merge."));
290213
}

advice.h

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,6 @@
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;
30-
extern int advice_add_embedded_repo;
31-
extern int advice_ignored_hook;
32-
extern int advice_waiting_for_editor;
33-
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;
38-
extern int advice_skipped_cherry_picks;
39-
408
/*
419
* To add a new advice, you need to:
4210
* Define a new advice_type.
@@ -46,6 +14,8 @@ extern int advice_skipped_cherry_picks;
4614
*/
4715
enum advice_type {
4816
ADVICE_ADD_EMBEDDED_REPO,
17+
ADVICE_ADD_EMPTY_PATHSPEC,
18+
ADVICE_ADD_IGNORED_FILE,
4919
ADVICE_AM_WORK_DIR,
5020
ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME,
5121
ADVICE_COMMIT_BEFORE_MERGE,

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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ static const char embedded_advice[] = N_(
423423
static void check_embedded_repo(const char *path)
424424
{
425425
struct strbuf name = STRBUF_INIT;
426+
static int adviced_on_embedded_repo = 0;
426427

427428
if (!warn_on_embedded_repo)
428429
return;
@@ -434,10 +435,10 @@ static void check_embedded_repo(const char *path)
434435
strbuf_strip_suffix(&name, "/");
435436

436437
warning(_("adding embedded git repository: %s"), name.buf);
437-
if (advice_add_embedded_repo) {
438+
if (!adviced_on_embedded_repo &&
439+
advice_enabled(ADVICE_ADD_EMBEDDED_REPO)) {
438440
advise(embedded_advice, name.buf, name.buf);
439-
/* there may be multiple entries; advise only once */
440-
advice_add_embedded_repo = 0;
441+
adviced_on_embedded_repo = 1;
441442
}
442443

443444
strbuf_release(&name);
@@ -451,7 +452,7 @@ static int add_files(struct dir_struct *dir, int flags)
451452
fprintf(stderr, _(ignore_error));
452453
for (i = 0; i < dir->ignored_nr; i++)
453454
fprintf(stderr, "%s\n", dir->ignored[i]->name);
454-
if (advice_add_ignored_file)
455+
if (advice_enabled(ADVICE_ADD_IGNORED_FILE))
455456
advise(_("Use -f if you really want to add them.\n"
456457
"Turn this message off by running\n"
457458
"\"git config advice.addIgnoredFile false\""));
@@ -560,7 +561,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
560561

561562
if (require_pathspec && pathspec.nr == 0) {
562563
fprintf(stderr, _("Nothing specified, nothing added.\n"));
563-
if (advice_add_empty_pathspec)
564+
if (advice_enabled(ADVICE_ADD_EMPTY_PATHSPEC))
564565
advise( _("Maybe you wanted to say 'git add .'?\n"
565566
"Turn this message off by running\n"
566567
"\"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
@@ -1236,7 +1236,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
12361236
" 'git remote prune %s' to remove any old, conflicting "
12371237
"branches"), remote_name);
12381238

1239-
if (advice_fetch_show_forced_updates) {
1239+
if (advice_enabled(ADVICE_FETCH_SHOW_FORCED_UPDATES)) {
12401240
if (!fetch_show_forced_updates) {
12411241
warning(_(warn_show_forced_updates));
12421242
} 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)