advice: move advice.graftFileDeprecated squashing to commit.[ch]

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 <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Aug 23, 2021 at 12:44 UTC ab628588f80e8dd889b700515c41548c1a356dcc
5 files changed +5 -20
advice.c
-16
@@ -4,8 +4,6 @@
4 #include "help.h"
5 #include "string-list.h"
6
7 -int advice_graft_file_deprecated = 1;
8 -
7 static int advice_use_color = -1;
8 static char advice_colors[][COLOR_MAXLEN] = {
9 GIT_COLOR_RESET,
@@ -33,13 +31,6 @@ static const char *advise_get_color(enum color_advice ix)
31 return "";
32 }
33
36 -static struct {
37 - const char *name;
38 - int *preference;
39 -} advice_config[] = {
40 - { "graftFileDeprecated", &advice_graft_file_deprecated },
41 -};
42 -
34 static struct {
35 const char *key;
36 int enabled;
@@ -162,13 +153,6 @@ int git_default_advice_config(const char *var, const char *value)
153 if (!skip_prefix(var, "advice.", &k))
154 return 0;
155
165 - for (i = 0; i < ARRAY_SIZE(advice_config); i++) {
166 - if (strcasecmp(k, advice_config[i].name))
167 - continue;
168 - *advice_config[i].preference = git_config_bool(var, value);
169 - break;
170 - }
171 -
156 for (i = 0; i < ARRAY_SIZE(advice_setting); i++) {
157 if (strcasecmp(k, advice_setting[i].key))
158 continue;
advice.h
-2
@@ -5,8 +5,6 @@
5
6 struct string_list;
7
8 -extern int advice_graft_file_deprecated;
9 -
8 /*
9 * To add a new advice, you need to:
10 * Define a new advice_type.
builtin/replace.c
+1 -1
@@ -507,7 +507,7 @@ static int convert_graft_file(int force)
507 if (!fp)
508 return -1;
509
510 - advice_graft_file_deprecated = 0;
510 + no_graft_file_deprecated_advice = 1;
511 while (strbuf_getline(&buf, fp) != EOF) {
512 if (*buf.buf == '#')
513 continue;
commit.c
+3 -1
@@ -25,6 +25,7 @@
25 static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **);
26
27 int save_commit_buffer = 1;
28 +int no_graft_file_deprecated_advice;
29
30 const char *commit_type = "commit";
31
@@ -190,7 +191,8 @@ static int read_graft_file(struct repository *r, const char *graft_file)
191 struct strbuf buf = STRBUF_INIT;
192 if (!fp)
193 return -1;
193 - if (advice_graft_file_deprecated)
194 + if (!no_graft_file_deprecated_advice &&
195 + advice_enabled(ADVICE_GRAFT_FILE_DEPRECATED))
196 advise(_("Support for <GIT_DIR>/info/grafts is deprecated\n"
197 "and will be removed in a future Git version.\n"
198 "\n"
commit.h
+1
@@ -41,6 +41,7 @@ struct commit {
41 };
42
43 extern int save_commit_buffer;
44 +extern int no_graft_file_deprecated_advice;
45 extern const char *commit_type;
46
47 /* While we can decorate any object with a name, it's only used for commits.. */