diff --git a/usr.bin/diff3/diff3.1 b/usr.bin/diff3/diff3.1 index 22e04b6af5e8..2cf1e57cb74e 100644 --- a/usr.bin/diff3/diff3.1 +++ b/usr.bin/diff3/diff3.1 @@ -1,206 +1,213 @@ .\" $OpenBSD: diff3.1,v 1.7 2007/05/31 19:20:09 jmc Exp $ .\" .\" Copyright (c) 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)diff3.1 8.2 (Berkeley) 4/18/94 .\" $FreeBSD$ .\" -.Dd May 25, 2017 +.Dd August 23, 2021 .Dt DIFF3 1 .Os .Sh NAME .Nm diff3 .Nd 3-way differential file comparison .Sh SYNOPSIS .Nm diff3 -.Op Fl 3aEeiXx +.Op Fl 3aEeiTXx .Op Fl Fl diff-program Ar program .Op Fl Fl strip-trailing-cr .Op Fl L | Fl Fl label Ar label1 .Op Fl L | Fl Fl label Ar label2 .Op Fl L | Fl Fl label Ar label3 .Ar file1 file2 file3 .Sh DESCRIPTION The .Nm utility compares the contents of three different versions of a file, .Ar file1 , .Ar file2 and .Ar file3 , writing the result to the standard output. The options describe different methods of merging and purging the separate versions into a new file. .Nm is used by .Xr rcs 1 to merge specific versions or create new versions. .Pp The options are as follows: .Bl -tag -width "-E, -X" .It Fl 3 , Fl Fl easy-only Produces an output script suitable for .Xr ed 1 with changes specific only to .Ar file3 . .It Fl a , Fl Fl text Treat all files as ASCII. .It Fl E , Fl Fl show-overlap .It Fl X Similar to .Fl e and .Fl x , respectively, but treat overlapping changes (i.e., changes that would be noted with ==== in the normal listing) differently. The overlapping lines from both files will be inserted by the edit script, bracketed by "<<<<<<" and ">>>>>>" lines. .It Fl e , Fl Fl ed Produces output in a form suitable as an input script for the .Xr ed 1 utility. The script may then be used to merge differences common between all three files and differences specific to .Ar file1 and .Ar file3 . In other words, the .Fl e option ignores differences specific to .Ar file1 and .Ar file2 , and those specific to .Ar file2 and .Ar file3 . It is useful for backing out changes specific to .Ar file2 only. .It Fl i Appends 'w' and 'q' .Xr ed 1 commands. .It Fl L , Fl Fl label Defines labels to print instead of file names .Ar file1 , .Ar file2 and .Ar file3 . +.It Fl T, Fl Fl initial-tab +In the normal listing, +use a tab instead of two spaces +at the beginning of each line. +In modes that produce an +.Xr ed 1 +script, this option changes nothing. .It Fl x, Fl Fl overlap-only Produces an output script suitable for .Xr ed 1 with changes specific only to all three versions. .It Fl Fl diff-program Ar program Use .Ar program instead of the default .Xr diff 1 to compare files. .It Fl Fl strip-trailing-cr Strip trailing carriage return on input files. .El .Pp The .Fl E option is used by .Tn RCS .Xr merge 1 to ensure that overlapping changes in the merged files are preserved and brought to someone's attention. .Pp For example, suppose lines 7-8 are changed in both .Ar file1 and .Ar file2 . Applying the edit script generated by the command .Pp .Dl $ diff3 -E file1 file2 file3 .Pp to .Ar file1 results in the file: .Bd -literal -offset indent lines 1-6 of file1 <<<<<<< file1 lines 7-8 of file1 ======= lines 7-8 of file3 >>>>>>> file3 rest of file1 .Ed .Pp The default output of .Nm makes notation of the differences between all files, and those differences specific to each pair of files. The changes are described by the commands necessary for .Xr ed 1 to create the desired target from the different versions. See .Xr diff 1 for a description of the commands. .Bl -tag -width "=====" .It Li \&==== The lines beneath this notation are ranges of lines which are different between all files. .It \&==== Ns Va n The lines beneath this notation are ranges of lines which are exclusively different in file .Va n . .El .Sh SEE ALSO .Xr diff 1 , .Xr ed 1 , .Xr merge 1 , .Xr rcs 1 , .Xr sdiff 1 .Sh HISTORY A .Nm command appeared in .At v7 . .Sh BUGS The .Fl e option cannot catch and change lines which have .Ql \&. as the first and only character on the line. The resulting script will fail on that line as .Ql \&. is an .Xr ed 1 editing command. diff --git a/usr.bin/diff3/tests/1t.out b/usr.bin/diff3/tests/1t.out new file mode 100644 index 000000000000..fc54ce50286f --- /dev/null +++ b/usr.bin/diff3/tests/1t.out @@ -0,0 +1,14 @@ +==== +1:2,3c + which multiple lines + and a few typ0s to fix +2:2,3c + which multiple lines + and a few typos to fix +3:2c + and a few typ0s to fix +====2 +1:4a +3:3a +2:5c + New line diff --git a/usr.bin/diff3/tests/Makefile b/usr.bin/diff3/tests/Makefile index 2ec7fbaab564..b8bea154944b 100644 --- a/usr.bin/diff3/tests/Makefile +++ b/usr.bin/diff3/tests/Makefile @@ -1,22 +1,23 @@ # $FreeBSD$ PACKAGE= tests ATF_TESTS_SH= diff3_test ${PACKAGE}FILES+= \ 1.txt \ 1cr.txt \ 2.txt \ 3.txt \ 1.out \ + 1t.out \ 2.out \ 3.out \ 4.out \ 5.out \ 6.out \ 7.out \ 8.out \ 9.out .include diff --git a/usr.bin/diff3/tests/diff3_test.sh b/usr.bin/diff3/tests/diff3_test.sh index f4b5adf95700..64031b023187 100755 --- a/usr.bin/diff3/tests/diff3_test.sh +++ b/usr.bin/diff3/tests/diff3_test.sh @@ -1,49 +1,52 @@ # $FreeBSD$ atf_test_case diff3 atf_test_case diff3_lesssimple diff3_body() { atf_check -o file:$(atf_get_srcdir)/1.out \ diff3 $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt atf_check -o file:$(atf_get_srcdir)/1.out \ diff3 --strip-trailing-cr $(atf_get_srcdir)/1cr.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt + atf_check -o file:$(atf_get_srcdir)/1t.out \ + diff3 -T $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt + atf_check -o file:$(atf_get_srcdir)/2.out \ diff3 -e $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt atf_check -o file:$(atf_get_srcdir)/3.out \ diff3 -E -L 1 -L 2 -L 3 $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt atf_check -o file:$(atf_get_srcdir)/4.out \ diff3 -X -L 1 -L 2 -L 3 $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt atf_check -o file:$(atf_get_srcdir)/5.out \ diff3 -x $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt atf_check -o file:$(atf_get_srcdir)/6.out \ diff3 -3 $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt atf_check -o file:$(atf_get_srcdir)/7.out \ diff3 -i $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt # atf_check -o file:$(atf_get_srcdir)/8.out \ # diff3 -A -L 1 -L 2 -L 3 $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt # atf_check -s exit:1 -o file:$(atf_get_srcdir)/9.out \ # diff3 -m -L 1 -L 2 -L 3 $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt } diff3_lesssimple_body() { atf_check -s exit:1 -o file:$(atf_get_srcdir)/10.out \ diff3 -m -L 1 -L 2 -L 3 $(atf_get_srcdir)/4.txt $(atf_get_srcdir)/5.txt $(atf_get_srcdir)/6.txt } atf_init_test_cases() { atf_add_test_case diff3 # atf_add_test_case diff3_lesssimple }