summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b5767dd)
raw | patch | inline | side by side (parent: b5767dd)
author | Junio C Hamano <junkio@cox.net> | |
Mon, 27 Feb 2006 22:16:30 +0000 (14:16 -0800) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Mon, 27 Feb 2006 22:16:30 +0000 (14:16 -0800) |
This by default makes --whitespace=warn, error, and strip to
warn only the first 5 additions of trailing whitespaces. A new
option --whitespace=error-all can be used to view all of them
before applying.
Signed-off-by: Junio C Hamano <junkio@cox.net>
warn only the first 5 additions of trailing whitespaces. A new
option --whitespace=error-all can be used to view all of them
before applying.
Signed-off-by: Junio C Hamano <junkio@cox.net>
apply.c | patch | blob | history |
index 7dbbeb47a00c4813702cc63a8c9badfe3e5e0b42..8139d832e7f98d3b7199c6ba9ac80f7039d0c892 100644 (file)
--- a/apply.c
+++ b/apply.c
strip_and_apply,
} new_whitespace = nowarn;
static int whitespace_error = 0;
+static int squelch_whitespace_errors = 5;
+static int applied_after_stripping = 0;
static const char *patch_input_file = NULL;
/*
@@ -832,11 +834,16 @@ static int parse_fragment(char *line, unsigned long size, struct patch *patch, s
*/
if ((new_whitespace != nowarn) &&
isspace(line[len-2])) {
- fprintf(stderr, "Added whitespace\n");
- fprintf(stderr, "%s:%d:%.*s\n",
- patch_input_file,
- linenr, len-2, line+1);
- whitespace_error = 1;
+ whitespace_error++;
+ if (squelch_whitespace_errors &&
+ squelch_whitespace_errors <
+ whitespace_error)
+ ;
+ else {
+ fprintf(stderr, "Adds trailing whitespace.\n%s:%d:%.*s\n",
+ patch_input_file,
+ linenr, len-2, line+1);
+ }
}
added++;
newlines--;
plen--;
while (0 < plen && isspace(patch[plen]))
plen--;
+ applied_after_stripping++;
}
memcpy(output, patch + 1, plen);
if (add_nl_to_tail)
new_whitespace = error_on_whitespace;
continue;
}
+ if (!strcmp(arg+13, "error-all")) {
+ new_whitespace = error_on_whitespace;
+ squelch_whitespace_errors = 0;
+ continue;
+ }
if (!strcmp(arg+13, "strip")) {
new_whitespace = strip_and_apply;
continue;
}
- die("unrecognixed whitespace option '%s'", arg+13);
+ die("unrecognized whitespace option '%s'", arg+13);
}
if (check_index && prefix_length < 0) {
}
if (read_stdin)
apply_patch(0, "<stdin>");
- if (whitespace_error && new_whitespace == error_on_whitespace)
- return 1;
+ if (whitespace_error) {
+ if (squelch_whitespace_errors &&
+ squelch_whitespace_errors < whitespace_error) {
+ int squelched =
+ whitespace_error - squelch_whitespace_errors;
+ fprintf(stderr, "warning: squelched %d whitespace error%s\n",
+ squelched,
+ squelched == 1 ? "" : "s");
+ }
+ if (new_whitespace == error_on_whitespace)
+ die("%d line%s add%s trailing whitespaces.",
+ whitespace_error,
+ whitespace_error == 1 ? "" : "s",
+ whitespace_error == 1 ? "s" : "");
+ if (applied_after_stripping)
+ fprintf(stderr, "warning: %d line%s applied after"
+ " stripping trailing whitespaces.\n",
+ applied_after_stripping,
+ applied_after_stripping == 1 ? "" : "s");
+ else if (whitespace_error)
+ fprintf(stderr, "warning: %d line%s add%s trailing"
+ " whitespaces.\n",
+ whitespace_error,
+ whitespace_error == 1 ? "" : "s",
+ whitespace_error == 1 ? "s" : "");
+ }
return 0;
}