From nobody Tue Jul 05 11:36:39 2022 X-Original-To: dev-commits-src-all@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 26C631CFBB8B; Tue, 5 Jul 2022 11:36:40 +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 4LcgcS0NQJz4qY5; Tue, 5 Jul 2022 11:36:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657021000; 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=Gaclqq8bSkU2HB0ggNgrmHPh/+a0WpmjoR1EVso/F6Q=; b=BNgY0WHVotcZPPJZmaokvSI5ZyoQsoR4yP7Gwuqu5P1oLfnozuXawnKAv8UoiXTkuByhik gLGW29RTw9sLWrlfe1ZOW0d1TT0lC/2vJQNhgFUWXiN5Ht739xQEOaDORW+kNG9K3JIoY2 LbjeHpQgs5X2BX/6CRC5/2NoyMJm4ArAAmblTIb75L/tNBCj7Ef/eSVE03m3UsQzT3jNF9 dLzBEsSSFlCE5/TcO2+vSJ1IVxf+bZQW1Q8rnDNUpNzcjV6KSEb5Rhe0NUTHBRSped/BVW XEmGmxv16cIXmh4axhiDXOIppPd0CYNLYBtZ0CGncyWGetHSQo7l+pKFSuYkhw== 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 E0C2F24B27; Tue, 5 Jul 2022 11:36:39 +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 265BadFb085354; Tue, 5 Jul 2022 11:36:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 265Bad4r085353; Tue, 5 Jul 2022 11:36:39 GMT (envelope-from git) Date: Tue, 5 Jul 2022 11:36:39 GMT Message-Id: <202207051136.265Bad4r085353@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: d458eb8de12c - main - diff3: make the eflag logic easier to follow List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: d458eb8de12cc656b324f6094e6ed1eedc35625a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657021000; 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=Gaclqq8bSkU2HB0ggNgrmHPh/+a0WpmjoR1EVso/F6Q=; b=nmUFuaUBA1jHgvv6cNhO4iPCYaQb67KX+/VCWCMZXOAk2Cird6YJ4fGe3PXm2hAZDl8gjn gN1P08iTY9WMeKX4Nfur/vsD8+0Z1Aw8ZDMiIAIo34QouVjTKV7+YOXwLKH7EBaatsEoLG 4pnNar93FlFV/7KcyZKD/XAlQv4KqGhYDdB8Nfdd0KUMguNtKpoOZ3WbVOp7iCs4+cDhyZ r07TZWVqd19pNfaD/a2RLvknqolWa+l7EhC+hQP6CZzrA7LT1SYrcqD60EID7Rl3Dcxung 3C1x8pTOrVyYyWmTrB2iyvF7dORCfdRA4CXJSFfa3V4eakoOEPPdjqJb66Rxyw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1657021000; a=rsa-sha256; cv=none; b=F4JiS3LS1PSokdn28ppdwKAoxEkbOZLDYRYPIR6dYi15e4rCKU+EKR8aDQ6MefJyJmImBN NqJyjezm/BkaLtF4BzrN0m9DXDZ73y/eaDEDoKca7YvdB6z8i6JN0vw4X5CH7lKwGGAMLo CbpmSHA/ylU6GzGpLqiMxp2/q95pkEwK09KzFOgWzSRyFZycbDUf+7Q2CR/P8T1vHZ/1r/ 2N7OFQLiaO1HwJGm17yLxZvBDXzIlNIuili0ZnQ1XLZegzA6jMXouEsKQC2iaUTSJaDWH1 557wJpJzyWU+JzVVTn1+uFupd8RY9UkHt/AdZT9J33xFAFc5dNcm/ClPJsDJ/g== 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=d458eb8de12cc656b324f6094e6ed1eedc35625a commit d458eb8de12cc656b324f6094e6ed1eedc35625a Author: Tom Jones AuthorDate: 2022-07-05 11:33:55 +0000 Commit: Tom Jones CommitDate: 2022-07-05 11:36:11 +0000 diff3: make the eflag logic easier to follow Discussed with: dim Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D35324 --- usr.bin/diff3/diff3.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/usr.bin/diff3/diff3.c b/usr.bin/diff3/diff3.c index 860af98d13e2..514e78c79ed6 100644 --- a/usr.bin/diff3/diff3.c +++ b/usr.bin/diff3/diff3.c @@ -112,6 +112,11 @@ struct diff { struct range new; }; +#define EFLAG_NONE 0 +#define EFLAG_OVERLAP 1 +#define EFLAG_NOOVERLAP 2 +#define EFLAG_UNMERGED 3 + static size_t szchanges; static struct diff *d13; @@ -313,7 +318,7 @@ merge(int m1, int m2) /* first file is different from the others */ if (!t2 || (t1 && d1->new.to < d2->new.from)) { /* stuff peculiar to 1st file */ - if (eflag == 0) { + if (eflag == EFLAG_NONE) { printf("====1\n"); change(1, &d1->old, false); keep(2, &d1->new); @@ -324,7 +329,7 @@ merge(int m1, int m2) } /* second file is different from others */ if (!t1 || (t2 && d2->new.to < d1->new.from)) { - if (eflag == 0) { + if (eflag == EFLAG_NONE) { printf("====2\n"); keep(1, &d2->new); change(3, &d2->new, false); @@ -361,7 +366,7 @@ merge(int m1, int m2) * dup = 0 means all files differ * dup = 1 means files 1 and 2 identical */ - if (eflag == 0) { + if (eflag == EFLAG_NONE) { printf("====%s\n", dup ? "3" : ""); change(1, &d1->old, dup); change(2, &d2->old, false); @@ -530,9 +535,11 @@ repos(int nchar) static int edit(struct diff *diff, bool dup, int j, int difftype) { - - if (((dup + 1) & eflag) == 0) + if (!(eflag == EFLAG_UNMERGED || + (!dup && eflag == EFLAG_OVERLAP ) || + (dup && eflag == EFLAG_NOOVERLAP))) { return (j); + } j++; overlap[j] = !dup; if (!dup) @@ -607,7 +614,7 @@ edscript(int n) if (iflag) printf("w\nq\n"); - exit(eflag == 0 ? overlapcnt : 0); + exit(eflag == EFLAG_NONE ? overlapcnt : 0); } /* @@ -825,13 +832,13 @@ main(int argc, char **argv) struct kevent *e; nblabels = 0; - eflag = 0; + eflag = EFLAG_NONE; oflag = 0; diffargv[diffargc++] = __DECONST(char *, diffprog); while ((ch = getopt_long(argc, argv, OPTIONS, longopts, NULL)) != -1) { switch (ch) { case '3': - eflag = 2; + eflag = EFLAG_NOOVERLAP; break; case 'a': diffargv[diffargc++] = __DECONST(char *, "-a"); @@ -840,10 +847,10 @@ main(int argc, char **argv) Aflag = 1; break; case 'e': - eflag = 3; + eflag = EFLAG_UNMERGED; break; case 'E': - eflag = 3; + eflag = EFLAG_UNMERGED; oflag = 1; break; case 'i': @@ -864,11 +871,11 @@ main(int argc, char **argv) Tflag = 1; break; case 'x': - eflag = 1; + eflag = EFLAG_OVERLAP; break; case 'X': oflag = 1; - eflag = 1; + eflag = EFLAG_OVERLAP; break; case DIFFPROG_OPT: diffprog = optarg; @@ -889,7 +896,7 @@ main(int argc, char **argv) argv += optind; if (Aflag) { - eflag = 3; + eflag = EFLAG_UNMERGED; oflag = 1; }