@matheusbsbs / matheus-bagliano / commits / 68aacb2f3c
Fork 0

diff --quiet

This adds the command line option 'quiet' to tell 'git diff-*' that we are not interested in the actual diff contents but only want to know if there is any change. This option automatically turns --exit-code on, and turns off output formatting, as it does not make much sense to show the first hit we happened to have found. The --quiet option is silently turned off (but --exit-code is still in effect, so is silent output) if postprocessing filters such as pickaxe and diff-filter are used. For all practical purposes I do not think of a reason to want to use these filters and not viewing the diff output. The backends have not been taught about the option with this patch. That is a topic for later rounds. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Mar 14, 2007 at 11:12 UTC 68aacb2f3ceef528ded945b510094918bfe3cb37
2 files changed +27 -4
diff.c
+25 -2
@@ -1958,6 +1958,23 @@ int diff_setup_done(struct diff_options *options)
1958 if (options->abbrev <= 0 || 40 < options->abbrev)
1959 options->abbrev = 40; /* full */
1960
1961 + /*
1962 + * It does not make sense to show the first hit we happened
1963 + * to have found. It does not make sense not to return with
1964 + * exit code in such a case either.
1965 + */
1966 + if (options->quiet) {
1967 + options->output_format = DIFF_FORMAT_NO_OUTPUT;
1968 + options->exit_with_status = 1;
1969 + }
1970 +
1971 + /*
1972 + * If we postprocess in diffcore, we cannot simply return
1973 + * upon the first hit. We need to run diff as usual.
1974 + */
1975 + if (options->pickaxe || options->filter)
1976 + options->quiet = 0;
1977 +
1978 return 0;
1979 }
1980
@@ -2136,6 +2153,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
2153 options->detect_rename = 0;
2154 else if (!strcmp(arg, "--exit-code"))
2155 options->exit_with_status = 1;
2156 + else if (!strcmp(arg, "--quiet"))
2157 + options->quiet = 1;
2158 else
2159 return 0;
2160 return 1;
@@ -2900,6 +2919,8 @@ static void diffcore_apply_filter(const char *filter)
2919
2920 void diffcore_std(struct diff_options *options)
2921 {
2922 + if (options->quiet)
2923 + return;
2924 if (options->break_opt != -1)
2925 diffcore_break(options->break_opt);
2926 if (options->detect_rename)
@@ -2912,8 +2933,8 @@ void diffcore_std(struct diff_options *options)
2933 diffcore_order(options->orderfile);
2934 diff_resolve_rename_copy();
2935 diffcore_apply_filter(options->filter);
2915 - if (options->exit_with_status)
2916 - options->has_changes = !!diff_queued_diff.nr;
2936 +
2937 + options->has_changes = !!diff_queued_diff.nr;
2938 }
2939
2940
@@ -2952,6 +2973,7 @@ void diff_addremove(struct diff_options *options,
2973 fill_filespec(two, sha1, mode);
2974
2975 diff_queue(&diff_queued_diff, one, two);
2976 + options->has_changes = 1;
2977 }
2978
2979 void diff_change(struct diff_options *options,
@@ -2977,6 +2999,7 @@ void diff_change(struct diff_options *options,
2999 fill_filespec(two, new_sha1, new_mode);
3000
3001 diff_queue(&diff_queued_diff, one, two);
3002 + options->has_changes = 1;
3003 }
3004
3005 void diff_unmerge(struct diff_options *options,
diff.h
+2 -2
@@ -57,6 +57,8 @@ struct diff_options {
57 find_copies_harder:1,
58 color_diff:1,
59 color_diff_words:1,
60 + has_changes:1,
61 + quiet:1,
62 exit_with_status:1;
63 int context;
64 int break_opt;
@@ -72,8 +74,6 @@ struct diff_options {
74 const char *msg_sep;
75 const char *stat_sep;
76 long xdl_opts;
75 - /* 0 - no differences; only meaningful if exit_with_status set */
76 - int has_changes;
77
78 int stat_width;
79 int stat_name_width;