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

Re: [PATCH v2 3/2] diff-no-index: simplify argv index calculation

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 7, 2022, 19:37 UTC
Message-ID
<xmqqr10nt1qz.fsf@gitster.g>
In-Reply-To
<9ea33608-3a6c-c0ef-9bb3-4bb535009aeb@web.de>
René Scharfe <l.s.r@web.de> writes:
Show 8 quoted lines
> Since 16bb3d714d (diff --no-index: use parse_options() instead of
> diff_opt_parse(), 2019-03-24) argc must be 2 if we reach the loop, i.e.
> argc - 2 == 0.  Remove that inconsequential term.
>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
> Bonus patch "while at it", would have saved me from going "huh?".
> Generated using -U8 for easier review.
All three patches made sense to me.  Thanks.
Show 29 quoted lines
>
>  diff-no-index.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/diff-no-index.c b/diff-no-index.c
> index a18f6c3c63..18edbdf4b5 100644
> --- a/diff-no-index.c
> +++ b/diff-no-index.c
> @@ -262,17 +262,17 @@ int diff_no_index(struct rev_info *revs,
>  	if (argc != 2) {
>  		if (implicit_no_index)
>  			warning(_("Not a git repository. Use --no-index to "
>  				  "compare two paths outside a working tree"));
>  		usage_with_options(diff_no_index_usage, options);
>  	}
>  	FREE_AND_NULL(options);
>  	for (i = 0; i < 2; i++) {
> -		const char *p = argv[argc - 2 + i];
> +		const char *p = argv[i];
>  		if (!strcmp(p, "-"))
>  			/*
>  			 * stdin should be spelled as "-"; if you have
>  			 * path that is "-", spell it as "./-".
>  			 */
>  			p = file_from_standard_input;
>  		else if (prefix)
>  			p = to_free[i] = prefix_filename(prefix, p);
> --
> 2.37.2
Previous: René ScharfeNext: Johannes Schindelin
Message 13 of 17 in “unleak paths allocated in "diff --no-index"”
  1. unleak paths allocated in "diff --no-index"Junio C Hamano, Sep 2, 2022
  2. diff --no-index: unleak paths[] elementsJunio C Hamano, Sep 2, 2022
  3. René ScharfeSep 3, 2022
  4. Junio C HamanoSep 5, 2022
  5. 1/2 diff-no-index: release strbuf on queue errorRené Scharfe, Sep 6, 2022
  6. René ScharfeSep 7, 2022
  7. 2/2 diff-no-index: release prefixed filenamesRené Scharfe, Sep 6, 2022
  8. Johannes SchindelinSep 7, 2022
  9. René ScharfeSep 7, 2022
  10. 1/2 diff-no-index: release strbuf on queue errorRené Scharfe, Sep 7, 2022
  11. 2/2 diff-no-index: release prefixed filenamesRené Scharfe, Sep 7, 2022
  12. 3/2 diff-no-index: simplify argv index calculationRené Scharfe, Sep 7, 2022
  13. Junio C HamanoSep 7, 2022
  14. Johannes SchindelinSep 5, 2022
  15. Ævar Arnfjörð BjarmasonSep 5, 2022
  16. Johannes SchindelinSep 7, 2022
  17. Ævar Arnfjörð BjarmasonSep 7, 2022

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.