git: c30a321a61ce - main - diff: support -qq to output absolutely nothing
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 14 Oct 2026 19:41:40 UTC
The branch main has been updated by allanjude:
URL: https://cgit.FreeBSD.org/src/commit/?id=c30a321a61ce7e1c03d4c314b2127b37f75564c6
commit c30a321a61ce7e1c03d4c314b2127b37f75564c6
Author: Allan Jude <allanjude@FreeBSD.org>
AuthorDate: 2024-09-20 15:30:58 +0000
Commit: Allan Jude <allanjude@FreeBSD.org>
CommitDate: 2026-10-14 19:41:34 +0000
diff: support -qq to output absolutely nothing
This is similar to `cmp -s`, but can be combined with:
-B --ignore-blank-lines
-b --ignore-space-change
-w --ignore-all-space
To only report a difference if it doesn't involve whitespace
Reviewed by: des, bapt, markj (previous version), ziaee (man page)
MFC after: 1 week
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D46717
---
usr.bin/diff/diff.1 | 5 ++++-
usr.bin/diff/diff.c | 13 ++++++++++---
usr.bin/diff/diff.h | 1 +
usr.bin/diff/diffreg.c | 7 +++++--
4 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/usr.bin/diff/diff.1 b/usr.bin/diff/diff.1
index 47f9c11eb3db..791945cc28b0 100644
--- a/usr.bin/diff/diff.1
+++ b/usr.bin/diff/diff.1
@@ -30,7 +30,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd January 7, 2025
+.Dd October 12, 2026
.Dt DIFF 1
.Os
.Sh NAME
@@ -319,6 +319,9 @@ This is the form used by rcsdiff.
.It Fl q -brief
Just print a line when the files differ.
Does not output a list of changes.
+Specify twice
+.Pq Fl qq
+to output nothing at all, for when you only want to examine the exit code.
.It Fl U Ar number Fl -unified Ar number
Like
.Fl u
diff --git a/usr.bin/diff/diff.c b/usr.bin/diff/diff.c
index b5fa12268bac..cf3e4ec1f11a 100644
--- a/usr.bin/diff/diff.c
+++ b/usr.bin/diff/diff.c
@@ -276,7 +276,12 @@ main(int argc, char **argv)
case 'q':
if (FORMAT_MISMATCHED(D_BRIEF))
conflicting_format();
- diff_format = D_BRIEF;
+ if (diff_format == D_BRIEF) {
+ diff_format = D_QUIET;
+ /* If already D_QUIET, avoid getting more verbose. */
+ } else if (diff_format != D_QUIET) {
+ diff_format = D_BRIEF;
+ }
break;
case 'S':
start = optarg;
@@ -474,8 +479,10 @@ main(int argc, char **argv)
if (stat(argv[1], &stb2) == -1)
err(2, "%s", argv[1]);
}
- print_status(diffreg(argv[0], argv[1], dflags, 1), argv[0],
- argv[1], "");
+
+ if (diff_format != D_QUIET)
+ print_status(diffreg(argv[0], argv[1], dflags, 1),
+ argv[0], argv[1], "");
}
if (fflush(stdout) != 0)
err(2, "stdout");
diff --git a/usr.bin/diff/diff.h b/usr.bin/diff/diff.h
index fe41e8746f4d..7d9e864b2434 100644
--- a/usr.bin/diff/diff.h
+++ b/usr.bin/diff/diff.h
@@ -50,6 +50,7 @@
#define D_BRIEF 6 /* Say if the files differ */
#define D_GFORMAT 7 /* Diff with defined changed group format */
#define D_SIDEBYSIDE 8 /* Side by side */
+#define D_QUIET 9 /* Don't output anything */
#define D_UNSET -2
diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c
index 5c1147bf2730..2ded8382de50 100644
--- a/usr.bin/diff/diffreg.c
+++ b/usr.bin/diff/diffreg.c
@@ -415,7 +415,8 @@ diffreg_stone(char *file1, char *file2, int flags, int capsicum)
goto closem;
}
- if (diff_format == D_BRIEF && ignore_pats == NULL &&
+ if ((diff_format == D_BRIEF || diff_format == D_QUIET) &&
+ ignore_pats == NULL &&
(flags & (D_FOLDBLANKS|D_IGNOREBLANKS|D_IGNORECASE|
D_SKIPBLANKLINES|D_STRIPCR)) == 0)
{
@@ -1107,7 +1108,8 @@ restart:
return;
}
proceed:
- if (*pflags & D_HEADER && diff_format != D_BRIEF) {
+ if ((*pflags & D_HEADER) != 0 &&
+ diff_format != D_BRIEF && diff_format != D_QUIET) {
printf("%s %s %s\n", diffargs, file1, file2);
*pflags &= ~D_HEADER;
}
@@ -1156,6 +1158,7 @@ proceed:
anychange = 1;
switch (diff_format) {
case D_BRIEF:
+ case D_QUIET:
return;
case D_NORMAL:
case D_EDIT: