Skip to content

Commit 8ef3e6b

Browse files
committed
interdiff: exit with error when whitespace damage detected
There is really no hope in this situation. It can't be fixed.
1 parent 73c0880 commit 8ef3e6b

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ TESTS = tests/newline1/run-test \
219219
tests/splitdiffD/run-test \
220220
tests/fullheader1/run-test \
221221
tests/fullheader2/run-test \
222-
tests/fullheader3/run-test
222+
tests/fullheader3/run-test \
223+
tests/whitespace/run-test
223224

224225
# These ones don't work yet.
225226
# Feel free to send me patches. :-)

src/interdiff.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,13 @@ clear_lines_info (struct lines_info *info)
303303
info->unline = NULL;
304304
}
305305

306+
static void
307+
whitespace_damage (const char *which)
308+
{
309+
error (EXIT_FAILURE, 0, "Whitespace damage detected in %s", which);
310+
}
311+
312+
306313
static struct lines *
307314
create_orig (FILE *f, struct lines_info *file,
308315
int reverted, int *clash)
@@ -386,6 +393,8 @@ create_orig (FILE *f, struct lines_info *file,
386393
}
387394

388395
switch (first_char) {
396+
case '\n':
397+
whitespace_damage("input");
389398
case ' ':
390399
if (leading_context) context++;
391400
if (new_lines) new_lines--;
@@ -632,6 +641,8 @@ do_output_patch1_only (FILE *p1, FILE *out, int not_reverted)
632641
}
633642

634643
switch (first_char) {
644+
case '\n':
645+
whitespace_damage("patch #1");
635646
case ' ':
636647
if (orig_lines) orig_lines--;
637648
if (new_lines) new_lines--;
@@ -911,6 +922,8 @@ trim_context (FILE *f /* positioned at start of @@ line */,
911922

912923
total_count++;
913924
switch (line[0]) {
925+
case '\n':
926+
whitespace_damage("input");
914927
case ' ' :
915928
if (orig_count) orig_count--;
916929
if (new_count) new_count--;
@@ -1664,6 +1677,8 @@ flipdiff (FILE *p1, FILE *p2, FILE *flip1, FILE *flip2)
16641677
new_lines--;
16651678

16661679
switch (line[0]) {
1680+
case '\n':
1681+
whitespace_damage("patch #2");
16671682
case ' ':
16681683
if (this_offset) {
16691684
offsets = add_offset (first_linenum,

tests/whitespace/run-test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
3+
# This is an interdiff(1) testcase.
4+
5+
6+
. ${top_srcdir-.}/tests/common.sh
7+
8+
cat << EOF > diff
9+
--- file1
10+
+++ file1
11+
@@ -1,2 +1,2 @@
12+
-A
13+
+a
14+
15+
EOF
16+
17+
# When detecting whitespace damage in the input, an error should be
18+
# written and the program should terminate with a non-zero exit code.
19+
20+
${INTERDIFF} -qp1 diff diff 2>errors && exit 1
21+
[ -s errors ] || exit 1

0 commit comments

Comments
 (0)