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

[PATCH] diff -c/--cc: do not mistake "resolved as deletion" as "use working tree"

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 4, 2011, 18:58 UTC
Message-ID
<7vwret3swq.fsf_-_@alter.siamese.dyndns.org>
In-Reply-To
<7vsjph6g4j.fsf@alter.siamese.dyndns.org>
The combined diff machinery can be used to compare:
 - a merge commit with its parent commits;
 - a working-tree file with multiple stages in an unmerged index; or
 - a working-tree file with the HEAD and the index.

The internal function combine-diff.c:show_patch_diff() checked if it needs to read the "result" from the working tree by looking at the object name of the result --- if it is null_sha1, it read from the working tree.

This mistook a merge that records a deletion as the conflict resolution as if it is a cue to read from the working tree. Pass this information explicitly from the caller instead.

Noticed and reported by Johan Herland.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * The patch is based on a bit older maintenance branch but will be queued
   in 'pu'.
 combine-diff.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/combine-diff.c b/combine-diff.c
index 655fa89..360b816 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -682,7 +682,8 @@ static void dump_quoted_path(const char *head,
 }
 
 static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
-			    int dense, struct rev_info *rev)
+			    int dense, int working_tree_file,
+			    struct rev_info *rev)
 {
 	struct diff_options *opt = &rev->diffopt;
 	unsigned long result_size, cnt, lno;
@@ -691,7 +692,6 @@ 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 abbrev = DIFF_OPT_TST(opt, FULL_INDEX) ? 40 : DEFAULT_ABBREV;
 	const char *a_prefix, *b_prefix;
 	mmfile_t result_file;
@@ -954,6 +954,12 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re
 	write_name_quoted(p->path, stdout, line_termination);
 }
 
+/*
+ * The result (p->elem) is from the working tree and their
+ * parents are typically from multiple stages during a merge
+ * (i.e. diff-files) or the state in HEAD and in the index
+ * (i.e. diff-index).
+ */
 void show_combined_diff(struct combine_diff_path *p,
 		       int num_parent,
 		       int dense,
@@ -967,7 +973,7 @@ void show_combined_diff(struct combine_diff_path *p,
 				  DIFF_FORMAT_NAME_STATUS))
 		show_raw_diff(p, num_parent, rev);
 	else if (opt->output_format & DIFF_FORMAT_PATCH)
-		show_patch_diff(p, num_parent, dense, rev);
+		show_patch_diff(p, num_parent, dense, 1, rev);
 }
 
 void diff_tree_combined(const unsigned char *sha1,
@@ -1035,7 +1041,7 @@ void diff_tree_combined(const unsigned char *sha1,
 			for (p = paths; p; p = p->next) {
 				if (p->len)
 					show_patch_diff(p, num_parent, dense,
-							rev);
+							0, rev);
 			}
 		}
 	}
-- 
1.7.6.401.g6a319
Previous: Junio C Hamano
Message 3 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.