Re: [PATCH v2 1/1] advice: add --no-advice global option
- From
Rubén Justo <rjusto@gmail.com>
- Date
- Apr 29, 2024, 17:05 UTC
- Message-ID
- <57b6c818-343a-450a-8183-2802abf1c62f@gmail.com>
- In-Reply-To
- <20240429010925.93205-2-james@jamesliu.io>
On Mon, Apr 29, 2024 at 11:09:25AM +1000, James Liu wrote:
Show 10 quoted lines
> int advice_enabled(enum advice_type type)
> {
> - int enabled = advice_setting[type].level != ADVICE_LEVEL_DISABLED;
> + int enabled;
> +
> + if (getenv(GIT_NO_ADVICE))
> + return 0;
> +
> + enabled = advice_setting[type].level != ADVICE_LEVEL_DISABLED;
> All hints are set to a default visibility value: "none", which means implicitly enabled. Maybe we can get this "no-advice" knob by making this default value configurable:
diff --git a/advice.c b/advice.c index 75111191ad..bc67b99ba7 100644 --- a/advice.c +++ b/advice.c @@ -39,6 +39,8 @@ enum advice_level { ADVICE_LEVEL_ENABLED, }; +static enum advice_level advice_default_level; + static struct { const char *key; enum advice_level level; @@ -126,7 +128,19 @@ void advise(const char *advice, ...) int advice_enabled(enum advice_type type) { - int enabled = advice_setting[type].level != ADVICE_LEVEL_DISABLED; + static int once = 0; + int enabled; + + if (!once++) { + const char* level = getenv("GIT_ADVICE_LEVEL"); + + if (level && !strcmp(level, "disable")) + advice_default_level = ADVICE_LEVEL_DISABLED; + } + + enabled = (advice_setting[type].level + ? advice_setting[type].level + : advice_default_level) != ADVICE_LEVEL_DISABLED; if (type == ADVICE_PUSH_UPDATE_REJECTED) return enabled &&