@matheusbsbs / matheus-bagliano / commits / fc96b7c9ba
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 fc96b7c9ba5034a408d508c663a96a15b8f8729c
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)
@@ -1895,11 +1903,16 @@ int main(int argc, char **argv)
1903 new_whitespace = error_on_whitespace;
1904 continue;
1905 }
1906 + if (!strcmp(arg+13, "error-all")) {
1907 + new_whitespace = error_on_whitespace;
1908 + squelch_whitespace_errors = 0;
1909 + continue;
1910 + }
1911 if (!strcmp(arg+13, "strip")) {
1912 new_whitespace = strip_and_apply;
1913 continue;
1914 }
1902 - die("unrecognixed whitespace option '%s'", arg+13);
1915 + die("unrecognized whitespace option '%s'", arg+13);
1916 }
1917
1918 if (check_index && prefix_length < 0) {
@@ -1919,7 +1932,31 @@ int main(int argc, char **argv)
1932 }
1933 if (read_stdin)
1934 apply_patch(0, "<stdin>");
1922 - if (whitespace_error && new_whitespace == error_on_whitespace)
1923 - return 1;
1935 + if (whitespace_error) {
1936 + if (squelch_whitespace_errors &&
1937 + squelch_whitespace_errors < whitespace_error) {
1938 + int squelched =
1939 + whitespace_error - squelch_whitespace_errors;
1940 + fprintf(stderr, "warning: squelched %d whitespace error%s\n",
1941 + squelched,
1942 + squelched == 1 ? "" : "s");
1943 + }
1944 + if (new_whitespace == error_on_whitespace)
1945 + die("%d line%s add%s trailing whitespaces.",
1946 + whitespace_error,
1947 + whitespace_error == 1 ? "" : "s",
1948 + whitespace_error == 1 ? "s" : "");
1949 + if (applied_after_stripping)
1950 + fprintf(stderr, "warning: %d line%s applied after"
1951 + " stripping trailing whitespaces.\n",
1952 + applied_after_stripping,
1953 + applied_after_stripping == 1 ? "" : "s");
1954 + else if (whitespace_error)
1955 + fprintf(stderr, "warning: %d line%s add%s trailing"
1956 + " whitespaces.\n",
1957 + whitespace_error,
1958 + whitespace_error == 1 ? "" : "s",
1959 + whitespace_error == 1 ? "s" : "");
1960 + }
1961 return 0;
1962 }