Re: [PATCH v5 1/1] config: add conditional include
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Feb 24, 2017, 17:46 UTC
- Message-ID
- <xmqq1sun5vo6.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <CACsJy8CerU-=PF6wqzUAM02jkrVVGJ5MA0NgL6z9bHn5KM6jiw@mail.gmail.com>
Duy Nguyen <pclouds@gmail.com> writes:
Show 18 quoted lines
>>> + if (skip_prefix_mem(cond, cond_len, "gitdir:", &cond, &cond_len))
>>> + return include_by_gitdir(cond, cond_len, 0);
>>> + else if (skip_prefix_mem(cond, cond_len, "gitdir/i:", &cond, &cond_len))
>>> + return include_by_gitdir(cond, cond_len, 1);
>>
>> This may be OK for now, but it should be trivial to start from a
>> table with two entries, i.e.
>>
>> struct include_cond {
>> const char *keyword;
>> int (*fn)(const char *, size_t);
>> };
>>
>> and will show a better way to do things to those who follow your
>> footsteps.
>
> Yeah I don't see a third include coming soon and did not go with that.
> Let's way for it and refactor then.I would have said exactly that in my message if you already had include_by_gitdir() and include_by_gitdir_i() as separate functions.
But I didn't, because the above code gives an excuse to the person who adds the third one to be lazy and add another "else if" for expediency, because making it table-driven would require an extra work to add two wrapper functions that do not have anything to do with the third one being added.