@matheusbsbs / matheus-bagliano / commits / 59aa256204
Fork 0

apply: squelch excessive errors and --whitespace=error-all

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>

Junio C Hamano committed Feb 27, 2006 at 14:16 UTC 59aa256204f74e02579d7586884c73f0db6eb0d6
1 file changed +45 -8
apply.c
+45 -8
@@ -41,6 +41,8 @@ static enum whitespace_eol {
41 strip_and_apply,
42 } new_whitespace = nowarn;
43 static int whitespace_error = 0;
44 +static int squelch_whitespace_errors = 5;
45 +static int applied_after_stripping = 0;
46 static const char *patch_input_file = NULL;
47
48 /*
@@ -832,11 +834,16 @@ static int parse_fragment(char *line, unsigned long size, struct patch *patch, s
834 */
835 if ((new_whitespace != nowarn) &&
836 isspace(line[len-2])) {
835 - fprintf(stderr, "Added whitespace\n");
836 - fprintf(stderr, "%s:%d:%.*s\n",
837 - patch_input_file,
838 - linenr, len-2, line+1);
839 - whitespace_error = 1;
837 + whitespace_error++;
838 + if (squelch_whitespace_errors &&
839 + squelch_whitespace_errors <
840 + whitespace_error)
841 + ;
842 + else {
843 + fprintf(stderr, "Adds trailing whitespace.\n%s:%d:%.*s\n",
844 + patch_input_file,
845 + linenr, len-2, line+1);
846 + }
847 }
848 added++;
849 newlines--;
@@ -1129,6 +1136,7 @@ static int apply_line(char *output, const char *patch, int plen)
1136 plen--;
1137 while (0 < plen && isspace(patch[plen]))
1138 plen--;
1139 + applied_after_stripping++;
1140 }
1141 memcpy(output, patch + 1, plen);
1142 if (add_nl_to_tail)
@@ -1887,11 +1895,16 @@ int main(int argc, char **argv)
1895 new_whitespace = error_on_whitespace;
1896 continue;
1897 }
1898 + if (!strcmp(arg+13, "error-all")) {
1899 + new_whitespace = error_on_whitespace;
1900 + squelch_whitespace_errors = 0;
1901 + continue;
1902 + }
1903 if (!strcmp(arg+13, "strip")) {
1904 new_whitespace = strip_and_apply;
1905 continue;
1906 }
1894 - die("unrecognixed whitespace option '%s'", arg+13);
1907 + die("unrecognized whitespace option '%s'", arg+13);
1908 }
1909
1910 if (check_index && prefix_length < 0) {
@@ -1911,7 +1924,31 @@ int main(int argc, char **argv)
1924 }
1925 if (read_stdin)
1926 apply_patch(0, "<stdin>");
1914 - if (whitespace_error && new_whitespace == error_on_whitespace)
1915 - return 1;
1927 + if (whitespace_error) {
1928 + if (squelch_whitespace_errors &&
1929 + squelch_whitespace_errors < whitespace_error) {
1930 + int squelched =
1931 + whitespace_error - squelch_whitespace_errors;
1932 + fprintf(stderr, "warning: squelched %d whitespace error%s\n",
1933 + squelched,
1934 + squelched == 1 ? "" : "s");
1935 + }
1936 + if (new_whitespace == error_on_whitespace)
1937 + die("%d line%s add%s trailing whitespaces.",
1938 + whitespace_error,
1939 + whitespace_error == 1 ? "" : "s",
1940 + whitespace_error == 1 ? "s" : "");
1941 + if (applied_after_stripping)
1942 + fprintf(stderr, "warning: %d line%s applied after"
1943 + " stripping trailing whitespaces.\n",
1944 + applied_after_stripping,
1945 + applied_after_stripping == 1 ? "" : "s");
1946 + else if (whitespace_error)
1947 + fprintf(stderr, "warning: %d line%s add%s trailing"
1948 + " whitespaces.\n",
1949 + whitespace_error,
1950 + whitespace_error == 1 ? "" : "s",
1951 + whitespace_error == 1 ? "s" : "");
1952 + }
1953 return 0;
1954 }