From owner-svn-src-all@freebsd.org Sat Sep 19 20:15:52 2020 Return-Path: Delivered-To: svn-src-all@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 A17833EE23F; Sat, 19 Sep 2020 20:15:52 +0000 (UTC) (envelope-from bapt@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Bv25N3lWwz4Rkg; Sat, 19 Sep 2020 20:15:52 +0000 (UTC) (envelope-from bapt@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 64ECE11AC0; Sat, 19 Sep 2020 20:15:52 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 08JKFqqh060645; Sat, 19 Sep 2020 20:15:52 GMT (envelope-from bapt@FreeBSD.org) Received: (from bapt@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 08JKFpIU060641; Sat, 19 Sep 2020 20:15:51 GMT (envelope-from bapt@FreeBSD.org) Message-Id: <202009192015.08JKFpIU060641@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bapt set sender to bapt@FreeBSD.org using -f From: Baptiste Daroussin Date: Sat, 19 Sep 2020 20:15:51 +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: r365914 - in stable/12/usr.bin/diff: . tests X-SVN-Group: stable-12 X-SVN-Commit-Author: bapt X-SVN-Commit-Paths: in stable/12/usr.bin/diff: . tests X-SVN-Commit-Revision: 365914 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Sep 2020 20:15:52 -0000 Author: bapt Date: Sat Sep 19 20:15:51 2020 New Revision: 365914 URL: https://svnweb.freebsd.org/changeset/base/365914 Log: MFC r361688-r361690, r365041 r361688: Restore compatibility with GNU diff regarding --label Various options to "diff(1)" show filenames, and traditionally make use of the "--label" parameter, if set. Restore this behaviour in BSD diff. While here add a regression test PR: 244533 Submitted by: Jamie Landeg-Jones r361689: diff: restore compatibility with GNU diff regarding -N option When -N is used the missing files are treated as empty. PR: 233402 Submitted by: Fehmi Noyan Isi Reported by: Roman Neuhauser Differential Revision: D25081 r361690: Document long version of -b option PR: 234195 Submitted by: Fehmi Noyan Isi Reported by: Andras Farkas r365041: diff: always properly kill pr(1) When diff is invoked with -l it will spawn the pr(1) program. In some circumpstances the pr(1) was not properly killed when diff program exits. Submitted by: Bret Ketchum Differential Revision: https://reviews.freebsd.org/D26232 Modified: stable/12/usr.bin/diff/diff.1 stable/12/usr.bin/diff/diff.c stable/12/usr.bin/diff/diffreg.c stable/12/usr.bin/diff/tests/diff_test.sh Directory Properties: stable/12/ (props changed) Modified: stable/12/usr.bin/diff/diff.1 ============================================================================== --- stable/12/usr.bin/diff/diff.1 Sat Sep 19 20:06:30 2020 (r365913) +++ stable/12/usr.bin/diff/diff.1 Sat Sep 19 20:15:51 2020 (r365914) @@ -30,7 +30,7 @@ .\" @(#)diff.1 8.1 (Berkeley) 6/30/93 .\" $FreeBSD$ .\" -.Dd April 27, 2020 +.Dd June 1, 2020 .Dt DIFF 1 .Os .Sh NAME @@ -330,7 +330,7 @@ Use of this option forces to produce a diff. .It Fl B Fl -ignore-blank-lines Causes chunks that include only blank lines to be ignored. -.It Fl b +.It Fl b -ignore-space-change Causes trailing blanks (spaces and tabs) to be ignored, and other strings of blanks to compare equal. .It Fl d -minimal Modified: stable/12/usr.bin/diff/diff.c ============================================================================== --- stable/12/usr.bin/diff/diff.c Sat Sep 19 20:06:30 2020 (r365913) +++ stable/12/usr.bin/diff/diff.c Sat Sep 19 20:15:51 2020 (r365914) @@ -27,6 +27,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -351,13 +352,33 @@ main(int argc, char **argv) if (strcmp(argv[0], "-") == 0) { fstat(STDIN_FILENO, &stb1); gotstdin = 1; - } else if (stat(argv[0], &stb1) != 0) - err(2, "%s", argv[0]); + } else if (stat(argv[0], &stb1) != 0) { + if (!Nflag || errno != ENOENT) + err(2, "%s", argv[0]); + dflags |= D_EMPTY1; + memset(&stb1, 0, sizeof(struct stat)); + } + if (strcmp(argv[1], "-") == 0) { fstat(STDIN_FILENO, &stb2); gotstdin = 1; - } else if (stat(argv[1], &stb2) != 0) - err(2, "%s", argv[1]); + } else if (stat(argv[1], &stb2) != 0) { + if (!Nflag || errno != ENOENT) + err(2, "%s", argv[1]); + dflags |= D_EMPTY2; + memset(&stb2, 0, sizeof(stb2)); + stb2.st_mode = stb1.st_mode; + } + + if (dflags & D_EMPTY1 && dflags & D_EMPTY2){ + warn("%s", argv[0]); + warn("%s", argv[1]); + exit(2); + } + + if (stb1.st_mode == 0) + stb1.st_mode = stb2.st_mode; + if (gotstdin && (S_ISDIR(stb1.st_mode) || S_ISDIR(stb2.st_mode))) errx(2, "can't compare - to a directory"); set_argstr(oargv, argv); @@ -465,6 +486,9 @@ print_only(const char *path, size_t dirlen, const char void print_status(int val, char *path1, char *path2, const char *entry) { + if (label[0] != NULL) path1 = label[0]; + if (label[1] != NULL) path2 = label[1]; + switch (val) { case D_BINARY: printf("Binary files %s%s and %s%s differ\n", Modified: stable/12/usr.bin/diff/diffreg.c ============================================================================== --- stable/12/usr.bin/diff/diffreg.c Sat Sep 19 20:06:30 2020 (r365913) +++ stable/12/usr.bin/diff/diffreg.c Sat Sep 19 20:15:51 2020 (r365914) @@ -412,10 +412,10 @@ diffreg(char *file1, char *file2, int flags, int capsi ixnew = xreallocarray(ixnew, len[1] + 2, sizeof(*ixnew)); check(f1, f2, flags); output(file1, f1, file2, f2, flags); - if (pr != NULL) - stop_pr(pr); closem: + if (pr != NULL) + stop_pr(pr); if (anychange) { status |= 1; if (rval == D_SAME) @@ -1704,4 +1704,4 @@ print_space(int nc, int n, int flags) { } } diff_output("%*s", col, ""); -} \ No newline at end of file +} Modified: stable/12/usr.bin/diff/tests/diff_test.sh ============================================================================== --- stable/12/usr.bin/diff/tests/diff_test.sh Sat Sep 19 20:06:30 2020 (r365913) +++ stable/12/usr.bin/diff/tests/diff_test.sh Sat Sep 19 20:15:51 2020 (r365914) @@ -10,8 +10,10 @@ atf_test_case side_by_side atf_test_case brief_format atf_test_case b230049 atf_test_case Bflag +atf_test_case Nflag atf_test_case tabsize atf_test_case conflicting_format +atf_test_case label simple_body() { @@ -164,6 +166,15 @@ Bflag_body() atf_check -s exit:1 -o file:"$(atf_get_srcdir)/Bflag_F.out" diff -B E F } +Nflag_body() +{ + atf_check -x 'printf "foo" > A' + + atf_check -s exit:1 -o ignore -e ignore diff -N A NOFILE + atf_check -s exit:1 -o ignore -e ignore diff -N NOFILE A + atf_check -s exit:2 -o ignore -e ignore diff -N NOFILE1 NOFILE2 +} + tabsize_body() { printf "\tA\n" > A @@ -195,6 +206,17 @@ conflicting_format_body() atf_check -s exit:1 -o ignore -e ignore diff --normal --normal A B } +label_body() +{ + printf "\tA\n" > A + + atf_check -o inline:"Files hello and world are identical\n" \ + -s exit:0 diff --label hello --label world -s A A + + atf_check -o inline:"Binary files hello and world differ\n" \ + -s exit:1 diff --label hello --label world `which diff` `which ls` +} + atf_init_test_cases() { atf_add_test_case simple @@ -207,6 +229,8 @@ atf_init_test_cases() atf_add_test_case brief_format atf_add_test_case b230049 atf_add_test_case Bflag + atf_add_test_case Nflag atf_add_test_case tabsize atf_add_test_case conflicting_format + atf_add_test_case label }