Merge branch 'jc/apply-blank-at-eof-fix'
* jc/apply-blank-at-eof-fix: apply --whitespace=error: correctly report new blank lines at end
This commit is contained in:
commit
89dfd2dfbf
@ -2447,6 +2447,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
|
|||||||
char *old, *oldlines;
|
char *old, *oldlines;
|
||||||
struct strbuf newlines;
|
struct strbuf newlines;
|
||||||
int new_blank_lines_at_end = 0;
|
int new_blank_lines_at_end = 0;
|
||||||
|
int found_new_blank_lines_at_end = 0;
|
||||||
|
int hunk_linenr = frag->linenr;
|
||||||
unsigned long leading, trailing;
|
unsigned long leading, trailing;
|
||||||
int pos, applied_pos;
|
int pos, applied_pos;
|
||||||
struct image preimage;
|
struct image preimage;
|
||||||
@ -2540,14 +2542,18 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
|
|||||||
error("invalid start of line: '%c'", first);
|
error("invalid start of line: '%c'", first);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (added_blank_line)
|
if (added_blank_line) {
|
||||||
|
if (!new_blank_lines_at_end)
|
||||||
|
found_new_blank_lines_at_end = hunk_linenr;
|
||||||
new_blank_lines_at_end++;
|
new_blank_lines_at_end++;
|
||||||
|
}
|
||||||
else if (is_blank_context)
|
else if (is_blank_context)
|
||||||
;
|
;
|
||||||
else
|
else
|
||||||
new_blank_lines_at_end = 0;
|
new_blank_lines_at_end = 0;
|
||||||
patch += len;
|
patch += len;
|
||||||
size -= len;
|
size -= len;
|
||||||
|
hunk_linenr++;
|
||||||
}
|
}
|
||||||
if (inaccurate_eof &&
|
if (inaccurate_eof &&
|
||||||
old > oldlines && old[-1] == '\n' &&
|
old > oldlines && old[-1] == '\n' &&
|
||||||
@ -2629,7 +2635,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
|
|||||||
preimage.nr + applied_pos >= img->nr &&
|
preimage.nr + applied_pos >= img->nr &&
|
||||||
(ws_rule & WS_BLANK_AT_EOF) &&
|
(ws_rule & WS_BLANK_AT_EOF) &&
|
||||||
ws_error_action != nowarn_ws_error) {
|
ws_error_action != nowarn_ws_error) {
|
||||||
record_ws_error(WS_BLANK_AT_EOF, "+", 1, frag->linenr);
|
record_ws_error(WS_BLANK_AT_EOF, "+", 1,
|
||||||
|
found_new_blank_lines_at_end);
|
||||||
if (ws_error_action == correct_ws_error) {
|
if (ws_error_action == correct_ws_error) {
|
||||||
while (new_blank_lines_at_end--)
|
while (new_blank_lines_at_end--)
|
||||||
remove_last_line(&postimage);
|
remove_last_line(&postimage);
|
||||||
|
Loading…
Reference in New Issue
Block a user