X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=apply.c;h=c3699668671706d35b84d78cfa6ccee675f684b4;hb=d5dddccaa0c61c67340efca36237dfa06eccef1c;hp=a5cdd8e2634500e9515afab8171897a4ccdac8f3;hpb=2ae1c53b51ff78b13cc8abf8e9798a12140b7638;p=git.git diff --git a/apply.c b/apply.c index a5cdd8e2..c3699668 100644 --- a/apply.c +++ b/apply.c @@ -32,14 +32,14 @@ static int no_add = 0; static int show_index_info = 0; static int line_termination = '\n'; static const char apply_usage[] = -"git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [-z] [-pNUM] ..."; +"git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [-z] [-pNUM] [--whitespace=] ..."; static enum whitespace_eol { nowarn_whitespace, warn_on_whitespace, error_on_whitespace, strip_whitespace, -} new_whitespace = nowarn_whitespace; +} new_whitespace = warn_on_whitespace; static int whitespace_error = 0; static int squelch_whitespace_errors = 5; static int applied_after_stripping = 0; @@ -48,13 +48,17 @@ static const char *patch_input_file = NULL; static void parse_whitespace_option(const char *option) { if (!option) { - new_whitespace = nowarn_whitespace; + new_whitespace = warn_on_whitespace; return; } if (!strcmp(option, "warn")) { new_whitespace = warn_on_whitespace; return; } + if (!strcmp(option, "nowarn")) { + new_whitespace = nowarn_whitespace; + return; + } if (!strcmp(option, "error")) { new_whitespace = error_on_whitespace; return; @@ -71,6 +75,15 @@ static void parse_whitespace_option(const char *option) die("unrecognized whitespace option '%s'", option); } +static void set_default_whitespace_mode(const char *whitespace_option) +{ + if (!whitespace_option && !apply_default_whitespace) { + new_whitespace = (apply + ? warn_on_whitespace + : nowarn_whitespace); + } +} + /* * For "diff-stat" like behaviour, we keep track of the biggest change * we've seen, and the longest filename. That allows us to do simple @@ -1951,9 +1964,11 @@ int main(int argc, char **argv) if (fd < 0) usage(apply_usage); read_stdin = 0; + set_default_whitespace_mode(whitespace_option); apply_patch(fd, arg); close(fd); } + set_default_whitespace_mode(whitespace_option); if (read_stdin) apply_patch(0, ""); if (whitespace_error) {