git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	git@vger.kernel.org,
	"Johannes Schindelin" <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCH 1/2] difftool: use "struct strvec" API in run_{dir,file}_diff()
Date: Sun, 12 Sep 2021 17:10:34 -0700	[thread overview]
Message-ID: <xmqqlf41ibd1.fsf@gitster.g> (raw)
In-Reply-To: <YT6BnnXeAWn8BycF@coredump.intra.peff.net> (Jeff King's message of "Sun, 12 Sep 2021 18:39:26 -0400")

Jeff King <peff@peff.net> writes:

> On Sat, Sep 11, 2021 at 08:21:11PM +0200, Ævar Arnfjörð Bjarmason wrote:
>
>> The underlying run_command() API can take either the "struct strvec
>> args", or a "const char **argv". Let's move to the former to use the
>> more "native" version of run_command() in both of these functions.
>
> It sounds like we're moving to use child.args (the strvec interface)
> instead of child.argv (the const char one). Which I support; I'd like to
> eventually get rid of the argv interface entirely because it has
> memory-ownership semantics that are easy to get wrong.
>
> But this...
>
>> @@ -393,10 +393,8 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
>>  	child.clean_on_exit = 1;
>>  	child.dir = prefix;
>>  	child.out = -1;
>> -	strvec_pushl(&child.args, "diff", "--raw", "--no-abbrev", "-z",
>> -		     NULL);
>> -	for (i = 0; i < argc; i++)
>> -		strvec_push(&child.args, argv[i]);
>> +	child.argv = args->v;
>> +
>
> ...is going in the opposite direction.
>
> I'd much rather see us continue to use child.args here, like:
>
>   strvec_pushv(&child.args, args->v);
>
> Though really I do think passing the strvec into run_dir_diff() is
> questionable in the first place. The caller depends on us to free the
> memory in the strvec for them, which is...subtle.
> ...
> +	strvec_push(&args, "diff");
> +	if (dir_diff)
> +		strvec_pushl(&args, "--raw", "--no-abbrev", "-z", NULL);
> +	strvec_pushv(&args, argv);
> +
>  	if (dir_diff)
> -		return run_dir_diff(extcmd, symlinks, prefix, argc, argv);
> -	return run_file_diff(prompt, prefix, argc, argv);
> +		return run_dir_diff(extcmd, symlinks, prefix, args.nr, args.v);
> +	return run_file_diff(prompt, prefix, args.nr, args.v);
>  }

Yes, I have to say that the end result of not having to rely on the
strvec type, in order to just call a main()- like function, makes it
much more pleasant read.


  parent reply	other threads:[~2021-09-13  0:13 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-11 18:21 [PATCH 0/2] parse-options.c: remove OPT_ARGUMENT Ævar Arnfjörð Bjarmason
2021-09-11 18:21 ` [PATCH 1/2] difftool: use "struct strvec" API in run_{dir,file}_diff() Ævar Arnfjörð Bjarmason
2021-09-12 22:39   ` Jeff King
2021-09-12 22:41     ` Jeff King
2021-09-13  0:10     ` Junio C Hamano [this message]
2021-09-11 18:21 ` [PATCH 2/2] parse-options API: remove OPTION_ARGUMENT feature Ævar Arnfjörð Bjarmason
2021-09-12 22:43   ` Jeff King
2021-09-13  3:35 ` [PATCH v2 0/4] difftool refactoring + remove OPT_ARGUMENT() macro Ævar Arnfjörð Bjarmason
2021-09-13  3:35   ` [PATCH v2 1/4] difftool: prepare "struct child_process" in cmd_difftool() Ævar Arnfjörð Bjarmason
2021-09-13  3:35   ` [PATCH v2 2/4] difftool: prepare "diff" cmdline " Ævar Arnfjörð Bjarmason
2021-09-13  3:35   ` [PATCH v2 3/4] difftool: use run_command() API in run_file_diff() Ævar Arnfjörð Bjarmason
2021-09-13 18:04     ` Jeff King
2021-09-13 19:13       ` Ævar Arnfjörð Bjarmason
2021-09-13 19:27         ` Jeff King
2021-09-13  3:35   ` [PATCH v2 4/4] parse-options API: remove OPTION_ARGUMENT feature Ævar Arnfjörð Bjarmason
2021-09-13  6:27     ` Junio C Hamano
2021-09-13 18:04   ` [PATCH v2 0/4] difftool refactoring + remove OPT_ARGUMENT() macro Jeff King

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

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

  git send-email \
    --in-reply-to=xmqqlf41ibd1.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --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.
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 NNTP newsgroup(s).