Skip to content

Commit d878d83

Browse files
committed
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
2 parents 36f8e7e + 67360b7 commit d878d83

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

diff.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3399,6 +3399,21 @@ static void add_formatted_headers(struct strbuf *msg,
33993399
line_prefix, meta, reset);
34003400
}
34013401

3402+
static int diff_filepair_is_phoney(struct diff_filespec *one,
3403+
struct diff_filespec *two)
3404+
{
3405+
/*
3406+
* This function specifically looks for pairs injected by
3407+
* create_filepairs_for_header_only_notifications(). Such
3408+
* pairs are "phoney" in that they do not represent any
3409+
* content or even mode difference, but were inserted because
3410+
* diff_queued_diff previously had no pair associated with
3411+
* that path but we needed some pair to avoid losing the
3412+
* "remerge CONFLICT" header associated with the path.
3413+
*/
3414+
return !DIFF_FILE_VALID(one) && !DIFF_FILE_VALID(two);
3415+
}
3416+
34023417
static void builtin_diff(const char *name_a,
34033418
const char *name_b,
34043419
struct diff_filespec *one,
@@ -3430,14 +3445,16 @@ static void builtin_diff(const char *name_a,
34303445

34313446
if (o->submodule_format == DIFF_SUBMODULE_LOG &&
34323447
(!one->mode || S_ISGITLINK(one->mode)) &&
3433-
(!two->mode || S_ISGITLINK(two->mode))) {
3448+
(!two->mode || S_ISGITLINK(two->mode)) &&
3449+
(!diff_filepair_is_phoney(one, two))) {
34343450
show_submodule_diff_summary(o, one->path ? one->path : two->path,
34353451
&one->oid, &two->oid,
34363452
two->dirty_submodule);
34373453
return;
34383454
} else if (o->submodule_format == DIFF_SUBMODULE_INLINE_DIFF &&
34393455
(!one->mode || S_ISGITLINK(one->mode)) &&
3440-
(!two->mode || S_ISGITLINK(two->mode))) {
3456+
(!two->mode || S_ISGITLINK(two->mode)) &&
3457+
(!diff_filepair_is_phoney(one, two))) {
34413458
show_submodule_inline_diff(o, one->path ? one->path : two->path,
34423459
&one->oid, &two->oid,
34433460
two->dirty_submodule);
@@ -3457,12 +3474,12 @@ static void builtin_diff(const char *name_a,
34573474
b_two = quote_two(b_prefix, name_b + (*name_b == '/'));
34583475
lbl[0] = DIFF_FILE_VALID(one) ? a_one : "/dev/null";
34593476
lbl[1] = DIFF_FILE_VALID(two) ? b_two : "/dev/null";
3460-
if (!DIFF_FILE_VALID(one) && !DIFF_FILE_VALID(two)) {
3477+
if (diff_filepair_is_phoney(one, two)) {
34613478
/*
3462-
* We should only reach this point for pairs from
3479+
* We should only reach this point for pairs generated from
34633480
* create_filepairs_for_header_only_notifications(). For
3464-
* these, we should avoid the "/dev/null" special casing
3465-
* above, meaning we avoid showing such pairs as either
3481+
* these, we want to avoid the "/dev/null" special casing
3482+
* above, because we do not want such pairs shown as either
34663483
* "new file" or "deleted file" below.
34673484
*/
34683485
lbl[0] = a_one;
@@ -5853,6 +5870,7 @@ static void diff_flush_patch(struct diff_filepair *p, struct diff_options *o)
58535870
{
58545871
int include_conflict_headers =
58555872
(additional_headers(o, p->one->path) &&
5873+
!o->pickaxe_opts &&
58565874
(!o->filter || filter_bit_tst(DIFF_STATUS_UNMERGED, o)));
58575875

58585876
/*
@@ -5908,6 +5926,8 @@ int diff_queue_is_empty(struct diff_options *o)
59085926
int i;
59095927
int include_conflict_headers =
59105928
(o->additional_path_headers &&
5929+
strmap_get_size(o->additional_path_headers) &&
5930+
!o->pickaxe_opts &&
59115931
(!o->filter || filter_bit_tst(DIFF_STATUS_UNMERGED, o)));
59125932

59135933
if (include_conflict_headers)

t/t4069-remerge-diff.sh

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
test_description='remerge-diff handling'
44

5-
TEST_PASSES_SANITIZE_LEAK=true
65
. ./test-lib.sh
76

87
# This test is ort-specific
@@ -57,6 +56,11 @@ test_expect_success 'remerge-diff on a clean merge' '
5756
test_cmp expect actual
5857
'
5958

59+
test_expect_success 'remerge-diff on a clean merge with a filter' '
60+
git show --oneline --remerge-diff --diff-filter=U bc_resolution >actual &&
61+
test_must_be_empty actual
62+
'
63+
6064
test_expect_success 'remerge-diff with both a resolved conflict and an unrelated change' '
6165
git log -1 --oneline ab_resolution >tmp &&
6266
cat <<-EOF >>tmp &&
@@ -90,6 +94,22 @@ test_expect_success 'remerge-diff with both a resolved conflict and an unrelated
9094
test_cmp expect actual
9195
'
9296

97+
test_expect_success 'pickaxe still includes additional headers for relevant changes' '
98+
# reuses "expect" from the previous testcase
99+
100+
git log --oneline --remerge-diff -Sacht ab_resolution >tmp &&
101+
sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
102+
test_cmp expect actual
103+
'
104+
105+
test_expect_success 'can filter out additional headers with pickaxe' '
106+
git show --remerge-diff --submodule=log --find-object=HEAD ab_resolution >actual &&
107+
test_must_be_empty actual &&
108+
109+
git show --remerge-diff -S"not present" --all >actual &&
110+
test_must_be_empty actual
111+
'
112+
93113
test_expect_success 'setup non-content conflicts' '
94114
git switch --orphan base &&
95115
@@ -185,6 +205,14 @@ test_expect_success 'remerge-diff w/ diff-filter=U: all conflict headers, no dif
185205
test_cmp expect actual
186206
'
187207

208+
test_expect_success 'submodule formatting ignores additional headers' '
209+
# Reuses "expect" from last testcase
210+
211+
git show --oneline --remerge-diff --diff-filter=U --submodule=log >tmp &&
212+
sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
213+
test_cmp expect actual
214+
'
215+
188216
test_expect_success 'remerge-diff w/ diff-filter=R: relevant file + conflict header' '
189217
git log -1 --oneline resolution >tmp &&
190218
cat <<-EOF >>tmp &&

0 commit comments

Comments
 (0)