aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-09-26 13:30:30 -0700
committerJunio C Hamano <gitster@pobox.com>2011-09-26 14:07:55 -0700
commit855726395342441808eff5e4e9ad9a2b9254edbc (patch)
treefeb0bf00d6dbef465854f9b371cca37eeef43434
parent77b15bbd88e2f48de093ff0e60de6dbc11e3329e (diff)
downloadgit-855726395342441808eff5e4e9ad9a2b9254edbc.tar.gz
git-855726395342441808eff5e4e9ad9a2b9254edbc.tar.xz
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>
-rw-r--r--builtin-apply.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/builtin-apply.c b/builtin-apply.c
index 37d3bc069..508b1edc1 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -1904,6 +1904,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
int size = frag->size;
char *old, *new, *oldlines, *newlines;
int new_blank_lines_at_end = 0;
+ int found_new_blank_lines_at_end = 0;
+ int hunk_linenr = frag->linenr;
unsigned long leading, trailing;
int pos, applied_pos;
struct image preimage;
@@ -1996,14 +1998,18 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
error("invalid start of line: '%c'", first);
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++;
+ }
else if (is_blank_context)
;
else
new_blank_lines_at_end = 0;
patch += len;
size -= len;
+ hunk_linenr++;
}
if (inaccurate_eof &&
old > oldlines && old[-1] == '\n' &&
@@ -2085,7 +2091,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
preimage.nr + applied_pos == img->nr &&
(ws_rule & WS_BLANK_AT_EOF) &&
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) {
while (new_blank_lines_at_end--)
remove_last_line(&postimage);