diff3: make the diff3 -E -m and diff3 -m behaviour match gnu diff3

In gnu diff3 3 way merging files where the new file and the target are
already the same will die and show what has failed to be merged except
if -E is passed in argument, in this case it will finish the merge.

This difference in behaviour was breaking one of the etcupdate testcase
with bsd diff3

Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D41730
This commit is contained in:
Baptiste Daroussin 2023-09-05 13:24:53 +02:00
parent 09b0401e91
commit b37a6938e3
5 changed files with 49 additions and 3 deletions

View file

@ -335,7 +335,8 @@ merge(int m1, int m2)
change(2, &d2->old, false);
} else if (Aflag || mflag) {
// XXX-THJ: What does it mean for the second file to differ?
j = edit(d2, dup, j, DIFF_TYPE2);
if (eflag == EFLAG_UNMERGED)
j = edit(d2, dup, j, DIFF_TYPE2);
}
d2++;
continue;
@ -861,7 +862,7 @@ main(int argc, char **argv)
eflag = EFLAG_UNMERGED;
break;
case 'E':
eflag = EFLAG_UNMERGED;
eflag = EFLAG_OVERLAP;
oflag = 1;
break;
case 'i':
@ -907,7 +908,8 @@ main(int argc, char **argv)
argv += optind;
if (Aflag) {
eflag = EFLAG_UNMERGED;
if (eflag == EFLAG_NONE)
eflag = EFLAG_UNMERGED;
oflag = 1;
}

View file

@ -23,5 +23,7 @@ ${PACKAGE}FILES+= \
long-ed.out \
long-A.out \
long-merge.out \
fbsdid1.txt \
fbsdid2.txt
.include <bsd.test.mk>

View file

@ -4,6 +4,7 @@ atf_test_case diff3_lesssimple
atf_test_case diff3_ed
atf_test_case diff3_A
atf_test_case diff3_merge
atf_test_case diff3_E_merge
diff3_body()
{
@ -66,6 +67,36 @@ diff3_merge_body()
diff3 -m -L long-m.txt -L long-o.txt -L long-y.txt $(atf_get_srcdir)/long-m.txt $(atf_get_srcdir)/long-o.txt $(atf_get_srcdir)/long-y.txt
}
diff3_E_merge_body()
{
expected="<<<<<<< 2
# \$FreeBSD: head/local 12000 jhb \$
=======
# \$FreeBSD: head/local 12345 jhb \$
>>>>>>> 3
# \$FreeBSD: head/local 12345 jhb \$
this is a file
these are some local mods to the file
"
# first test the regular test
cp $(atf_get_srcdir)/fbsdid2.txt out.txt
atf_check -s exit:1 -o inline:"${expected}" \
diff3 -m -L 1 -L 2 -L 3 out.txt $(atf_get_srcdir)/fbsdid1.txt $(atf_get_srcdir)/fbsdid2.txt
merged="# \$FreeBSD: head/local 12345 jhb \$
this is a file
these are some local mods to the file
"
atf_check -s exit:0 -o inline:"${merged}" \
diff3 -E -m out.txt $(atf_get_srcdir)/fbsdid1.txt $(atf_get_srcdir)/fbsdid2.txt
}
atf_init_test_cases()
{
atf_add_test_case diff3
@ -73,4 +104,5 @@ atf_init_test_cases()
atf_add_test_case diff3_ed
atf_add_test_case diff3_A
atf_add_test_case diff3_merge
atf_add_test_case diff3_E_merge
}

View file

@ -0,0 +1,5 @@
# $FreeBSD: head/local 12000 jhb $
this is a file
these are some local mods to the file

View file

@ -0,0 +1,5 @@
# $FreeBSD: head/local 12345 jhb $
this is a file
these are some local mods to the file