Commit Graph

80 Commits

Author SHA1 Message Date
Olivier Cochard
b67df8d7c2 diff: Use unprivileged_user with report_identical test
Approved by:	bapt
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D28466
2021-02-03 17:18:59 +01:00
Baptiste Daroussin
c69047ca75 Revert "diff: eliminate a useless lseek"
This changes breaks when one of the files is stdin

This reverts commit fa977a3b2b.

Reported by:	olivier
2021-02-02 10:08:25 +01:00
Baptiste Daroussin
7a57c9cb5a diff: eleminitate useless macros
The diff_output was not bringing any values but was obfuscating
the code.
2021-01-27 12:29:33 +01:00
Baptiste Daroussin
e43239f514 diff: simplify the hash functions
Instead of 3 different complex case they have all been folded into a
simple on based on switch
2021-01-27 12:28:26 +01:00
Baptiste Daroussin
e52546a3a7 diff: fix typo in a comment 2021-01-27 12:18:46 +01:00
Baptiste Daroussin
931ad51808 diff: remove stalled entries in headers 2021-01-27 12:18:45 +01:00
Baptiste Daroussin
15abb23286 diff: eliminate space at end of line
No functionnal changes
2021-01-27 12:18:45 +01:00
Baptiste Daroussin
fa977a3b2b diff: eliminate a useless lseek
fdopen with the "r" already position the stream at the beginning
of the file.
2021-01-27 12:18:45 +01:00
Baptiste Daroussin
c440e7870a diff: add a test case about the non regular file support 2021-01-27 12:18:45 +01:00
Jamie Landeg-Jones
fefb3c46a8 diff: fix incorrectly displaying files as duplicates
When diff hits certain access errors, function diffreg() shows the error
message, and then returns to the calling function, which calls
print_status() with the return value.

However, in these cases, the return value isn't changed from the initial
default value of D_SAME.

Normally, print_status() with a value of D_SAME does nothing, so this
works out ok, however, if the "-s" flag is set, a message is displayed
showing identicality:

case D_SAME:
                if (sflag)
                        printf("Files %s%s and %s%s are identical\n",                                                                                                       path1, entry, path2, entry);
                break;

This then produces such results as:

% diff  -s /COPYRIGHT /var/run/rpcbind.sock
diff: /var/run/rpcbind.sock: Operation not supported
Files /COPYRIGHT and /var/run/rpcbind.sock are identical

% diff  -s /COPYRIGHT /etc/master.passwd
diff: /etc/master.passwd: Permission denied
Files /COPYRIGHT and /etc/master.passwd are identical

Create a D_ERROR status which is returned in such cases, and
print_status() then deals with that status seperately from D_SAME

PR:		252614
MFC after:	1 week
2021-01-25 20:38:18 +01:00
Baptiste Daroussin
13860e71eb diff: add a test case for failed -s option 2021-01-25 20:37:58 +01:00
Ed Maste
12a8d3027d diff: honour flags with -q
Previously -q (just print a line when files differ) ignored flags like
-w (ignore whitespace).  Avoid the D_BRIEF short-circuit when flags are
in effect.

