Re: [PATCH v3 2/2] config: learn the "hostname:" includeIf condition
- From
- Ignacio Encinas Rubio <ignacio@iencinas.com>
- Date
- Mar 19, 2024, 21:32 UTC
- Message-ID
- <cf3f27f9-c3c5-465e-bd49-767a1acabf0d@iencinas.com>
- In-Reply-To
- <20240319210428.GC1159535@coredump.intra.peff.net>
On 19/3/24 22:04, Jeff King wrote:
Show 10 quoted lines
> On Tue, Mar 19, 2024 at 07:37:22PM +0100, Ignacio Encinas wrote: > >> +`hostname`:: >> + The data that follows the keyword `hostname:` is taken to be a >> + pattern with standard globbing wildcards. If the current >> + hostname (output of gethostname(2)) matches the >> + pattern, the include condition is met. > > I was going to comment further here, but I see Eric already replied with > everything I was going to say. ;)
Please see my reply there. Thanks for the suggestion and sorry again if I sounded rude!
Show 28 quoted lines
> One small comment on the patch...
>
>> +static int include_by_hostname(const char *cond, size_t cond_len)
>> +{
>> + int ret;
>> + char my_host[HOST_NAME_MAX + 1];
>> + struct strbuf pattern = STRBUF_INIT;
>> +
>> + if (xgethostname(my_host, sizeof(my_host)))
>> + return 0;
>> +
>> + strbuf_add(&pattern, cond, cond_len);
>> + ret = !wildmatch(pattern.buf, my_host, 0);
>> + strbuf_release(&pattern);
>> + return ret;
>> +}
>
> This is absolutely a nit, but I think using xmemdupz() like:
>
> char *pattern;
> ...
>
> pattern = xmemdupz(cond, cond_len);
> ...
> free(pattern);
>
> expresses the intent more directly (it's also a little more efficient,
> but that's probably not measurable).Noted, thanks!
> -Peff