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

Re: [PATCH 1/3] diff: use filespec path to set up tempfiles for ext-diff

From
Jeff King <peff@peff.net>
Date
Jan 6, 2023, 13:10 UTC
Message-ID
<Y7gdsxNT2TM/5M17@coredump.intra.peff.net>
In-Reply-To
<xmqqbknbsu9y.fsf@gitster.g>
On Fri, Jan 06, 2023 at 09:48:57PM +0900, Junio C Hamano wrote:
Show 6 quoted lines
> > The breakage seems to go all the way back to cd676a5136 (diff
> > --relative: output paths as relative to the current subdirectory,
> > 2008-02-12).
> 
> Not surprising.  When I wrote all the rest of "diff", I didn't
> plan to do "--relative" ;-)

:) Commit cd676a5136 mentions that "diff --relative" does not interact well with "--no-index", and that was one of the things I tested while poking (to make sure I did not make anything worse). And indeed, it seems that --relative is mostly ignored there. We could follow through on the plan from the end of the commit message to forbid combining the two, but it may not be that important given how long it has been an issue (and that I think people may set diff.relative in their config these days).

Show 5 quoted lines
> Thanks for a clear description.  The fix looks trivially obvious and
> correct.
> [...]
> > -	struct diff_tempfile *temp = prepare_temp_file(r, name, df);
> > +	struct diff_tempfile *temp = prepare_temp_file(r, df->path, df);

One nagging concern I had is whether "df->path" might ever point to something unexpected (or even be NULL). The fact that textconv unconditionally passes it made me feel a lot better. But I also ended up walking back to the source of the "name" and "other" fields, which is this code in run_diff():

	name  = one->path;
	other = (strcmp(name, two->path) ? two->path : NULL);
	attr_path = name;
	if (o->prefix_length)
		strip_prefix(o->prefix_length, &name, &other);

So those values really are just aliases for one->path and two->path, modulo the prefix stripping (which as you might guess, came from cd676a5136 itself). And using them directly instead of the stripped versions is definitely the right thing to do.

-Peff
Previous: Junio C HamanoNext: Jeff King
Message 5 of 7 in “Problem with git diff --relative, diff.external, run from a sub-directory”
  1. Carl BaldwinJan 4, 2023
  2. 0/3 fixing "diff --relative" with external diffJeff King, Jan 6, 2023
  3. 1/3 diff: use filespec path to set up tempfiles for ext-diffJeff King, Jan 6, 2023
  4. Junio C HamanoJan 6, 2023
  5. Jeff KingJan 6, 2023
  6. 2/3 diff: clean up external-diff argv setupJeff King, Jan 6, 2023
  7. 3/3 diff: drop "name" parameter from prepare_temp_file()Jeff King, Jan 6, 2023

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.