Subject: Re: [PATCH v6 1/4] git: make super-prefix option

From: Junio C Hamano <[email-masked]>
Date: Tue, 04 Oct 2016 10:35:12 -0700

Stefan Beller <[email-masked]> writes:

> On Thu, Sep 29, 2016 at 2:48 PM, Brandon Williams <[email-masked]> wrote:
>
>>
>> +const char *get_super_prefix(void)
>> +{
>> +       if (!super_prefix)
>> +               super_prefix = getenv(GIT_SUPER_PREFIX_ENVIRONMENT);
>> +       return super_prefix;
>> +}
>> +
>
> As said earlier, is the following a valid thought:
>
>> The getenv() function returns a pointer to the value in the
>> environment, or NULL if there is no match.
>> So in case this is not set (when e.g. the user did not specify the
>> super prefix), we would probe it a couple of times.
>> The caching effect only occurs when the string is set. So this looks
>> like we save repetitive calls, but we do not always do that.

That reading is correct.  If the code wants to do the caching, it
should do so correctly.  Unless we expect that some callers might
want to be able to invalidate the cache,

	get_super_prefix(void)
	{
		static int initialized;
		if (!initialized) {
			super_prefix = getenv(...);
			initialized = 1;
		}
                return super_prefix;
	}                

would suffice.

Thanks for careful reading.