git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	git@vger.kernel.org, doron.behar@gmail.com
Subject: Re: [PATCH 1/2] parse-options: expand $HOME on filename options
Date: Wed, 14 Feb 2018 10:24:02 -0800	[thread overview]
Message-ID: <xmqqbmgro2f1.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20180214140557.GA27850@sigill.intra.peff.net> (Jeff King's message of "Wed, 14 Feb 2018 09:05:58 -0500")

Jeff King <peff@peff.net> writes:

>> Support $HOME expansion for all filename options. There are about seven
>> of them.
>
> I think this probably makes sense.
>
>>  parse-options.c | 9 ++++++---
>>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> Should this be mentioned in the comment documenting OPT_FILENAME()?

Perhaps.  I think all mention of "$HOME expansion" should be
replaced with "tilde expansion", though.  I first thought we are
expanding any environment variable and $HOME is merely an example of
it when I read the title and the log message, before seeing that the
patch just adds a call to expand_user_path().

Other than that, looks good.  Thanks for a quick enhancement and a
review.

>> diff --git a/parse-options.c b/parse-options.c
>> index d265a756b5..c33f14c74e 100644
>> --- a/parse-options.c
>> +++ b/parse-options.c
>> @@ -38,10 +38,13 @@ static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt,
>>  
>>  static void fix_filename(const char *prefix, const char **file)
>>  {
>> -	if (!file || !*file || !prefix || is_absolute_path(*file)
>> -	    || !strcmp("-", *file))
>> +	if (!file || !*file || is_absolute_path(*file) ||
>> +	    !strcmp("-", *file))
>>  		return;
>> -	*file = prefix_filename(prefix, *file);
>> +	if (**file == '~')
>> +		*file = expand_user_path(*file, 0);
>> +	else if (prefix)
>> +		*file = prefix_filename(prefix, *file);
>>  }
>
> I thought at first this needed a final "else" clause, because we don't
> assign to *file if we have neither a prefix nor a user-path. But that's
> what the callers expect (and we are similarly a noop if we hit the first
> conditional). So this looks right.
>
> -Peff

  reply	other threads:[~2018-02-14 18:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-14 10:10 [BUG] git init doesn't respect `--template` like configuration variable init.templateDir and $GIT_TEMPLATE_DIR Doron Behar
2018-02-14 10:51 ` [PATCH 1/2] parse-options: expand $HOME on filename options Nguyễn Thái Ngọc Duy
2018-02-14 10:51   ` [PATCH 2/2] init-db: change --template type to OPTION_FILENAME Nguyễn Thái Ngọc Duy
2018-02-14 14:08     ` Jeff King
2018-02-14 14:05   ` [PATCH 1/2] parse-options: expand $HOME on filename options Jeff King
2018-02-14 18:24     ` Junio C Hamano [this message]
2018-02-14 22:46   ` Ævar Arnfjörð Bjarmason
2018-02-15 18:36     ` Junio C Hamano
2018-02-22  9:26     ` Duy Nguyen
2018-02-22 13:38       ` Ævar Arnfjörð Bjarmason
2018-02-23 10:11         ` Duy Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqbmgro2f1.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=doron.behar@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).