Skip to content

Commit 8557263

Browse files
committed
apply --whitespace=error: correctly report new blank lines at end
Earlier, 77b15bb (apply --whitespace=warn/error: diagnose blank at EOF, 2009-09-03) cheated by reporting the line number of the hunk that contains the offending line that adds new blank lines at the end of the file. All other types of whitespace errors are reported with the line number in the patch file that has the actual offending text. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 77b15bb commit 8557263

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

builtin-apply.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,6 +1904,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
19041904
int size = frag->size;
19051905
char *old, *new, *oldlines, *newlines;
19061906
int new_blank_lines_at_end = 0;
1907+
int found_new_blank_lines_at_end = 0;
1908+
int hunk_linenr = frag->linenr;
19071909
unsigned long leading, trailing;
19081910
int pos, applied_pos;
19091911
struct image preimage;
@@ -1996,14 +1998,18 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
19961998
error("invalid start of line: '%c'", first);
19971999
return -1;
19982000
}
1999-
if (added_blank_line)
2001+
if (added_blank_line) {
2002+
if (!new_blank_lines_at_end)
2003+
found_new_blank_lines_at_end = hunk_linenr;
20002004
new_blank_lines_at_end++;
2005+
}
20012006
else if (is_blank_context)
20022007
;
20032008
else
20042009
new_blank_lines_at_end = 0;
20052010
patch += len;
20062011
size -= len;
2012+
hunk_linenr++;
20072013
}
20082014
if (inaccurate_eof &&
20092015
old > oldlines && old[-1] == '\n' &&
@@ -2085,7 +2091,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
20852091
preimage.nr + applied_pos == img->nr &&
20862092
(ws_rule & WS_BLANK_AT_EOF) &&
20872093
ws_error_action != nowarn_ws_error) {
2088-
record_ws_error(WS_BLANK_AT_EOF, "+", 1, frag->linenr);
2094+
record_ws_error(WS_BLANK_AT_EOF, "+", 1,
2095+
found_new_blank_lines_at_end);
20892096
if (ws_error_action == correct_ws_error) {
20902097
while (new_blank_lines_at_end--)
20912098
remove_last_line(&postimage);

0 commit comments

Comments
 (0)