Merge branch 'en/remerge-diff-fixes'

Fix a few "git log --remerge-diff" bugs.

* en/remerge-diff-fixes:
  diff: fix filtering of merge commits under --remerge-diff
  diff: fix filtering of additional headers under --remerge-diff
  diff: have submodule_format logic avoid additional diff headers
This commit is contained in:
Junio C Hamano
2022-09-15 16:09:46 -07:00
2 changed files with 55 additions and 7 deletions

32
diff.c
View File

@ -3399,6 +3399,21 @@ static void add_formatted_headers(struct strbuf *msg,
line_prefix, meta, reset);
}
static int diff_filepair_is_phoney(struct diff_filespec *one,
struct diff_filespec *two)
{
/*
* This function specifically looks for pairs injected by
* create_filepairs_for_header_only_notifications(). Such
* pairs are "phoney" in that they do not represent any
* content or even mode difference, but were inserted because
* diff_queued_diff previously had no pair associated with
* that path but we needed some pair to avoid losing the
* "remerge CONFLICT" header associated with the path.
*/
return !DIFF_FILE_VALID(one) && !DIFF_FILE_VALID(two);
}
static void builtin_diff(const char *name_a,
const char *name_b,
struct diff_filespec *one,
@ -3430,14 +3445,16 @@ static void builtin_diff(const char *name_a,
if (o->submodule_format == DIFF_SUBMODULE_LOG &&
(!one->mode || S_ISGITLINK(one->mode)) &&
(!two->mode || S_ISGITLINK(two->mode))) {
(!two->mode || S_ISGITLINK(two->mode)) &&
(!diff_filepair_is_phoney(one, two))) {
show_submodule_diff_summary(o, one->path ? one->path : two->path,
&one->oid, &two->oid,
two->dirty_submodule);
return;
} else if (o->submodule_format == DIFF_SUBMODULE_INLINE_DIFF &&
(!one->mode || S_ISGITLINK(one->mode)) &&
(!two->mode || S_ISGITLINK(two->mode))) {
(!two->mode || S_ISGITLINK(two->mode)) &&
(!diff_filepair_is_phoney(one, two))) {
show_submodule_inline_diff(o, one->path ? one->path : two->path,
&one->oid, &two->oid,
two->dirty_submodule);
@ -3457,12 +3474,12 @@ static void builtin_diff(const char *name_a,
b_two = quote_two(b_prefix, name_b + (*name_b == '/'));
lbl[0] = DIFF_FILE_VALID(one) ? a_one : "/dev/null";
lbl[1] = DIFF_FILE_VALID(two) ? b_two : "/dev/null";
if (!DIFF_FILE_VALID(one) && !DIFF_FILE_VALID(two)) {
if (diff_filepair_is_phoney(one, two)) {
/*
* We should only reach this point for pairs from
* We should only reach this point for pairs generated from
* create_filepairs_for_header_only_notifications(). For
* these, we should avoid the "/dev/null" special casing
* above, meaning we avoid showing such pairs as either
* these, we want to avoid the "/dev/null" special casing
* above, because we do not want such pairs shown as either
* "new file" or "deleted file" below.
*/
lbl[0] = a_one;
@ -5853,6 +5870,7 @@ static void diff_flush_patch(struct diff_filepair *p, struct diff_options *o)
{
int include_conflict_headers =
(additional_headers(o, p->one->path) &&
!o->pickaxe_opts &&
(!o->filter || filter_bit_tst(DIFF_STATUS_UNMERGED, o)));
/*
@ -5908,6 +5926,8 @@ int diff_queue_is_empty(struct diff_options *o)
int i;
int include_conflict_headers =
(o->additional_path_headers &&
strmap_get_size(o->additional_path_headers) &&
!o->pickaxe_opts &&
(!o->filter || filter_bit_tst(DIFF_STATUS_UNMERGED, o)));
if (include_conflict_headers)