svn commit: r365914 - in stable/12/usr.bin/diff: . tests

Baptiste Daroussin bapt at FreeBSD.org
Sat Sep 19 20:15:52 UTC 2020


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 <jamie at catflap.org>
  
  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 <fnoyanisi at yahoo.com>
  Reported by: Roman Neuhauser <roman at sigpipe.cz>
  Differential Revision: D25081
  
  r361690:
  Document long version of -b option
  
  PR:  234195
  Submitted by: Fehmi Noyan Isi <fnoyanisi at yahoo.com>
  Reported by: Andras Farkas <deepbluemistake at gmail.com>
  
  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 <ctype.h>
 #include <err.h>
+#include <errno.h>
 #include <getopt.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -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
 }


More information about the svn-src-all mailing list