Bug 278988 - diff -B -q: unintuitive or incorrect?
Summary: diff -B -q: unintuitive or incorrect?
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 14.0-STABLE
Hardware: amd64 Any
: --- Affects Many People
Assignee: Ed Maste
URL: https://reviews.freebsd.org/D45220
Keywords:
Depends on:
Blocks:
 
Reported: 2024-05-14 20:39 UTC by dhekir
Modified: 2024-06-07 21:16 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description dhekir 2024-05-14 20:39:05 UTC
I stumbled upon a very unintuitive behavior of diff: when option -q is used, -B is ignored, unless it is also accompanied by -b, as in the following examples

# create test files: one containing a single newline, another containing 2 newlines
$ echo "" > a
$ echo -e "\n" > b

$ diff a b -B # ok: no diff reported
$ diff a b -B -q # weird: -B seems ignored, diff reported (GNU diff does not report it)
$ diff a b -b # ok: -b only ignores spaces, not entire lines
$ diff a b -b -q # ok: the diff remains, -q does not affect it
$ diff a b -B -b -q # ok: this time, -B was taken into account

So, we have:

1. -B works on its own;
2. when -B -q is used, -B seems ignored;
3. -b on its own does not suffice to remove the diff in these files
4. -B -b -q works (no diff), but since -b is irrelevant without -q, this seems like a bug.

In GNU diff, `diff a b -B -q` behaves as what I consider "expected": the files are considered equal.

If this is intended behavior, the documentation needs to mention it.

Bug #252515 is similar to this one (it mentioned `-w`, while this one mentions `-B`).
Comment 1 dhekir 2024-05-15 08:12:02 UTC
I wonder if it would suffice to add D_SKIPBLANKLINES to the flags in https://reviews.freebsd.org/D28064.
Comment 2 commit-hook freebsd_committer freebsd_triage 2024-05-18 00:05:42 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=fb623aab3927a6825ff7731198ec2e33426f7607

commit fb623aab3927a6825ff7731198ec2e33426f7607
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2024-05-16 14:53:23 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2024-05-18 00:03:56 +0000

    diff: honour -B flag with -q

    PR:             278988
    Reviewed by:    bapt
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D45220

 usr.bin/diff/diffreg.c          |  3 ++-
 usr.bin/diff/tests/diff_test.sh | 11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
Comment 3 commit-hook freebsd_committer freebsd_triage 2024-05-25 00:00:03 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=1b7672ed992963e1c79ccc152f4afd72c91481f3

commit 1b7672ed992963e1c79ccc152f4afd72c91481f3
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2024-05-16 14:53:23 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2024-05-24 23:59:11 +0000

    diff: honour -B flag with -q

    PR:             278988
    Reviewed by:    bapt
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D45220

    (cherry picked from commit fb623aab3927a6825ff7731198ec2e33426f7607)

 usr.bin/diff/diffreg.c          |  3 ++-
 usr.bin/diff/tests/diff_test.sh | 10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
Comment 4 commit-hook freebsd_committer freebsd_triage 2024-06-07 21:16:22 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=12ea2d04c37982cabf7865e8897226c81aae4ab0

commit 12ea2d04c37982cabf7865e8897226c81aae4ab0
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2024-05-16 14:53:23 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2024-06-07 21:15:57 +0000

    diff: honour -B flag with -q

    PR:             278988
    Reviewed by:    bapt
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D45220

    (cherry picked from commit fb623aab3927a6825ff7731198ec2e33426f7607)
    (cherry picked from commit 1b7672ed992963e1c79ccc152f4afd72c91481f3)

 usr.bin/diff/diffreg.c          |  3 ++-
 usr.bin/diff/tests/diff_test.sh | 10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)