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

Re* BUG?: git diff with 3 args consults work tree when it shouldn't

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 4, 2011, 02:54 UTC
Message-ID
<7vsjph6g4j.fsf@alter.siamese.dyndns.org>
In-Reply-To
<201108011935.11373.johan@herland.net>

What happens is that the more-than-two-ways combined diff is sometimes used to show the difference _to_ the working tree files.

In combine-diff.c::show_patch_diff(), we try to detect that case by checking if sha1 recorded as "the result" is null, because diff-files will give us 0{40} as the blob object name for files in the working tree.

Unfortunately, that forgets another case where blob object is null, which is when the merge result tree _deleted_ the path.

This patch is not tested outside your test case. IOW, I know it will get three-tree case correctly, but I didn't test it with cases where we should look at the working tree files, so this may introduce regressions.

See 713a11f (combine-diff: diff-files fix., 2006-02-13) if you are interested. I suspect that we may need to add a bit to the API to tell this function if the end result is in the working tree.

 combine-diff.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/combine-diff.c b/combine-diff.c
index be67cfc..b4f1050 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -777,7 +777,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
 	struct sline *sline; /* survived lines */
 	int mode_differs = 0;
 	int i, show_hunks;
-	int working_tree_file = is_null_sha1(elem->sha1);
+	int working_tree_file = is_null_sha1(elem->sha1) && elem->mode;
 	mmfile_t result_file;
 	struct userdiff_driver *userdiff;
 	struct userdiff_driver *textconv = NULL;
Previous: Johan HerlandNext: Junio C Hamano
Message 2 of 3 in “BUG?: git diff with 3 args consults work tree when it shouldn't”
  1. Johan HerlandAug 1, 2011
  2. Re* BUG?: git diff with 3 args consults work tree when it shouldn'tJunio C Hamano, Aug 4, 2011
  3. diff -c/--cc: do not mistake "resolved as deletion" as "use working tree"Junio C Hamano, Aug 4, 2011

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.