git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 3/4] advice: add `advice_set` to update advice settings at runtime

From
Ben Boeckel <mathstuf@gmail.com>
Date
Aug 5, 2021, 23:03 UTC
Message-ID
<20210805230321.532218-4-mathstuf@gmail.com>
In-Reply-To
<20210805230321.532218-1-mathstuf@gmail.com>

There are two uses of global `advice_` variables that write to them. Replace these uses with a new API that writes to the internal table so that the global variables may be removed completely.

Signed-off-by: Ben Boeckel <mathstuf@gmail.com>
---
 advice.c          | 5 +++++
 advice.h          | 5 +++++
 builtin/add.c     | 2 +-
 builtin/replace.c | 2 +-
 4 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/advice.c b/advice.c
index 0cf3cda26a..ee4edc5e28 100644
--- a/advice.c
+++ b/advice.c
@@ -189,6 +189,11 @@ int advice_enabled(enum advice_type type)
 	}
 }
 
+void advice_set(enum advice_type type, int value)
+{
+	advice_setting[type].enabled = value;
+}
+
 void advise_if_enabled(enum advice_type type, const char *advice, ...)
 {
 	va_list params;
diff --git a/advice.h b/advice.h
index 95489ab4c6..101c4054b7 100644
--- a/advice.h
+++ b/advice.h
@@ -89,6 +89,11 @@ void advise(const char *advice, ...);
  */
 int advice_enabled(enum advice_type type);
 
+/**
+ * Enable or disable advice of a certain kind.
+ */
+void advice_set(enum advice_type type, int value);
+
 /**
  * Checks the visibility of the advice before printing.
  */
diff --git a/builtin/add.c b/builtin/add.c
index a903306300..3d1fd64294 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -433,7 +433,7 @@ static void check_embedded_repo(const char *path)
 	if (advice_enabled(ADVICE_ADD_EMBEDDED_REPO)) {
 		advise(embedded_advice, name.buf, name.buf);
 		/* there may be multiple entries; advise only once */
-		advice_add_embedded_repo = 0;
+		advice_set(ADVICE_ADD_EMBEDDED_REPO, 0);
 	}
 
 	strbuf_release(&name);
diff --git a/builtin/replace.c b/builtin/replace.c
index cd48765911..1340878021 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -507,7 +507,7 @@ static int convert_graft_file(int force)
 	if (!fp)
 		return -1;
 
-	advice_graft_file_deprecated = 0;
+	advice_set(ADVICE_GRAFT_FILE_DEPRECATED, 0);
 	while (strbuf_getline(&buf, fp) != EOF) {
 		if (*buf.buf == '#')
 			continue;
-- 
2.31.1
Previous: Ben BoeckelNext: Ben Boeckel
Message 18 of 32 in “advice: remove usage of `advice_*` global variables”
  1. 0/4 advice: remove usage of `advice_*` global variablesBen Boeckel, Jul 31, 2021
  2. 1/4 advice: add a function to set the value of an advice typeBen Boeckel, Jul 31, 2021
  3. Johannes SchindelinAug 2, 2021
  4. 2/4 advice: add enum variants for missing advice variablesBen Boeckel, Jul 31, 2021
  5. Johannes SchindelinAug 2, 2021
  6. Ben BoeckelAug 3, 2021
  7. 3/4 advice: remove uses of global `advice_` variablesBen Boeckel, Jul 31, 2021
  8. Johannes SchindelinAug 2, 2021
  9. Ben BoeckelAug 3, 2021
  10. 4/4 advice: remove static global variables for advice trackingBen Boeckel, Jul 31, 2021
  11. Johannes SchindelinAug 2, 2021
  12. Ben BoeckelAug 3, 2021
  13. Johannes SchindelinAug 2, 2021
  14. Ben BoeckelAug 3, 2021
  15. 0/4 advice: remove usage of `advice_*` global variablesBen Boeckel, Aug 5, 2021
  16. 1/4 advice: add enum variants for missing advice variablesBen Boeckel, Aug 5, 2021
  17. 2/4 advice: remove read uses of global `advice_` variablesBen Boeckel, Aug 5, 2021
  18. 3/4 advice: add `advice_set` to update advice settings at runtimeBen Boeckel, Aug 5, 2021
  19. 4/4 advice: remove static global variables for advice trackingBen Boeckel, Aug 5, 2021
  20. 0/4 advice: remove usage of `advice_*` global variablesÆvar Arnfjörð Bjarmason, Aug 6, 2021
  21. 2/4 advice: remove read uses of most global `advice_` variablesÆvar Arnfjörð Bjarmason, Aug 6, 2021
  22. Eric SunshineAug 6, 2021
  23. 1/4 advice: add enum variants for missing advice variablesÆvar Arnfjörð Bjarmason, Aug 6, 2021
  24. 3/4 advice: remove use of global advice_add_embedded_repoÆvar Arnfjörð Bjarmason, Aug 6, 2021
  25. Eric SunshineAug 6, 2021
  26. 4/4 advice: move advice.graftFileDeprecated squashing to commit.[ch]Ævar Arnfjörð Bjarmason, Aug 6, 2021
  27. 0/4 advice: remove usage of `advice_*` global variablesÆvar Arnfjörð Bjarmason, Aug 23, 2021
  28. 1/4 advice: add enum variants for missing advice variablesÆvar Arnfjörð Bjarmason, Aug 23, 2021
  29. 2/4 advice: remove read uses of most global `advice_` variablesÆvar Arnfjörð Bjarmason, Aug 23, 2021
  30. 3/4 advice: remove use of global advice_add_embedded_repoÆvar Arnfjörð Bjarmason, Aug 23, 2021
  31. 4/4 advice: move advice.graftFileDeprecated squashing to commit.[ch]Ævar Arnfjörð Bjarmason, Aug 23, 2021
  32. Junio C HamanoAug 25, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.