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: