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 <gitster@pobox.com>
Junio C Hamano committed
Sep 26, 2011 at 13:30 UTC
855726395342441808eff5e4e9ad9a2b9254edbc
1 file changed
+9
-2
builtin-apply.c
+9
-2
@@ -1904,6 +1904,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
1904
int size = frag->size;
1905
char *old, *new, *oldlines, *newlines;
1906
int new_blank_lines_at_end = 0;
1907
+ int found_new_blank_lines_at_end = 0;
1908
+ int hunk_linenr = frag->linenr;
1909
unsigned long leading, trailing;
1910
int pos, applied_pos;
1911
struct image preimage;
@@ -1996,14 +1998,18 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
1998
error("invalid start of line: '%c'", first);
1999
return -1;
2000
}
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;
2004
new_blank_lines_at_end++;
2005
+ }
2006
else if (is_blank_context)
2007
;
2008
else
2009
new_blank_lines_at_end = 0;
2010
patch += len;
2011
size -= len;
2012
+ hunk_linenr++;
2013
}
2014
if (inaccurate_eof &&
2015
old > oldlines && old[-1] == '\n' &&
@@ -2085,7 +2091,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
2091
preimage.nr + applied_pos == img->nr &&
2092
(ws_rule & WS_BLANK_AT_EOF) &&
2093
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);
2096
if (ws_error_action == correct_ws_error) {
2097
while (new_blank_lines_at_end--)
2098
remove_last_line(&postimage);