Skip to content

Commit ed34952

Browse files
committed
correctly summarize ws fixes
1 parent 54548b7 commit ed34952

File tree

4 files changed

+544
-3
lines changed

4 files changed

+544
-3
lines changed

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,14 @@ add_test(NAME fixdiff7
104104
-P ${CMAKE_CURRENT_SOURCE_DIR}/tests/runtest.cmake
105105
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests/7)
106106

107+
add_test(NAME fixdiff8
108+
COMMAND ${CMAKE_COMMAND}
109+
-DCMD=$<TARGET_FILE:${PROJECT_NAME}>
110+
-DSRC=deaddrop.js
111+
-DPATCH=gemini.patch
112+
-DEXPSHA=0549dec027cd6e589d998c4fc423beaab919a10a563e4f3e770c952dc3b0c55c
113+
-DEXPSHA_WIN=2e6b9b12ae0128c9edfc109744b9c67848712b0521c322a45104895aa4cbc3b1
114+
-P ${CMAKE_CURRENT_SOURCE_DIR}/tests/runtest.cmake
115+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests/8)
116+
107117

fixdiff.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ typedef struct {
116116

117117
int pending_empty_lines;
118118

119+
int whitespace_corrected[64];
120+
int count_whitespace_corrected;
121+
119122
char ongoing;
120123
char skip_this_one;
121124
char lead_in_active;
@@ -399,13 +402,16 @@ fixdiff_find_original(dp_t *pdp, int *line_start)
399402
return 1;
400403
}
401404

405+
pdp->count_whitespace_corrected = 0;
406+
402407
/*
403408
* Outer loop walks through each line in source.
404409
* Inner loop tries to match starting from that line
405410
*/
406411

407412
while (!hit) {
408413
line_ending_t let, les;
414+
int n;
409415

410416
init_lbuf(&lb, "src_comp");
411417
lb.fd = open(pdp->pf, OFLAGS(O_RDONLY));
@@ -484,7 +490,12 @@ fixdiff_find_original(dp_t *pdp, int *line_start)
484490
if ((p1 < p1_end) != (p2 < p2_end))
485491
goto record_breakage;
486492

487-
elog("(fixable whitespace-only difference at stanza line %d)\n", lb_temp.li);
493+
for (n = 0; n < pdp->count_whitespace_corrected; n++)
494+
if (pdp->whitespace_corrected[n] == lb_temp.li)
495+
break;
496+
if (n == pdp->count_whitespace_corrected &&
497+
pdp->count_whitespace_corrected < sizeof(pdp->whitespace_corrected) / sizeof(int))
498+
pdp->whitespace_corrected[pdp->count_whitespace_corrected++] = lb_temp.li;
488499

489500
/*
490501
* We have to take care about picking up windows _TEXT
@@ -592,8 +603,7 @@ fixdiff_find_original(dp_t *pdp, int *line_start)
592603
}
593604

594605
if (lea != LE_ZERO)
595-
if (write(lb_temp.fd, "\n", TO_POSLEN(1)) !=
596-
(ssize_t)1) {
606+
if (write(lb_temp.fd, "\n", TO_POSLEN(1)) != (ssize_t)1) {
597607
close(lb_ef.fd);
598608
pdp->reason = "failed to write extra "
599609
"stanza trailer to temp file";
@@ -614,6 +624,10 @@ fixdiff_find_original(dp_t *pdp, int *line_start)
614624

615625
close(lb_ef.fd);
616626
}
627+
628+
if (pdp->count_whitespace_corrected)
629+
elog(" (fixed %d whitespace-only differences in stanza)\n",
630+
pdp->count_whitespace_corrected);
617631
}
618632

619633
out:

0 commit comments

Comments
 (0)