Web lists-archives.com

Re: [PATCH v2 1/7] run-command: add preliminary support for multiple hooks




Am 16.05.19 um 00:44 schrieb brian m. carlson:
> On Tue, May 14, 2019 at 05:12:39PM +0200, Johannes Schindelin wrote:
>> On Tue, 14 May 2019, brian m. carlson wrote:
>>> +/*
>>> + * Return 1 if a hook exists at path (which may be modified) using access(2)
>>> + * with check (which should be F_OK or X_OK), 0 otherwise. If strip is true,
>>> + * additionally consider the same filename but with STRIP_EXTENSION added.
>>> + * If check is X_OK, warn if the hook exists but is not executable.
>>> + */
>>> +static int has_hook(struct strbuf *path, int strip, int check)
>>> +{
>>> +	if (access(path->buf, check) < 0) {
>>> +		int err = errno;
>>> +
>>> +		if (strip) {
>>> +#ifdef STRIP_EXTENSION
>>> +			strbuf_addstr(path, STRIP_EXTENSION);
>>> +			if (access(path->buf, check) >= 0)
>>> +				return 1;
>>> +			if (errno == EACCES)
>>> +				err = errno;
>>> +#endif
>>> +		}
>>
>> How about simply guarding the entire `if()`? It is a bit unusual to guard
>> *only* the inside block ;-)
> 
> I can make that change.

But then we'll have an unused argument in some build configurations.

-- Hannes