From nobody Fri Apr 15 14:01:32 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 492968D3AA5; Fri, 15 Apr 2022 14:01:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Kfyg01fQ9z517w; Fri, 15 Apr 2022 14:01:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1650031292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=IEeIWqn4Tx9x+rDh1uwWsMIy0X4TsNYc5KXwxKSlkVg=; b=FRkMKQkNHgueEc6fnDqXXcnCMLydYOAkRMIsIWAbChijwklylqhqkZ27xrHdVWH/KC6V2Z C8Q8cMK2MBYOogDWFoVFqhm1xNseYUagbfKxThMn0Ou7g62fzSEpxdb/eTpfyUrLPrbpIl B8n1IQaI3KNHiu4j8eLvf6F0guKFcEz5eWRWuXBlftjCCRE3NfzyIfqPacEIpBmlJDGnSc acJ45R2caFnq5yhMBqdbz7f/WlMC8dyKJ79l90dUH6HzgVqSRjcirrmINTsgpgXLlqq6WO X0xACCmL3XrrstAofN6ZENBzpGDcnJoPkx8vDYBiKfTK0/2pW1lQC0sX+rB6kQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 18FA1167F4; Fri, 15 Apr 2022 14:01:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 23FE1Wg4033514; Fri, 15 Apr 2022 14:01:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 23FE1Wut033513; Fri, 15 Apr 2022 14:01:32 GMT (envelope-from git) Date: Fri, 15 Apr 2022 14:01:32 GMT Message-Id: <202204151401.23FE1Wut033513@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Tom Jones Subject: git: 7c03df6855f4 - main - diff3: allow diff3 ed scripts to generate deletions List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: thj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7c03df6855f451749501748b98019c8e2d9d9600 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1650031292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=IEeIWqn4Tx9x+rDh1uwWsMIy0X4TsNYc5KXwxKSlkVg=; b=Pj9z0XV7Z47WFUg88Khm3dvyOid91NmKqFhbiqUWb2OCU2uWYy6Dwysgr+tG60/pcLyy+j tMWET82wnX30my1D0IJQNBSfzBcg9+7abSX21A1sEDel9wzeaRd+ymqQSXcmi23VAK6oNr u16uUMhxqd1j6g56oZwn2laTnmcg6zqLwDeIXr9/1623I1ftWF6wEuxiAJmGHG0BhzW1bt l6s4DpIswAJ9nb2pjpyBVrq0ZdMHE6vlgSJvEAk+X+He7+CEECCRVU62PfXAq+ConYI1Tr AqpiRHcMberO+gdx+Bkf6wwCWACH5iDmrVWxidw39idvikRzKDFkeMzNPIIFpg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1650031292; a=rsa-sha256; cv=none; b=dFS9HxLJXj+09s0Pz3Qgb2sFrJKMj0S//D/+ai07G4V9uOvQCCTefdhJXY+awy25ydDH18 GizHZnEBq1mi+T25e749E/hiLSob0vGxtTupyxDp7IZMCpQojoH7hzB9iy25NpUhHapR16 5jdBQA8SagQiJ9fdXtbtPTHoWzkZ9GlNMlfBSuKrCchzOLjTT58wM8wO5qJglzQKvB+2Ht y/ccfU+XPPbohnJ3gamedgywnOXk3KO9Yt9NP2XpZyhorLwVIqA/q4bFqIdp55xPoMAtWu Hp45Sp2Zm5TysYmt1XqJzcE89ww6N0dUdrG/qpk1kmFbcxg3FXfteGuMUbco4g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by thj: URL: https://cgit.FreeBSD.org/src/commit/?id=7c03df6855f451749501748b98019c8e2d9d9600 commit 7c03df6855f451749501748b98019c8e2d9d9600 Author: Tom Jones AuthorDate: 2022-04-15 13:59:14 +0000 Commit: Tom Jones CommitDate: 2022-04-15 14:00:59 +0000 diff3: allow diff3 ed scripts to generate deletions diff3 with the -e (ed script flag) can generate line deletions, add support for deletions and add a test case to exercise this behaviour. This functionality was unearthed through comparison of bsd diff3 and gnu diff3 output. Reviewed by: pstef Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D34912 --- usr.bin/diff3/diff3.c | 22 ++++++++++++++-------- usr.bin/diff3/tests/Makefile | 7 +++++-- usr.bin/diff3/tests/diff3_test.sh | 14 ++++++++------ usr.bin/diff3/tests/long-ed.out | 7 +++++++ usr.bin/diff3/tests/long-m.txt | 26 ++++++++++++++++++++++++++ usr.bin/diff3/tests/long-o.txt | 27 +++++++++++++++++++++++++++ usr.bin/diff3/tests/long-y.txt | 26 ++++++++++++++++++++++++++ 7 files changed, 113 insertions(+), 16 deletions(-) diff --git a/usr.bin/diff3/diff3.c b/usr.bin/diff3/diff3.c index 122243a9448f..37aa599eaab7 100644 --- a/usr.bin/diff3/diff3.c +++ b/usr.bin/diff3/diff3.c @@ -139,7 +139,7 @@ static int skip(int, int, const char *); static void change(int, struct range *, bool); static void keep(int, struct range *); static void merge(int, int); -static void prange(struct range *); +static void prange(struct range *, bool); static void repos(int); static void edscript(int) __dead2; static void increase(void); @@ -382,7 +382,7 @@ change(int i, struct range *rold, bool dup) printf("%d:", i); last[i] = rold->to; - prange(rold); + prange(rold, false); if (dup) return; i--; @@ -395,7 +395,7 @@ change(int i, struct range *rold, bool dup) * n1. */ static void -prange(struct range *rold) +prange(struct range *rold, bool delete) { if (rold->to <= rold->from) @@ -404,7 +404,10 @@ prange(struct range *rold) printf("%d", rold->from); if (rold->to > rold->from + 1) printf(",%d", rold->to - 1); - printf("c\n"); + if (delete) + printf("d\n"); + else + printf("c\n"); } } @@ -514,12 +517,14 @@ static void edscript(int n) { int k; + bool delete; size_t j; char block[BUFSIZ]; for (; n > 0; n--) { + delete = (de[n].new.from == de[n].new.to); if (!oflag || !overlap[n]) { - prange(&de[n].old); + prange(&de[n].old, delete); } else { printf("%da\n", de[n].old.to - 1); if (Aflag) { @@ -550,9 +555,10 @@ edscript(int n) j = r; (void)fwrite(block, 1, j, stdout); } - if (!oflag || !overlap[n]) - printf(".\n"); - else { + if (!oflag || !overlap[n]) { + if (!delete) + printf(".\n"); + } else { printf("%s\n.\n", f3mark); printf("%da\n%s\n.\n", de[n].old.from - 1, f1mark); } diff --git a/usr.bin/diff3/tests/Makefile b/usr.bin/diff3/tests/Makefile index b8bea154944b..91af4d1a6237 100644 --- a/usr.bin/diff3/tests/Makefile +++ b/usr.bin/diff3/tests/Makefile @@ -3,12 +3,14 @@ PACKAGE= tests ATF_TESTS_SH= diff3_test - ${PACKAGE}FILES+= \ 1.txt \ 1cr.txt \ 2.txt \ 3.txt \ + long-m.txt \ + long-o.txt \ + long-y.txt \ 1.out \ 1t.out \ 2.out \ @@ -18,6 +20,7 @@ ${PACKAGE}FILES+= \ 6.out \ 7.out \ 8.out \ - 9.out + 9.out \ + long-ed.out .include diff --git a/usr.bin/diff3/tests/diff3_test.sh b/usr.bin/diff3/tests/diff3_test.sh index 64031b023187..0eb08f46a803 100755 --- a/usr.bin/diff3/tests/diff3_test.sh +++ b/usr.bin/diff3/tests/diff3_test.sh @@ -2,6 +2,7 @@ atf_test_case diff3 atf_test_case diff3_lesssimple +atf_test_case diff3_ed diff3_body() { @@ -31,12 +32,6 @@ diff3_body() atf_check -o file:$(atf_get_srcdir)/7.out \ diff3 -i $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt - -# atf_check -o file:$(atf_get_srcdir)/8.out \ -# diff3 -A -L 1 -L 2 -L 3 $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt - -# atf_check -s exit:1 -o file:$(atf_get_srcdir)/9.out \ -# diff3 -m -L 1 -L 2 -L 3 $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt } diff3_lesssimple_body() @@ -45,8 +40,15 @@ diff3_lesssimple_body() diff3 -m -L 1 -L 2 -L 3 $(atf_get_srcdir)/4.txt $(atf_get_srcdir)/5.txt $(atf_get_srcdir)/6.txt } +diff3_ed_body() +{ + atf_check -s exit:0 -o file:$(atf_get_srcdir)/long-ed.out \ + diff3 -e $(atf_get_srcdir)/long-m.txt $(atf_get_srcdir)/long-o.txt $(atf_get_srcdir)/long-y.txt +} + atf_init_test_cases() { atf_add_test_case diff3 # atf_add_test_case diff3_lesssimple + atf_add_test_case diff3_ed } diff --git a/usr.bin/diff3/tests/long-ed.out b/usr.bin/diff3/tests/long-ed.out new file mode 100644 index 000000000000..8814a3518d60 --- /dev/null +++ b/usr.bin/diff3/tests/long-ed.out @@ -0,0 +1,7 @@ +24d +16c +This line is different in yours and mine, but the best in yours +. +8c +This line is different in yours, much butter +. diff --git a/usr.bin/diff3/tests/long-m.txt b/usr.bin/diff3/tests/long-m.txt new file mode 100644 index 000000000000..327bf8c225f7 --- /dev/null +++ b/usr.bin/diff3/tests/long-m.txt @@ -0,0 +1,26 @@ +This is a long file +These lines are the same in all three files +These lines are the same in all three files +This line is different in mine, not better +These lines are the same in all three files +These lines are the same in all three files +These lines are the same in all three files +This line is different in yours +These lines are the same in all three files +These lines are the same in all three files +This line is different in yours and mine, the same is in both +These lines are the same in all three files +These lines are the same in all three files +These lines are the same in all three files +These lines are the same in all three files +This line is different in yours and mine, best change in mine +These lines are the same in all three files +These lines are the same in all three files +These lines are the same in all three files +These lines are the same in all three files +These lines are the same in all three files +These lines are the same in all three files +These lines are the same in all three files +This line is deleted in yours +These lines are the same in all three files +These lines are the same in all three files diff --git a/usr.bin/diff3/tests/long-o.txt b/usr.bin/diff3/tests/long-o.txt new file mode 100644 index 000000000000..b4085d1d98c0 --- /dev/null +++ b/usr.bin/diff3/tests/long-o.txt @@ -0,0 +1,27 @@ +This is a long file +These lines are the same in all three files +These lines are the same in all three files +This line is different in mine +These lines are the same in all three files +These lines are the same in all three files +These lines are the same in all three files +This line is different in yours +These lines are the same in all three files +These lines are the same in all three files +This line is different in yours and mine, but the same +These lines are the same in all three files +These lines are the same in all three files +These lines are the same in all three files +These lines are the same in all three files +This line is different in yours and mine, but the different in each +These lines are the same in all three files +These lines are the same in all three files +These lines are the same in all three files +These lines are the same in all three files +This line is deleted in mine +These lines are the same in all three files +These lines are the same in all three files +These lines are the same in all three files +This line is deleted in yours +These lines are the same in all three files +These lines are the same in all three files diff --git a/usr.bin/diff3/tests/long-y.txt b/usr.bin/diff3/tests/long-y.txt new file mode 100644 index 000000000000..1bb25004924e --- /dev/null +++ b/usr.bin/diff3/tests/long-y.txt @@ -0,0 +1,26 @@ +This is a long file +These lines are the same in all three files +These lines are the same in all three files +This line is different in mine +These lines are the same in all three files +These lines are the same in all three files +These lines are the same in all three files +This line is different in yours, much butter +These lines are the same in all three files +These lines are the same in all three files +This line is different in yours and mine, the same is in both +These lines are the same in all three files +These lines are the same in all three files +These lines are the same in all three files +These lines are the same in all three files +This line is different in yours and mine, but the best in yours +These lines are the same in all three files +These lines are the same in all three files +These lines are the same in all three files +These lines are the same in all three files +This line is deleted in mine +These lines are the same in all three files +These lines are the same in all three files +These lines are the same in all three files +These lines are the same in all three files +These lines are the same in all three files