git: b37a6938e39a - main - diff3: make the diff3 -E -m and diff3 -m behaviour match gnu diff3
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 06 Sep 2023 15:07:01 UTC
The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=b37a6938e39a7ed9542fafee671465bf719fd537 commit b37a6938e39a7ed9542fafee671465bf719fd537 Author: Baptiste Daroussin <bapt@FreeBSD.org> AuthorDate: 2023-09-05 11:24:53 +0000 Commit: Baptiste Daroussin <bapt@FreeBSD.org> CommitDate: 2023-09-06 15:06:39 +0000 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 --- usr.bin/diff3/diff3.c | 8 +++++--- usr.bin/diff3/tests/Makefile | 2 ++ usr.bin/diff3/tests/diff3_test.sh | 32 ++++++++++++++++++++++++++++++++ usr.bin/diff3/tests/fbsdid1.txt | 5 +++++ usr.bin/diff3/tests/fbsdid2.txt | 5 +++++ 5 files changed, 49 insertions(+), 3 deletions(-) diff --git a/usr.bin/diff3/diff3.c b/usr.bin/diff3/diff3.c index e80b1d142231..380987560ee0 100644 --- a/usr.bin/diff3/diff3.c +++ b/usr.bin/diff3/diff3.c @@ -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; } diff --git a/usr.bin/diff3/tests/Makefile b/usr.bin/diff3/tests/Makefile index df000d68cc7e..3b720586d148 100644 --- a/usr.bin/diff3/tests/Makefile +++ b/usr.bin/diff3/tests/Makefile @@ -23,5 +23,7 @@ ${PACKAGE}FILES+= \ long-ed.out \ long-A.out \ long-merge.out \ + fbsdid1.txt \ + fbsdid2.txt .include <bsd.test.mk> diff --git a/usr.bin/diff3/tests/diff3_test.sh b/usr.bin/diff3/tests/diff3_test.sh index 3a4fc128ca16..3cbd7dac1ed9 100755 --- a/usr.bin/diff3/tests/diff3_test.sh +++ b/usr.bin/diff3/tests/diff3_test.sh @@ -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 } diff --git a/usr.bin/diff3/tests/fbsdid1.txt b/usr.bin/diff3/tests/fbsdid1.txt new file mode 100644 index 000000000000..9f94660bda97 --- /dev/null +++ b/usr.bin/diff3/tests/fbsdid1.txt @@ -0,0 +1,5 @@ +# $FreeBSD: head/local 12000 jhb $ + +this is a file + +these are some local mods to the file diff --git a/usr.bin/diff3/tests/fbsdid2.txt b/usr.bin/diff3/tests/fbsdid2.txt new file mode 100644 index 000000000000..420ad975868b --- /dev/null +++ b/usr.bin/diff3/tests/fbsdid2.txt @@ -0,0 +1,5 @@ +# $FreeBSD: head/local 12345 jhb $ + +this is a file + +these are some local mods to the file