aboutsummaryrefslogtreecommitdiff
path: root/builtin-apply.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-01-15 00:59:05 -0800
committerJunio C Hamano <gitster@pobox.com>2008-02-05 00:38:41 -0800
commitb2979ff599a6bcf9dbf5e2ef1e32b81a1b88e115 (patch)
treeb828718fd340db7f6a704caa04aa05b815a18092 /builtin-apply.c
parentc1beba5b479a39143ebef96ba10103bbd9a70089 (diff)
downloadgit-b2979ff599a6bcf9dbf5e2ef1e32b81a1b88e115.tar.gz
git-b2979ff599a6bcf9dbf5e2ef1e32b81a1b88e115.tar.xz
core.whitespace: cr-at-eol
This new error mode allows a line to have a carriage return at the end of the line when checking and fixing trailing whitespace errors. Some people like to keep CRLF line ending recorded in the repository, and still want to take advantage of the automated trailing whitespace stripping. We still show ^M in the diff output piped to "less" to remind them that they do have the CR at the end, but these carriage return characters at the end are no longer flagged as errors. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-apply.c')
-rw-r--r--builtin-apply.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/builtin-apply.c b/builtin-apply.c
index fccf4a40c..2b8ba81d8 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -1525,6 +1525,7 @@ static int copy_wsfix(char *output, const char *patch, int plen,
*/
int i;
int add_nl_to_tail = 0;
+ int add_cr_to_tail = 0;
int fixed = 0;
int last_tab_in_indent = -1;
int last_space_in_indent = -1;
@@ -1536,12 +1537,19 @@ static int copy_wsfix(char *output, const char *patch, int plen,
*/
if ((ws_rule & WS_TRAILING_SPACE) &&
(2 < plen && isspace(patch[plen-2]))) {
- if (patch[plen-1] == '\n')
+ if (patch[plen - 1] == '\n') {
add_nl_to_tail = 1;
- plen--;
- while (0 < plen && isspace(patch[plen-1]))
plen--;
- fixed = 1;
+ if (1 < plen && patch[plen - 1] == '\r') {
+ add_cr_to_tail = !!(ws_rule & WS_CR_AT_EOL);
+ plen--;
+ }
+ }
+ if (0 < plen && isspace(patch[plen - 1])) {
+ while (0 < plen && isspace(patch[plen-1]))
+ plen--;
+ fixed = 1;
+ }
}
/*
@@ -1602,6 +1610,8 @@ static int copy_wsfix(char *output, const char *patch, int plen,
}
memcpy(output, patch, plen);
+ if (add_cr_to_tail)
+ output[plen++] = '\r';
if (add_nl_to_tail)
output[plen++] = '\n';
if (fixed && count_error)