PR:		252515
Reported by:	Scott Aitken
Reviewed by:	kevans
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D28064
2021-01-09 13:34:06 -05:00
Kyle Evans
b0d30b27f0 diff: don't force the format to 'context' with -p immediately
Instead, leave the fomat as unspecified (if it hasn't been) and use the
-p flag as a hint to 'context' if no other formatting option is specified.

This fixes `diff -purw`, used frequently by emaste, and matches the behavior
of its GNU counterpart.

PR:		250015
Reviewed by:	emaste
MFC after:	1 week
2020-10-27 12:27:26 +00:00
Baptiste Daroussin
fb0d1c6980 diff: always properly kill pr(1)
When diff is invoked with -l it will spawn the pr(1) program.
In some circumpstances the pr(1) was not properly killed when diff program
exits.

Submitted by:	Bret Ketchum
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D26232
2020-09-01 14:52:39 +00:00
Kyle Evans
ac05de1788 diff: fix side_by_side after r363679
It's currently unclear to me how this could have worked previously; \n here
is not a literal newline but actual '\' 'n', and was getting passed to the
underlying regex engine as such. regex(3) does not translate this to a
newline, and this became an error because we don't really allow escaping
of arbitrary ordinary characters anymore.

Run the pattern strings through printf to make sure we're dealing with real
newlines before passing them through to atf_check, which ultimately feeds
them directly to regcomp(3).

This fix is different than that will be needed for sed, in that this is the
proper way to inject newlines into search strings as long as regex(3)
won't combine \ + n as folks might expect.

Reported by:	Jenkins via lwhsu
MFC after:	1 week
2020-07-30 13:33:45 +00:00
Fernando Apesteguía
204fa3b066 diff(1): Add EXAMPLES section
Add examples for -r, -u, -N, -x, -q and -I

Approved by:	0mp@
Differential Revision:	https://reviews.freebsd.org/D25345
2020-06-19 06:48:16 +00:00
Baptiste Daroussin
8ccef19395 Document long version of -b option
PR:		234195
Submitted by:	Fehmi Noyan Isi <fnoyanisi@yahoo.com>
Reported by:	Andras Farkas <deepbluemistake@gmail.com>
MFC after:	3 days
2020-06-01 09:15:15 +00:00
Baptiste Daroussin
2816b9998c diff: restore compatibility with GNU diff regarding -N option
When -N is used the missing files are treated as empty.

PR:		233402
Submitted by:	Fehmi Noyan Isi <fnoyanisi@yahoo.com>
Reported by:	Roman Neuhauser <roman@sigpipe.cz>
MFC after:	3 days
Differential Revision:	D25081
2020-06-01 09:09:36 +00:00
Baptiste Daroussin
f096ed981f Restore compatibility with GNU diff regarding --label
Various options to "diff(1)" show filenames, and traditionally make use of the
"--label" parameter, if set.

Restore this behaviour in BSD diff.

While here add a regression test

PR:		244533
Submitted by:	Jamie Landeg-Jones <jamie@catflap.org>
MFC after:	3 days
2020-06-01 09:01:13 +00:00
Kyle Evans
67c907653e diff(1): don't reject specifying the same format multiple times
This may happen, for instance, if one happens to have an alias of diff to
diff -up and attempts to specify the amount of context on top of that.

Aliases like this may cause other problems, but if they're really not ever
generating non-unified diffs then we should at least not break that
use-case.

In addition, we'll now pick up a format mismatch if -p is specified with
!contextual && !unified && !unset.

Fix up a small trailing whitespace nit in the tests while we're here, and
add tests to make sure that we can double up all the formatting options.

Reported by:	jbeich
MFC after:	3 days
2020-04-28 14:33:33 +00:00
Kyle Evans
db9cccfbb1 diff(1): reject conflicting formatting options
This matches GNU diff(1) behavior and, more importantly, eliminates any
source of confusion if multiple formatting options are specified.

Note that the committed diff differs slightly from the submitted: I've
modified it so that we initialize diff_format to something that isn't an
accepted format option so that we can also reject --normal -c and -c
--normal, which would've otherwise been accepted because the default was
--normal. After option parsing we default it to D_NORMAL if it's still
unset.

PR:		243975
Submitted by:	fehmi noyan isi
MFC after:	1 week
2020-04-20 16:14:44 +00:00
Kyle Evans
43fbd65451 diff: fix segfault with --tabsize and no/malformed argument
--tabsize was previously listed as optional_argument, but didn't account for
the optionality of it in the argument handling. This is irrelevant -- the
manpage doesn't indicate that the argument is optional, and indeed there's
no clear interpretation of omitting the argument because there's no other
side effect of --tabsize.

The "malformed" argument part of the header on this message is simply
referring to usage like this:

% diff --tabsize 4 A B

With an optional_argument, the argument must be attached to the parameter
directly (e.g. --tabsize=4), so the argument is effectively NULL with the
above invocation as if no argument had been passed.

PR:		243974
Submitted by:	fehmi noyan isi <fnoyanisi yahoo com> (diff.c portion)
MFC after:	3 days
2020-02-13 20:23:55 +00:00
Mateusz Piotrowski
469635f600 diff.1: Fix style & document -y as extension to POSIX
- Long options must be stylized with the Fl macro as well.

Reviewed by:	bapt
Approved by:	bcr (mentor)
Differential Revision:	https://reviews.freebsd.org/D23642
2020-02-12 20:06:41 +00:00
Baptiste Daroussin
79208b1025 Fix most of the style warnings 2020-02-07 12:26:38 +00:00
Baptiste Daroussin
89fd163c4e Update diff(1) TODO removing what has been implemented 2020-02-07 10:18:01 +00:00
Baptiste Daroussin
64793e748c diff: implement -y (--side-by-side) along with -W and --suppress-common-lines
PR:		219933
Submitted by:	fehmi noyan isi <fnoyanisi@yahoo.com>
MFC after:	3 weeks
2020-02-07 10:17:13 +00:00
Mark Johnston
7dddaa0979 Do not skip line-by-line comparison if -q and -I are specified.
This fixes a regression from r356695.

Submitted by:	kevans
Reported by:	Jenkins via lwhsu
MFC after:	6 days
2020-01-14 15:35:03 +00:00
Baptiste Daroussin
12d9c0dc55 When system calls indicate an error they return -1, not some arbitrary
value < 0.  errno is only updated in this case.

Obtained from:	OpenBSD
MFC after:	3 days
2020-01-14 08:22:28 +00:00
Baptiste Daroussin
f9eac42577 asprintf returns -1, not an arbitrary value < 0. Also upon error the
(very sloppy specification) leaves an undefined value in *ret, so it is
wrong to inspect it, the error condition is enough.

Obtained from:	OpenBSD
MFC after:	3 days
2020-01-14 08:18:04 +00:00
Baptiste Daroussin
a3337141a4 mkstemp returns -1
Obtained from:	OpenBSD
MFC after:	3 days
2020-01-14 08:16:15 +00:00
Mark Johnston
5248d3b1b2 Optimize diff -q.
Once we know whether the files differ, we don't need to do any further
work.

PR:		242828
Submitted by:	fehmi noyan isi <fnoyanisi@yahoo.com> (original version)
Reviewed by:	bapt, kevans
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D23152
2020-01-13 18:29:47 +00:00
Mariusz Zaborski
377421df96 capsicum: use a new capsicum helpers in tools
Use caph_{rights,ioctls,fcntls}_limit to simplify the code.
2018-11-04 19:24:49 +00:00
Kyle Evans
9488de009c diff(1): Refactor -B a little bit
Instead of doing a second pass to skip empty lines if we've specified -I, go
ahead and check both at once. Ignore critera has been split out into its own
function to try and keep the logic cleaner.
2018-08-19 04:15:38 +00:00
Kyle Evans
e68edb8cf0 diff(1): Implement -B/--ignore-blank-lines
As noted by cem in r338035, coccinelle invokes diff(1) with the -B flag.
This was not previously implemented here, so one was forced to create a link
for GNU diff to /usr/local/bin/diff

Implement the -B flag and add some primitive tests for it. It is implemented
in the same fashion that -I is implemented; each chunk's lines are scanned,
and if a non-blank line is encountered then the chunk will be output.
Otherwise, it's skipped.

MFC after:	2 weeks
2018-08-19 03:57:20 +00:00
Xin LI
9977c7b512 Improve --strip-trailing-cr handling:
- Advance ctold for f1 and ctnew for f2
 - ungetc() if the character is unexpected
 - Don't break early when we hit the combination on one side

PR:		230049
Reported by:	maskray <emacsray gmail com>
Reviewed by:	bapt, maskray
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D16451
2018-07-27 05:21:20 +00:00
Mariusz Zaborski
7672a0148f Convert cap_enter() < 0 && errno != ENOSYS to caph_enter() < 0.
No functional change intended.
2018-06-19 23:43:14 +00:00
Baptiste Daroussin
43d7b1c097 Fix memory leak
CID:		1393352
2018-06-12 16:42:11 +00:00
Baptiste Daroussin
5a43dca273 Correctly test return value of pipe(2)
CID:		1393351
2018-06-12 16:40:22 +00:00
Baptiste Daroussin
e620f7fb56 diff: Import fixes from OpenBSD
original commit log by miller@OpenBSD  r1.46:
Fix exit value when diffing directories with missing files and the -N
or -P options are not used.  From Ibrahim Khalifa
2018-06-09 21:09:24 +00:00
Baptiste Daroussin
6fa5bf0832 Isolate the pr(1) related code in its own source files
This keeps diffreg.c closer to what it is supposed to do:
diffing regular files.

It also allows my code to get a proper license
2018-06-09 20:24:17 +00:00
Baptiste Daroussin
0118df5ecf Replace homemade equivalent of tolower(3) by towlower(3)
This will help in the futur making diff -i works with multibyte
2017-12-13 16:09:00 +00:00
Pedro F. Giffuni
df57947f08 spdx: initial adoption of licensing ID tags.
The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.

Initially, only tag files that use BSD 4-Clause "Original" license.

RelNotes:	yes
Differential Revision:	https://reviews.freebsd.org/D13133
2017-11-18 14:26:50 +00:00
Bryan Drewery
3806950135 DIRDEPS_BUILD: Connect new directories.
Sponsored by:	Dell EMC Isilon
2017-10-31 00:04:07 +00:00
Enji Cooper
d511b20a69 Add HAS_TESTS to all Makefiles that are currently using the
`SUBDIR.${MK_TESTS}+= tests` idiom.

This is a follow up to r321912.
2017-08-02 08:50:42 +00:00
Enji Cooper
4b330699f8 Convert traditional ${MK_TESTS} conditional idiom for including test
directories to SUBDIR.${MK_TESTS} idiom

This is being done to pave the way for future work (and homogenity) in
^/projects/make-check-sandbox .

No functional change intended.

MFC after:	1 weeks
2017-08-02 08:35:51 +00:00
Enji Cooper
274b460b60 Use more flexible expression for replacing t_diff in
contrib/netbsd-tests/usr.bin/diff/t_diff.sh with the name of the script via
`basename $0`.

This was a change I forgot to port over from
^/head/gnu/usr.bin/diff/tests/Makefile@r272787.
2017-07-19 18:30:16 +00:00
Enji Cooper
4017abe27c Add tests that exercise -q, like -rq and add tests that test -q like -Nrq
MFC after:	2 months
MFC with:	r321076, r321077, r321078
2017-07-17 18:07:53 +00:00
Enji Cooper
2d920b13cb Fix exit status with -rq when there is a file in one directory but not another,
i.e., when print_only is called.

Prior to this change, -rq was always returning 0. After this change it will
return 1 if there is a difference between two directories.

This fixes compatibility with GNU diff and unbreaks backwards compatibility
expectations.

Found when trying to extend diff_test:brief_format_test.

MFC after:	2 months
MFC with:	r321076, r321077
2017-07-17 18:06:42 +00:00
Enji Cooper
4574a545d2 Add some tests for brief (--brief/-q) format
MFC after:	2 months
MFC with:	r321076
2017-07-17 17:50:50 +00:00
Enji Cooper
4d8c579095 Don't emit "diff: diff <options> arguments" when diffing files if
-q is specified.

This improves compatibility with GNU diff.

Found by accident with `diff -Nrq /usr/tests /usr/tests.new | grep Kyuafile`.

MFC after:	2 months
Relnotes:	yes
2017-07-17 17:36:04 +00:00