Subject: Re: [PATCH v3] config: add conditional include

From: Matthieu Moy <[email-masked]>
Date: Wed, 13 Jul 2016 14:48:45 +0200

Jeff King <[email-masked]> writes:

> On Wed, Jul 13, 2016 at 09:21:37AM +0200, Matthieu Moy wrote:
>
>> > +static int prepare_include_condition_pattern(struct strbuf *pat)
>> > +{
>> > +	int prefix = 0;
>> > +
>> > +	/* TODO: maybe support ~user/ too */
>> > +	if (pat->buf[0] == '~' && is_dir_sep(pat->buf[1])) {
>> > +		struct strbuf path = STRBUF_INIT;
>> > +		const char *home = getenv("HOME");
>> > +
>> > +		if (!home)
>> > +			return error(_("$HOME is not defined"));
>> 
>> expand_user_path in path.c seems to do the same as you're doing (but
>> does deal with ~user). Any reason not to use it?
>
> I had a similar question, which Duy answered in:
>
>   http://article.gmane.org/gmane.comp.version-control.git/298528
>
> It does feel pretty hacky, though (especially for a case that seems
> unlikely to come up: people having wildcard patterns in the name of
> their home directory).

Ah, OK. Then I'd suggest at least an improvement in the comment:

 		/*
-		 * perform literal matching on the prefix part so that
- 		 * any wildcard character in it can't create side effects.
+		 * perform literal matching on the expanded prefix part
+		 * so that any wildcard character in it (e.g in the
+		 * expansion of ~) can't create side effects.
 		 */

I would also rename the variable prefix -> expanded_prefix. As-is, the
code is really hard to understand IMHO.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/