Skip to content

Commit 9969454

Browse files
committed
diff -c/--cc: do not mistake "resolved as deletion" as "use working tree"
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 <[email protected]>
1 parent 206af7c commit 9969454

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

combine-diff.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,8 @@ static void dump_quoted_path(const char *head,
682682
}
683683

684684
static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
685-
int dense, struct rev_info *rev)
685+
int dense, int working_tree_file,
686+
struct rev_info *rev)
686687
{
687688
struct diff_options *opt = &rev->diffopt;
688689
unsigned long result_size, cnt, lno;
@@ -691,7 +692,6 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
691692
struct sline *sline; /* survived lines */
692693
int mode_differs = 0;
693694
int i, show_hunks;
694-
int working_tree_file = is_null_sha1(elem->sha1);
695695
int abbrev = DIFF_OPT_TST(opt, FULL_INDEX) ? 40 : DEFAULT_ABBREV;
696696
const char *a_prefix, *b_prefix;
697697
mmfile_t result_file;
@@ -954,6 +954,12 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re
954954
write_name_quoted(p->path, stdout, line_termination);
955955
}
956956

957+
/*
958+
* The result (p->elem) is from the working tree and their
959+
* parents are typically from multiple stages during a merge
960+
* (i.e. diff-files) or the state in HEAD and in the index
961+
* (i.e. diff-index).
962+
*/
957963
void show_combined_diff(struct combine_diff_path *p,
958964
int num_parent,
959965
int dense,
@@ -967,7 +973,7 @@ void show_combined_diff(struct combine_diff_path *p,
967973
DIFF_FORMAT_NAME_STATUS))
968974
show_raw_diff(p, num_parent, rev);
969975
else if (opt->output_format & DIFF_FORMAT_PATCH)
970-
show_patch_diff(p, num_parent, dense, rev);
976+
show_patch_diff(p, num_parent, dense, 1, rev);
971977
}
972978

973979
void diff_tree_combined(const unsigned char *sha1,
@@ -1035,7 +1041,7 @@ void diff_tree_combined(const unsigned char *sha1,
10351041
for (p = paths; p; p = p->next) {
10361042
if (p->len)
10371043
show_patch_diff(p, num_parent, dense,
1038-
rev);
1044+
0, rev);
10391045
}
10401046
}
10411047
}

0 commit comments

Comments
 (0)