Re: [PATCH v3 2/2] usage: add warn_once() helper for repeated warnings
- From
Derrick Stolee <derrickstolee@github.com>
- Date
- Jun 2, 2022, 13:43 UTC
- Message-ID
- <049aae88-f5b3-788e-3979-34e8178e6bd4@github.com>
- In-Reply-To
- <220601.86r148yxi3.gmgdl@evledraar.gmail.com>
On 6/1/2022 3:33 PM, Ævar Arnfjörð Bjarmason wrote:
Show 28 quoted lines
> > On Wed, Jun 01 2022, Derrick Stolee wrote: > >> On 6/1/2022 8:29 AM, Ævar Arnfjörð Bjarmason wrote:> >>> On Wed, Jun 01 2022, Derrick Stolee via GitGitGadget wrote: >>> >>>> From: Derrick Stolee <derrickstolee@github.com> >>>> >>>> The previous change added a warning when valid_remote() detects >>>> credentials in the URL. Since remotes are validated multiple times per >>>> process, this causes multiple warnings to print. >>> >>> Why are we validating remotes multiple times per process? Can't we just >>> do it once? >>> >>> Is this a case of two callers going through the whole machinery and not >>> being aware of one another? >>> >>> Perhaps it's a pain to deal with that in this case, but it would be >>> better to note why here than taking it as a given. >> >> We could certainly investigate this more, but it seems like a more >> problematic approach than the one taken here. We could add a "is_valid" >> bit to struct remote, but then could some code path modify that struct >> after it was validated? > > I tested this a bit and I think this alternate approach is simpler, and > it passes your tests:
...
Show 22 quoted lines
> +static void valid_remote_at_end(const struct remote *remote)
> +{
> + int i;
> +
> + for (i = 0; i < remote->url_nr; i++)
> + check_if_creds_in_url(remote->url[i]);
> +}
> +
> static const char *alias_url(const char *url, struct rewrites *r)
> {
> int i, j;
> @@ -687,6 +692,7 @@ remotes_remote_get_1(struct remote_state *remote_state, const char *name,
> add_url_alias(remote_state, ret, name);
> if (!valid_remote(ret))
> return NULL;
> + valid_remote_at_end(ret);
> return ret;
> }
>
> I.e. we already have one spot where we get the full remote config, you
> were just hooking into valid_remote() which we call N times while doing
> that, let's just call it at the end.Thanks for finding a place where the current behavior only runs once.
I agree that this is a much simpler approach and reduces this series back down to one.
Thanks, -Stolee