git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] difftool: use "struct strvec" API in run_{dir,file}_diff()

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 13, 2021, 00:10 UTC
Message-ID
<xmqqlf41ibd1.fsf@gitster.g>
In-Reply-To
<YT6BnnXeAWn8BycF@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 45 quoted lines
> 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.

Previous: Jeff KingNext: Ævar Arnfjörð Bjarmason
Message 5 of 17 in “parse-options.c: remove OPT_ARGUMENT”
  1. 0/2 parse-options.c: remove OPT_ARGUMENTÆvar Arnfjörð Bjarmason, Sep 11, 2021
  2. 1/2 difftool: use "struct strvec" API in run_{dir,file}_diff()Ævar Arnfjörð Bjarmason, Sep 11, 2021
  3. Jeff KingSep 12, 2021
  4. Jeff KingSep 12, 2021
  5. Junio C HamanoSep 13, 2021
  6. 2/2 parse-options API: remove OPTION_ARGUMENT featureÆvar Arnfjörð Bjarmason, Sep 11, 2021
  7. Jeff KingSep 12, 2021
  8. 0/4 difftool refactoring + remove OPT_ARGUMENT() macroÆvar Arnfjörð Bjarmason, Sep 13, 2021
  9. 2/4 difftool: prepare "diff" cmdline in cmd_difftool()Ævar Arnfjörð Bjarmason, Sep 13, 2021
  10. 1/4 difftool: prepare "struct child_process" in cmd_difftool()Ævar Arnfjörð Bjarmason, Sep 13, 2021
  11. 3/4 difftool: use run_command() API in run_file_diff()Ævar Arnfjörð Bjarmason, Sep 13, 2021
  12. Jeff KingSep 13, 2021
  13. Ævar Arnfjörð BjarmasonSep 13, 2021
  14. Jeff KingSep 13, 2021
  15. 4/4 parse-options API: remove OPTION_ARGUMENT featureÆvar Arnfjörð Bjarmason, Sep 13, 2021
  16. Junio C HamanoSep 13, 2021
  17. Jeff KingSep 13, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.