mirror of
https://github.com/git/git.git
synced 2026-01-09 01:34:00 +00:00
apply: check and fix incomplete lines
The final line of a file that lacks the terminating newline at its
end is called an incomplete line. In general they are frowned upon
for many reasons (imagine concatenating two files with "cat A B" and
what happens when A ends in an incomplete line, for example), and
text-oriented tools often mishandle such a line.
Implement checks in "git apply" for incomplete lines, which is off
by default for backward compatibility's sake, so that "git apply
--whitespace={fix,warn,error}" can notice, warn against, and fix
them.
As one of the new test shows, if you modify contents on an
incomplete line in the original and leave the resulting line
incomplete, it is still considered a whitespace error, the reasoning
being that "you'd better fix it while at it if you are making a
change on an incomplete line anyway", which may controversial.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
13
apply.c
13
apply.c
@@ -1640,6 +1640,14 @@ static void record_ws_error(struct apply_state *state,
|
||||
state->squelch_whitespace_errors < state->whitespace_error)
|
||||
return;
|
||||
|
||||
/*
|
||||
* line[len] for an incomplete line points at the "\n" at the end
|
||||
* of patch input line, so "%.*s" would drop the last letter on line;
|
||||
* compensate for it.
|
||||
*/
|
||||
if (result & WS_INCOMPLETE_LINE)
|
||||
len++;
|
||||
|
||||
err = whitespace_error_string(result);
|
||||
if (state->apply_verbosity > verbosity_silent)
|
||||
fprintf(stderr, "%s:%d: %s.\n%.*s\n",
|
||||
@@ -1794,7 +1802,10 @@ static int parse_fragment(struct apply_state *state,
|
||||
}
|
||||
|
||||
/* eat the "\\ No newline..." as well, if exists */
|
||||
len += skip_len;
|
||||
if (skip_len) {
|
||||
len += skip_len;
|
||||
state->linenr++;
|
||||
}
|
||||
}
|
||||
if (oldlines || newlines)
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user