git: af2f01643184 - main - diff: don't output carriage returns that were stripped on input
Piotr Pawel Stefaniak
pstef at FreeBSD.org
Mon Aug 23 05:07:21 UTC 2021
The branch main has been updated by pstef:
URL: https://cgit.FreeBSD.org/src/commit/?id=af2f0164318455433db95adce07af829285b78ad
commit af2f0164318455433db95adce07af829285b78ad
Author: Piotr Pawel Stefaniak <pstef at FreeBSD.org>
AuthorDate: 2021-08-22 16:05:59 +0000
Commit: Piotr Pawel Stefaniak <pstef at FreeBSD.org>
CommitDate: 2021-08-23 05:04:28 +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.
---
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 cd893091d016..b8b7fe1d8068 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
@@ -267,6 +276,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
More information about the dev-commits-src-main
mailing list