Created attachment 223468 [details] patch I was wondering why a "diff -rq" on FreeBSD-12 (BSD diff) ran endlessly while on FreeBSD-11 (GNU diff) it terminated in 0.6 seconds. This is because BSD diff compares files and dirs even if they are the same. I checked what GNU diff does in this case and added the corresponding code to diffdir() and diffreg(). The style is probably considered bad ;-).
Created attachment 258071 [details] patches for diff ^Triage: rebase patch.
Does this still occur with the new diff(1) implementation in 15 and 16?
I don't have access to machines running 15 or 16 so I can't test. I tried to build the new diff on a 14-STABLE box but failed due to missing fdscandir() in libc. But it probably can be tested easily by anyone on 15 or 16 by comparing a big dir with itself -- e.g. somthing like diff -rq /usr/src /usr/src If this does not return immediately, the problem is still there.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=590126789c841d80655869bc075c8980c173dd1c commit 590126789c841d80655869bc075c8980c173dd1c Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2026-02-05 14:39:57 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2026-02-05 14:39:57 +0000 diff: Don't compare a file or directory to itself While here, stop abusing struct dirent for something we don't even need to store. PR: 254455 MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: thj, kevans Differential Revision: https://reviews.freebsd.org/D55113 usr.bin/diff/diffdir.c | 14 ++++++-------- usr.bin/diff/diffreg.c | 3 +++ usr.bin/diff/tests/diff_test.sh | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-)
A commit in branch stable/15 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=5fdcdf4a7ed53bb1e49cd627a0ebeaf3751a7f0b commit 5fdcdf4a7ed53bb1e49cd627a0ebeaf3751a7f0b Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2026-02-05 14:39:57 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2026-02-10 14:24:08 +0000 diff: Don't compare a file or directory to itself While here, stop abusing struct dirent for something we don't even need to store. PR: 254455 MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: thj, kevans Differential Revision: https://reviews.freebsd.org/D55113 (cherry picked from commit 590126789c841d80655869bc075c8980c173dd1c) diff: Fix build rc must be defined first. Fixes: 590126789c84 MFC after: 1 week X-MFC with: 590126789c84 (cherry picked from commit ee44ab936e84bacaa49847d36aabdf280f9fecce) usr.bin/diff/diffdir.c | 16 ++++++++-------- usr.bin/diff/diffreg.c | 3 +++ usr.bin/diff/tests/diff_test.sh | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-)
A commit in branch stable/14 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=7f412c6f88edc3aafb53a83f1743ad49da4679a9 commit 7f412c6f88edc3aafb53a83f1743ad49da4679a9 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2026-02-05 14:39:57 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2026-02-10 14:24:19 +0000 diff: Don't compare a file or directory to itself While here, stop abusing struct dirent for something we don't even need to store. PR: 254455 MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: thj, kevans Differential Revision: https://reviews.freebsd.org/D55113 (cherry picked from commit 590126789c841d80655869bc075c8980c173dd1c) diff: Fix build rc must be defined first. Fixes: 590126789c84 MFC after: 1 week X-MFC with: 590126789c84 (cherry picked from commit ee44ab936e84bacaa49847d36aabdf280f9fecce) usr.bin/diff/diffdir.c | 16 ++++++++-------- usr.bin/diff/diffreg.c | 3 +++ usr.bin/diff/tests/diff_test.sh | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-)
A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=9c99eacbc33b357a0f80603b2e17c927a689fa78 commit 9c99eacbc33b357a0f80603b2e17c927a689fa78 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2026-02-05 14:39:57 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2026-02-10 15:36:24 +0000 diff: Don't compare a file or directory to itself While here, stop abusing struct dirent for something we don't even need to store. PR: 254455 MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: thj, kevans Differential Revision: https://reviews.freebsd.org/D55113 (cherry picked from commit 590126789c841d80655869bc075c8980c173dd1c) diff: Fix build rc must be defined first. Fixes: 590126789c84 MFC after: 1 week X-MFC with: 590126789c84 (cherry picked from commit ee44ab936e84bacaa49847d36aabdf280f9fecce) usr.bin/diff/diffdir.c | 14 ++++++++------ usr.bin/diff/diffreg.c | 3 +++ usr.bin/diff/tests/diff_test.sh | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-)
A commit in branch releng/14.4 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=b4139147bbb7e368316bee86ffac0fdb79319839 commit b4139147bbb7e368316bee86ffac0fdb79319839 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2026-02-05 14:39:57 +0000 Commit: Colin Percival <cperciva@FreeBSD.org> CommitDate: 2026-02-11 06:14:30 +0000 diff: Don't compare a file or directory to itself While here, stop abusing struct dirent for something we don't even need to store. Approved by: re (cperciva) PR: 254455 MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: thj, kevans Differential Revision: https://reviews.freebsd.org/D55113 (cherry picked from commit 590126789c841d80655869bc075c8980c173dd1c) diff: Fix build rc must be defined first. Fixes: 590126789c84 MFC after: 1 week X-MFC with: 590126789c84 (cherry picked from commit ee44ab936e84bacaa49847d36aabdf280f9fecce) (cherry picked from commit 7f412c6f88edc3aafb53a83f1743ad49da4679a9) usr.bin/diff/diffdir.c | 16 ++++++++-------- usr.bin/diff/diffreg.c | 3 +++ usr.bin/diff/tests/diff_test.sh | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-)