summaryrefslogtreecommitdiff
path: root/usr.bin/diff
AgeCommit message (Collapse)Author
2025-06-23libc: Rename fscandir{,_b}() to fdscandir{,_b}().Dag-Erling Smørgrav
This seems to fit the pattern better (e.g. fdopendir()). I've added weak references to ease the transition, but since it's only been a few days, we can remove them (and the ObsoleteFiles entries for the manual pages) before we branch stable/15. Fixes: deeebfdecab5 Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D50980
2025-06-20diff: Fix gcc build.Dag-Erling Smørgrav
Sponsored by: Klara, Inc.
2025-06-20diff: Whitespace nits.Dag-Erling Smørgrav
Sponsored by: Klara, Inc.
2025-06-20diff: Detect loops when diffing directories.Dag-Erling Smørgrav
Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D50936
2025-06-06diff: minor fixes to manual pagePau Amma
* Add missing dash before long option name in synopsis. * Remove spurious paragraph break and bullet item. * While there, fix mandoc -T lint complaints. Reviewed by: ziaee, des Differential Revision: https://reviews.freebsd.org/D48388
2024-12-23diff: Fix device case.Dag-Erling Smørgrav
We already fell back to Stone for FIFOs, but we actually need to fall back to Stone for everything except regular files, because libdiff's atomizer needs to know the size of its input in advance, and neither FIFOs nor devices can be trusted to report their size. MFC after: 1 week Reported by: mav Reviewed by: mav, allanjude Differential Revision: https://reviews.freebsd.org/D48181
2024-10-02libdiff: Implement diff coloring.Dag-Erling Smørgrav
This patch got accidentally left out when libdiff was imported. The rest of the code (command-line option etc.) was present, just not the part that actually prints ANSI color codes. Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D46873
2024-07-29diff: Fix integer overflow.Dag-Erling Smørgrav
The legacy Stone algorithm uses `int` to represent line numbers, array indices, and array lengths. If given inputs approaching `INT_MAX` lines, it would overflow and attempt to allocate ridiculously large amounts of memory. To avoid this without penalizing non-pathological inputs, switch a few variables to `size_t` and add checks while and immediately after reading both inputs. MFC after: 3 days PR: 280371 Sponsored by: Klara, Inc. Reviewed by: allanjude Differential Revision: https://reviews.freebsd.org/D46169
2024-07-29diff: Fix usage message and documentation.Dag-Erling Smørgrav
The `--ignore-all-space` option was incorrectly documented as `--ignore-all-blanks` in some (but not all) places. MFC after: 3 days PR: 280434 Sponsored by: Klara, Inc. Reviewed by: 0mp, markj Differential Revision: https://reviews.freebsd.org/D46160
2024-07-15Remove residual blank line at start of MakefileWarner Losh
This is a residual of the $FreeBSD$ removal. MFC After: 3 days (though I'll just run the command on the branches) Sponsored by: Netflix
2024-06-30diff: Document the --no-dereference option.Dag-Erling Smørgrav
Also, --no-dereference should not imply --recurse. MFC after: 3 days Sponsored by: Klara, Inc. Reviewed by: allanjude Differential Revision: https://reviews.freebsd.org/D45779
2024-05-20diff: Nits in tests.Dag-Erling Smørgrav
Sponsored by: Klara, Inc.
2024-05-20diff: Warn if the atomizer detected truncation.Dag-Erling Smørgrav
Sponsored by: Klara, Inc. Reviewed by: allanjude, markj Differential Revision: https://reviews.freebsd.org/D45219
2024-05-17diff: honour -B flag with -qEd Maste
PR: 278988 Reviewed by: bapt Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D45220
2024-05-03diff: Sort headers.Dag-Erling Smørgrav
MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D45078
2024-04-19diff: use getline() instead of fgetln()Martin Tournoij
This replaces fgetln() with getline(). The main reason for this is portability, making things easier for people who want to compile these tools on non-FreeBSD systems. I appreciate that's probably not the top concern for FreeBSD base tools, but fgetln() is impossible to port to most platforms, as concurrent access is essentially impossible to implement fully correct without the line buffer on the FILE struct. Other than this, many generic FreeBSD tools compile fairly cleanly on Linux with a few small changes. Most uses of fgetln() pre-date getline() support (added in 2009 with 69099ba2ec8b), and there's been some previous patches (ee3ca711a898 8c98e6b1a7f3 1a2a4fc8ce1b) for other tools. Obtained from: https://github.com/dcantrell/bsdutils and https://github.com/chimera-linux/chimerautils Signed-off-by: Martin Tournoij <martin@arp242.net> Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/893
2024-03-27diff: Integrate libdiff from OpenBSD GoT.Dag-Erling Smørgrav
This adds support for two new diff algorithms, Myers diff and Patience diff. These algorithms perform a different form of search compared to the classic Stone algorithm and support escapes when worst case scenarios are encountered. Add the -A flag to allow selection of the algorithm, but default to using the new Myers diff implementation. The libdiff implementation currently only supports a subset of input and output options supported by diff. When these options are used, but the algorithm is not selected, automatically fallback to the classic Stone algorithm until support for these modes can be added. Based on work originally done by thj@ with contributions from kevans@. Sponsored by: Klara, Inc. Reviewed by: thj Differential Revision: https://reviews.freebsd.org/D44302
2024-03-19diff: Improve history section.Dag-Erling Smørgrav
Reviewed by: gbe Differential Revision: https://reviews.freebsd.org/D44409
2024-03-15diff(1) add FreeBSD HISTORYDavid E. O'Brien
2024-02-26diff: Bump manual page date.Dag-Erling Smørgrav
Sponsored by: Klara, Inc.
2024-02-26diff: Fix --expand-tabs and --side-by-side.Dag-Erling Smørgrav
* Overhaul column width and padding calculation. * Rewrite print_space() so it is now a) correct and b) understandable. * Rewrite tab expansion in fetch() for the same reason. This brings us in line with GNU diff for all cases I could think of. Sponsored by: Klara, Inc. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D44014
2023-12-26diff(1): fix a typoPin-Yi Kuo
On the manpage of diff(1), "when" is mistyped to "wen". Event: Advanced UNIX Programming Course (Fall'23) at NTHU. Signed-off-by: Pin-Yi Kuo <kuokuoyiyi@gapp.nthu.edu.tw> Reviewed by: imp, zlei Pull Request: https://github.com/freebsd/freebsd-src/pull/943
2023-11-26usr.bin: Automated cleanup of cdefs and other formattingWarner Losh
Apply the following automated changes to try to eliminate no-longer-needed sys/cdefs.h includes as well as now-empty blank lines in a row. Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/ Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/ Remove /\n+#if.*\n#endif.*\n+/ Remove /^#if.*\n#endif.*\n/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/ Sponsored by: Netflix
2023-11-26usr.bin: Remove ancient SCCS tags.Warner Losh
Remove ancient SCCS tags from the tree, automated scripting, with two minor fixup to keep things compiling. All the common forms in the tree were removed with a perl script. Sponsored by: Netflix
2023-08-16Remove $FreeBSD$: one-line nroff patternWarner Losh
Remove /^\.\\"\s*\$FreeBSD\$$\n/
2023-08-16Remove $FreeBSD$: one-line sh patternWarner Losh
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16Remove $FreeBSD$: one-line .c patternWarner Losh
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16Remove $FreeBSD$: one-line .h patternWarner Losh
Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
2023-08-16Remove $FreeBSD$: two-line .h patternWarner Losh
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-06-20diff: Fully comment out the jackpot variable.John Baldwin
This fixes a set but unused warning.
2022-12-13diff: restyle loop a bitKyle Evans
This is a bit more readable, and this loop is probably unlikely to gain any `continue` or `break`s. Suggested by: pstef Differential Revision: https://reviews.freebsd.org/D37676
2022-12-13diff: fix side-by-side output with tabbed inputKyle Evans
The previous logic conflated some things... in this block: - j: input characters rendered so far - nc: number of characters in the line - col: columns rendered so far - hw: column width ((h)ard (w)idth?) Comparing j to hw or col to nc are naturally wrong, as col and hw are limits on their respective counters and nc is already brought down to hw if the input line should be truncated to start with. Right now, we end up easily truncating lines with tabs in them as we count each tab for $tabwidth lines in the input line, but we really should only be accounting for them in the column count. The problem is most easily demonstrated by the two input files added for the tests, the two tabbed lines lose at least a word or two even though there's plenty of space left in the row for each side. Reviewed by: bapt, pstef Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D37676
2022-11-15diff: Don't (ab)use sprintf() as a kind of strcat().John Baldwin
Previously print_header() used sprintf() of a buffer to itself as a kind of string builder but without checking for overflows. This raised -Wformat-truncation and -Wrestrict warnings in GCC. Instead, just conditionally print the new timestamp fields after the initial strftime()-formatted string. While here, use sizeof(buf) with strftime() rather than a magic number. Reviewed by: bapt Differential Revision: https://reviews.freebsd.org/D36814
2022-11-15diff: Don't treat null characters like carriage returns in readhash().John Baldwin
The implicit fall-through in the !D_FORCEASCII case caused null characters to be treated as carriage returns honoring the D_STRIPCR, D_FOLDBLANKS, and D_IGNOREBLANKS flags. Reported by: GCC -Wimplicit-fallthrough Reviewed by: bapt Fixes: 3cbf98e2bee9 diff: read whole files to determine if they are ASCII text Differential Revision: https://reviews.freebsd.org/D36813
2022-10-03diff: Fix a use after free as well as a memory leak in change().John Baldwin
When -B or -I are used, change() evaluates the lines in a hunk to determine if it is a hunk that should be ignored. It does this by reading each candidate line into a mallocated buffer via preadline() and then calling ignoreline(). Previously the buffer was freed as a side effect of ignoreline_pattern() called from ignoreline(). However, if only -B was specified, then ignoreline_pattern() was not called and the lines were leaked. If both options were specified, then ignoreline_pattern() was called before checking for a blank line so that the second check was a use after free. To fix, pull the free() out of ignoreline_pattern() and instead do it up in change() so that is paired with preadline(). While here, simplify ignoreline() by checking for the -B and -I cases individually without a separate clause for when both are set. Also, do the cheaper check (-B) first, and remove a false comment (this function is only called if at least one of -I or -B are specified). Reviewed by: emaste Reported by: GCC 12 -Wuse-after-free Differential Revision: https://reviews.freebsd.org/D36822
2022-04-18diff: tests: loosen up requirements for report_identicalKyle Evans
This test cannot run without an unprivileged_user being specified anyways, so just run as the unprivileged user. Revoking read permisions works just as well if you're guaranteed non-root. Reviewed by: pstef Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D34950
2022-03-10diff: Re-add void argument to usageTom Jones
Previous commit (8cf449db88b2c7a505bc241a78f9736b43f2ede5) unintentionally dropped the 'void' argument to usage, reinstate it. Sponsored by: Klara Inc.
2022-03-10diff: add support for --help and --versionTom Jones
Add support for --help and --version to be compatible with gnu diff. gnu diff --help writes to stdout, do the same to be compatible Reviewed by: bapt, pstef, debrup, Pau Amma Sponsored by: Klara Inc. Differential Revision: https://reviews.freebsd.org/D34508
2022-03-09diff: set cflag when passed to diffTom Jones
In b5541f456d641d23e0c46874daff0b62552bf3cb when flags were converted to be boolean, the setting of cflag as an integer was removed, but no boolean set was added. This effects the output format of dates, but the context type was set to D_CONTEXT so other functionality worked. Reviewed by: bapt Sponsored by: Klara Inc. Differential Revision: https://reviews.freebsd.org/D34481
2022-03-04Fix indentation in usr.bin/diff/pr.cDimitry Andric
In commit 6fa5bf0832ef the pr(1) related code in diff was moved around, but some part of the indentation was messed up, and one line was duplicated. Remove the duplicated line, and fix up the indentation. Reviewed by: bapt MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D34398
2022-03-02Revert "Temporarily skip usr.bin.diff.diff_test.functionname in CI"Li-Wen Hsu
This reverts commit 85eeb6ea62d45c5df893a16b87969bd7313a3dbb. The issue has been fixed by 4be7d087c2b566f4910683836be279d55c1a81c6. PR: 262086
2022-03-01diff: Use start of change when searching for functionTom Jones
Use the start of change when searching for a function rather than the start of the context. In short functions if this could result in search for the function name starting from before the function definition. PR: 262086 Reviewed by: bapt, mckusick, mhorne Sponsored by: Klara Inc. Differential Revision: https://reviews.freebsd.org/D34328
2022-02-21Temporarily skip usr.bin.diff.diff_test.functionname in CILi-Wen Hsu
PR: 262086 Sponsored by: The FreeBSD Foundation
2022-02-18diff: fix failed compare when ignoring file caseTom Jones
With --ignore-file-name-case we need to compare files regardless of case. We need to propigate both names down to diffit so we can look up the correct file when the names differ based on case, otherwise we try to look up the file using the case from the a tree which might not be discoverable if its case is different in the b tree. Reviewed by: bapt Sponsored by: Klara Inc. Differential Revision: https://reviews.freebsd.org/D34201
2022-02-18Remove surplus check for which diff is being testedTom Jones
Must have left this when I was testing the test invocation for 8f79bd9b85716c495c2741ac25db37e8d71f22f7 Pointy hat: thj Sponsored by: Klara Inc.
2022-02-18diff: add --no-dereference flagTom Jones
When diffing files and directories, don't follow symbolic links, instead compare where the links point to. Reviewed by: bapt Sponsored by: Klara Inc. Differential Revision: https://reviews.freebsd.org/D34203
2022-02-18diff: Detect Objective-C methodsTom Jones
When searching back for function definitions, consider lines starting with '+' and '-', this allows us to pick up Objective-C methods as well as C style function definitions. Reviewed by: bapt Sponsored by: Klara Inc. Differential Revision: https://reviews.freebsd.org/D34202
2021-10-07diff: consider two files with same inodes as identicalMariusz Zaborski
Obtained from: OpenBSD MFC after: 1 week
2021-09-16diff: link with libm for sqrt()Piotr Pawel Stefaniak
Reported by: Jenkins Fixes: bcf2e78dc48378456798191f1c15cb76d6221a65
2021-09-16diff: implement option -F (--show-function-line)Piotr Pawel Stefaniak
With unified and context diffs, show the last line that matches the provided pattern before the context. Reviewed by: bapt Differential Revision: https://reviews.freebsd.org/D31714