From owner-svn-src-stable-12@freebsd.org Sun May 3 03:44:59 2020 Return-Path: Delivered-To: svn-src-stable-12@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id AC8A62D2136; Sun, 3 May 2020 03:44:59 +0000 (UTC) (envelope-from kevans@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49FBhC453pz499b; Sun, 3 May 2020 03:44:59 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 878754D2F; Sun, 3 May 2020 03:44:59 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0433ixVj030987; Sun, 3 May 2020 03:44:59 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0433ixM2030985; Sun, 3 May 2020 03:44:59 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <202005030344.0433ixM2030985@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Sun, 3 May 2020 03:44:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r360595 - in stable/12/usr.bin/diff: . tests X-SVN-Group: stable-12 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable/12/usr.bin/diff: . tests X-SVN-Commit-Revision: 360595 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 May 2020 03:44:59 -0000 Author: kevans Date: Sun May 3 03:44:58 2020 New Revision: 360595 URL: https://svnweb.freebsd.org/changeset/base/360595 Log: MFC r360437: diff(1): don't reject specifying the same format multiple times This may happen, for instance, if one happens to have an alias of diff to diff -up and attempts to specify the amount of context on top of that. Aliases like this may cause other problems, but if they're really not ever generating non-unified diffs then we should at least not break that use-case. In addition, we'll now pick up a format mismatch if -p is specified with !contextual && !unified && !unset. Fix up a small trailing whitespace nit in the tests while we're here, and add tests to make sure that we can double up all the formatting options. Modified: stable/12/usr.bin/diff/diff.c stable/12/usr.bin/diff/tests/diff_test.sh Directory Properties: stable/12/ (props changed) Modified: stable/12/usr.bin/diff/diff.c ============================================================================== --- stable/12/usr.bin/diff/diff.c Sun May 3 03:44:16 2020 (r360594) +++ stable/12/usr.bin/diff/diff.c Sun May 3 03:44:58 2020 (r360595) @@ -122,6 +122,8 @@ main(int argc, char **argv) newarg = 1; diff_context = 3; diff_format = D_UNSET; +#define FORMAT_MISMATCHED(type) \ + (diff_format != D_UNSET && diff_format != (type)) while ((ch = getopt_long(argc, argv, OPTIONS, longopts, NULL)) != -1) { switch (ch) { case '0': case '1': case '2': case '3': case '4': @@ -142,7 +144,7 @@ main(int argc, char **argv) break; case 'C': case 'c': - if (diff_format != D_UNSET) + if (FORMAT_MISMATCHED(D_CONTEXT)) conflicting_format(); cflag = 1; diff_format = D_CONTEXT; @@ -157,18 +159,18 @@ main(int argc, char **argv) dflags |= D_MINIMAL; break; case 'D': - if (diff_format != D_UNSET) + if (FORMAT_MISMATCHED(D_IFDEF)) conflicting_format(); diff_format = D_IFDEF; ifdefname = optarg; break; case 'e': - if (diff_format != D_UNSET) + if (FORMAT_MISMATCHED(D_EDIT)) conflicting_format(); diff_format = D_EDIT; break; case 'f': - if (diff_format != D_UNSET) + if (FORMAT_MISMATCHED(D_REVERSE)) conflicting_format(); diff_format = D_REVERSE; break; @@ -202,11 +204,20 @@ main(int argc, char **argv) Nflag = 1; break; case 'n': - if (diff_format != D_UNSET) + if (FORMAT_MISMATCHED(D_NREVERSE)) conflicting_format(); diff_format = D_NREVERSE; break; case 'p': + /* + * If it's not unset and it's not set to context or + * unified, we'll error out here as a conflicting + * format. If it's unset, we'll go ahead and set it to + * context. + */ + if (FORMAT_MISMATCHED(D_CONTEXT) && + FORMAT_MISMATCHED(D_UNIFIED)) + conflicting_format(); if (diff_format == D_UNSET) diff_format = D_CONTEXT; dflags |= D_PROTOTYPE; @@ -218,7 +229,7 @@ main(int argc, char **argv) rflag = 1; break; case 'q': - if (diff_format != D_UNSET) + if (FORMAT_MISMATCHED(D_BRIEF)) conflicting_format(); diff_format = D_BRIEF; break; @@ -236,7 +247,7 @@ main(int argc, char **argv) break; case 'U': case 'u': - if (diff_format != D_UNSET) + if (FORMAT_MISMATCHED(D_UNIFIED)) conflicting_format(); diff_format = D_UNIFIED; if (optarg != NULL) { @@ -264,12 +275,12 @@ main(int argc, char **argv) push_excludes(optarg); break; case 'y': - if (diff_format != D_UNSET) + if (FORMAT_MISMATCHED(D_SIDEBYSIDE)) conflicting_format(); diff_format = D_SIDEBYSIDE; break; case OPT_CHANGED_GROUP_FORMAT: - if (diff_format != D_UNSET) + if (FORMAT_MISMATCHED(D_GFORMAT)) conflicting_format(); diff_format = D_GFORMAT; group_format = optarg; @@ -283,7 +294,7 @@ main(int argc, char **argv) ignore_file_case = 0; break; case OPT_NORMAL: - if (diff_format != D_UNSET) + if (FORMAT_MISMATCHED(D_NORMAL)) conflicting_format(); diff_format = D_NORMAL; break; Modified: stable/12/usr.bin/diff/tests/diff_test.sh ============================================================================== --- stable/12/usr.bin/diff/tests/diff_test.sh Sun May 3 03:44:16 2020 (r360594) +++ stable/12/usr.bin/diff/tests/diff_test.sh Sun May 3 03:44:58 2020 (r360595) @@ -186,6 +186,13 @@ conflicting_format_body() atf_check -s exit:2 -e ignore diff -q -c A B atf_check -s exit:2 -e ignore diff --normal -c A B atf_check -s exit:2 -e ignore diff -c --normal A B + + atf_check -s exit:1 -o ignore -e ignore diff -u -u A B + atf_check -s exit:1 -o ignore -e ignore diff -e -e A B + atf_check -s exit:1 -o ignore -e ignore diff -y -y A B + atf_check -s exit:1 -o ignore -e ignore diff -q -q A B + atf_check -s exit:1 -o ignore -e ignore diff -c -c A B + atf_check -s exit:1 -o ignore -e ignore diff --normal --normal A B } atf_init_test_cases() @@ -201,5 +208,5 @@ atf_init_test_cases() atf_add_test_case b230049 atf_add_test_case Bflag atf_add_test_case tabsize - atf_add_test_case conflicting_format + atf_add_test_case conflicting_format }