diff mbox series

[RFC,v3,3/4] advice: remove use of global advice_add_embedded_repo

Message ID RFC-patch-v3-3.4-02613d0f30-20210806T191231Z-avarab@gmail.com (mailing list archive)
State Superseded
Headers show
Series advice: remove usage of `advice_*` global variables | expand

Commit Message

Ævar Arnfjörð Bjarmason Aug. 6, 2021, 7:13 p.m. UTC
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 adviced in
check_embedded_repo() than setting the global variable.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 advice.c      | 2 --
 advice.h      | 1 -
 builtin/add.c | 7 ++++---
 3 files changed, 4 insertions(+), 6 deletions(-)

Comments

Eric Sunshine Aug. 6, 2021, 8:01 p.m. UTC | #1
On Fri, Aug 6, 2021 at 3:13 PM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
> 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

s/, for/. For/

> more straightforward to track whether we've adviced in

s/adviced/advised/
...or better...
s/we've adviced/we've shown advice/

> check_embedded_repo() than setting the global variable.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
diff mbox series

Patch

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 },
 };
 
diff --git a/advice.h b/advice.h
index ed51db0f05..4b754f4c62 100644
--- a/advice.h
+++ b/advice.h
@@ -5,7 +5,6 @@ 
 
 struct string_list;
 
-extern int advice_add_embedded_repo;
 extern int advice_graft_file_deprecated;
 
 /*
diff --git a/builtin/add.c b/builtin/add.c
index cf29b302d4..8a5dd29f3f 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -419,6 +419,7 @@  static const char embedded_advice[] = N_(
 static void check_embedded_repo(const char *path)
 {
 	struct strbuf name = STRBUF_INIT;
+	static int adviced_on_embedded_repo = 0;
 
 	if (!warn_on_embedded_repo)
 		return;
@@ -430,10 +431,10 @@  static void check_embedded_repo(const char *path)
 	strbuf_strip_suffix(&name, "/");
 
 	warning(_("adding embedded git repository: %s"), name.buf);
-	if (advice_add_embedded_repo) {
+	if (!adviced_on_embedded_repo &&
+	    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;
+		adviced_on_embedded_repo = 1;
 	}
 
 	strbuf_release(&name);