Date: Sat, 25 Sep 2021 08:41:28 GMT From: Piotr Pawel Stefaniak <pstef@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: ece58f7ada40 - stable/13 - diff: don't output carriage returns that were stripped on input Message-ID: <202109250841.18P8fS52018027@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by pstef: URL: https://cgit.FreeBSD.org/src/commit/?id=ece58f7ada409ac68e072cdddcc29e21127aafce commit ece58f7ada409ac68e072cdddcc29e21127aafce Author: Piotr Pawel Stefaniak <pstef@FreeBSD.org> AuthorDate: 2021-08-22 16:05:59 +0000 Commit: Piotr Pawel Stefaniak <pstef@FreeBSD.org> CommitDate: 2021-09-25 08:34:38 +0000 diff: don't output carriage returns that were stripped on input --strip-trailing-cr worked as intended for comparison between files, but the characters were still present in final output. (cherry picked from commit af2f0164318455433db95adce07af829285b78ad) --- usr.bin/diff/diffreg.c | 11 ++++++++++- usr.bin/diff/tests/Makefile | 3 ++- usr.bin/diff/tests/diff_test.sh | 10 ++++++++++ usr.bin/diff/tests/strip_o.out | 7 +++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c index 651ec88df909..113b7b621256 100644 --- a/usr.bin/diff/diffreg.c +++ b/usr.bin/diff/diffreg.c @@ -1273,7 +1273,16 @@ fetch(long *f, int a, int b, FILE *lb, int ch, int oldfile, int flags) } col = 0; for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) { - if ((c = getc(lb)) == EOF) { + c = getc(lb); + if (flags & D_STRIPCR && c == '\r') { + if ((c = getc(lb)) == '\n') + j++; + else { + ungetc(c, lb); + c = '\r'; + } + } + if (c == EOF) { if (diff_format == D_EDIT || diff_format == D_REVERSE || diff_format == D_NREVERSE) diff --git a/usr.bin/diff/tests/Makefile b/usr.bin/diff/tests/Makefile index 78744d3bed8e..303a37911fbd 100644 --- a/usr.bin/diff/tests/Makefile +++ b/usr.bin/diff/tests/Makefile @@ -26,7 +26,8 @@ ${PACKAGE}FILES+= \ header.out \ header_ns.out \ ifdef.out \ - group-format.out + group-format.out \ + strip_o.out NETBSD_ATF_TESTS_SH+= netbsd_diff_test diff --git a/usr.bin/diff/tests/diff_test.sh b/usr.bin/diff/tests/diff_test.sh index b9d1698d982e..c311c3bf2fbc 100755 --- a/usr.bin/diff/tests/diff_test.sh +++ b/usr.bin/diff/tests/diff_test.sh @@ -9,6 +9,7 @@ atf_test_case group_format atf_test_case side_by_side atf_test_case brief_format atf_test_case b230049 +atf_test_case stripcr_o atf_test_case b252515 atf_test_case Bflag atf_test_case Nflag @@ -68,6 +69,14 @@ b230049_body() b230049_a.in b230049_b.in } +stripcr_o_body() +{ + printf 'a\nX\nc\n' > stripcr_o_X.in + printf 'a\r\nY\r\nc\r\n' > stripcr_o_Y.in + atf_check -o "file:$(atf_get_srcdir)/strip_o.out" -s eq:1 \ + diff -L1 -L2 -u --strip-trailing-cr stripcr_o_X.in stripcr_o_Y.in +} + b252515_body() { printf 'a b\n' > b252515_a.in @@ -266,6 +275,7 @@ atf_init_test_cases() atf_add_test_case side_by_side atf_add_test_case brief_format atf_add_test_case b230049 + atf_add_test_case stripcr_o atf_add_test_case b252515 atf_add_test_case Bflag atf_add_test_case Nflag diff --git a/usr.bin/diff/tests/strip_o.out b/usr.bin/diff/tests/strip_o.out new file mode 100644 index 000000000000..47bbfbd4e921 --- /dev/null +++ b/usr.bin/diff/tests/strip_o.out @@ -0,0 +1,7 @@ +--- 1 ++++ 2 +@@ -1,3 +1,3 @@ + a +-X ++Y + c
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202109250841.18P8fS52018027>