shithub: plan9front

Download patch

ref: cd7480f68f3496b84ae25f916c2d700fc5afb42f
parent: 160e36aaef907ac15bbda9af1f628b266a7568df
author: Kyle Milz <krwmilz@gmail.com>
date: Fri Nov 5 15:03:20 EDT 2021

diff: fix -u when comparing identical files

--- a/sys/src/cmd/diff/diff.h	Fri Nov  5 20:15:28 2021
+++ b/sys/src/cmd/diff/diff.h	Fri Nov  5 15:03:20 2021
@@ -22,6 +22,5 @@
 void panic(int, char *, ...);
 void check(Biobuf *, Biobuf *);
 void change(int, int, int, int);
-void fileheader(void);
 void flushchanges(void);
 
--- a/sys/src/cmd/diff/diffio.c	Fri Nov  5 20:15:28 2021
+++ b/sys/src/cmd/diff/diffio.c	Fri Nov  5 15:03:20 2021
@@ -267,16 +267,22 @@
 	if (a > b && c > d)
 		return;
 	anychange = 1;
-	if (mflag && firstchange == 0) {
-		if(mode) {
-			buf[0] = '-';
-			buf[1] = mode;
-			buf[2] = ' ';
-			buf[3] = '\0';
-		} else {
-			buf[0] = '\0';
+	if (firstchange == 0) {
+		if (mflag) {
+			if(mode) {
+				buf[0] = '-';
+				buf[1] = mode;
+				buf[2] = ' ';
+				buf[3] = '\0';
+			} else {
+				buf[0] = '\0';
+			}
+			Bprint(&stdout, "diff %s%s %s\n", buf, file1, file2);
+		}
+		if (mode == 'u') {
+			Bprint(&stdout, "--- %s\n", file1);
+			Bprint(&stdout, "+++ %s\n", file2);
 		}
-		Bprint(&stdout, "diff %s%s %s\n", buf, file1, file2);
 		firstchange = 1;
 	}
 	verb = a > b ? 'a': c > d ? 'd': 'c';
@@ -337,15 +343,6 @@
 	if(i<nchanges)
 		return i+1;
 	return nchanges;
-}
-
-void
-fileheader(void)
-{
-	if(mode != 'u')
-		return;
-	Bprint(&stdout, "--- %s\n", file1);
-	Bprint(&stdout, "+++ %s\n", file2);
 }
 
 void
--- a/sys/src/cmd/diff/diffreg.c	Fri Nov  5 20:15:28 2021
+++ b/sys/src/cmd/diff/diffreg.c	Fri Nov  5 15:03:20 2021
@@ -285,7 +285,6 @@
 	m = len[0];
 	J[0] = 0;
 	J[m+1] = len[1]+1;
-	fileheader();
 	if (mode != 'e') {
 		for (i0 = 1; i0 <= m; i0 = i1+1) {
 			while (i0 <= m && J[i0] == J[i0-1]+1)