@@ -1351,7 +1351,7 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
13511351 int len = eds -> len ;
13521352 unsigned flags = eds -> flags ;
13531353
1354- if (o -> dry_run )
1354+ if (! o -> file )
13551355 return ;
13561356
13571357 switch (s ) {
@@ -3765,9 +3765,9 @@ static void builtin_diff(const char *name_a,
37653765
37663766 if (o -> word_diff )
37673767 init_diff_words_data (& ecbdata , o , one , two );
3768- if (o -> dry_run ) {
3768+ if (! o -> file ) {
37693769 /*
3770- * Unlike the !dry_run case, we need to ignore the
3770+ * Unlike the normal output case, we need to ignore the
37713771 * return value from xdi_diff_outf() here, because
37723772 * xdi_diff_outf() takes non-zero return from its
37733773 * callback function as a sign of error and returns
@@ -4423,7 +4423,6 @@ static void run_external_diff(const struct external_diff *pgm,
44234423{
44244424 struct child_process cmd = CHILD_PROCESS_INIT ;
44254425 struct diff_queue_struct * q = & diff_queued_diff ;
4426- int quiet = !(o -> output_format & DIFF_FORMAT_PATCH ) || o -> dry_run ;
44274426 int rc ;
44284427
44294428 /*
@@ -4432,7 +4431,7 @@ static void run_external_diff(const struct external_diff *pgm,
44324431 * external diff program lacks the ability to tell us whether
44334432 * it's empty then we consider it non-empty without even asking.
44344433 */
4435- if (!pgm -> trust_exit_code && quiet ) {
4434+ if (!pgm -> trust_exit_code && ! o -> file ) {
44364435 o -> found_changes = 1 ;
44374436 return ;
44384437 }
@@ -4457,7 +4456,10 @@ static void run_external_diff(const struct external_diff *pgm,
44574456 diff_free_filespec_data (one );
44584457 diff_free_filespec_data (two );
44594458 cmd .use_shell = 1 ;
4460- cmd .no_stdout = quiet ;
4459+ if (!o -> file )
4460+ cmd .no_stdout = 1 ;
4461+ else if (o -> file != stdout )
4462+ cmd .out = xdup (fileno (o -> file ));
44614463 rc = run_command (& cmd );
44624464 if (!pgm -> trust_exit_code && rc == 0 )
44634465 o -> found_changes = 1 ;
@@ -4618,7 +4620,7 @@ static void run_diff_cmd(const struct external_diff *pgm,
46184620 p -> status == DIFF_STATUS_RENAMED )
46194621 o -> found_changes = 1 ;
46204622 } else {
4621- if (! o -> dry_run )
4623+ if (o -> file )
46224624 fprintf (o -> file , "* Unmerged path %s\n" , name );
46234625 o -> found_changes = 1 ;
46244626 }
@@ -6196,15 +6198,15 @@ static void diff_flush_patch(struct diff_filepair *p, struct diff_options *o)
61966198/* return 1 if any change is found; otherwise, return 0 */
61976199static int diff_flush_patch_quietly (struct diff_filepair * p , struct diff_options * o )
61986200{
6199- int saved_dry_run = o -> dry_run ;
6201+ FILE * saved_file = o -> file ;
62006202 int saved_found_changes = o -> found_changes ;
62016203 int ret ;
62026204
6203- o -> dry_run = 1 ;
6205+ o -> file = NULL ;
62046206 o -> found_changes = 0 ;
62056207 diff_flush_patch (p , o );
62066208 ret = o -> found_changes ;
6207- o -> dry_run = saved_dry_run ;
6209+ o -> file = saved_file ;
62086210 o -> found_changes |= saved_found_changes ;
62096211 return ret ;
62106212}
@@ -6832,38 +6834,18 @@ void diff_flush(struct diff_options *options)
68326834 DIFF_FORMAT_NAME |
68336835 DIFF_FORMAT_NAME_STATUS |
68346836 DIFF_FORMAT_CHECKDIFF )) {
6835- /*
6836- * make sure diff_Flush_patch_quietly() to be silent.
6837- */
6838- FILE * dev_null = NULL ;
6839- int saved_color_moved = options -> color_moved ;
6840-
6841- if (options -> flags .diff_from_contents ) {
6842- dev_null = xfopen ("/dev/null" , "w" );
6843- options -> color_moved = 0 ;
6844- }
68456837 for (i = 0 ; i < q -> nr ; i ++ ) {
68466838 struct diff_filepair * p = q -> queue [i ];
68476839
68486840 if (!check_pair_status (p ))
68496841 continue ;
68506842
6851- if (options -> flags .diff_from_contents ) {
6852- FILE * saved_file = options -> file ;
6853- int found_changes ;
6843+ if (options -> flags .diff_from_contents &&
6844+ ! diff_flush_patch_quietly ( p , options ))
6845+ continue ;
68546846
6855- options -> file = dev_null ;
6856- found_changes = diff_flush_patch_quietly (p , options );
6857- options -> file = saved_file ;
6858- if (!found_changes )
6859- continue ;
6860- }
68616847 flush_one_pair (p , options );
68626848 }
6863- if (options -> flags .diff_from_contents ) {
6864- fclose (dev_null );
6865- options -> color_moved = saved_color_moved ;
6866- }
68676849 separator ++ ;
68686850 }
68696851
@@ -6914,15 +6896,6 @@ void diff_flush(struct diff_options *options)
69146896 if (output_format & DIFF_FORMAT_NO_OUTPUT &&
69156897 options -> flags .exit_with_status &&
69166898 options -> flags .diff_from_contents ) {
6917- /*
6918- * run diff_flush_patch for the exit status. setting
6919- * options->file to /dev/null should be safe, because we
6920- * aren't supposed to produce any output anyway.
6921- */
6922- diff_free_file (options );
6923- options -> file = xfopen ("/dev/null" , "w" );
6924- options -> close_file = 1 ;
6925- options -> color_moved = 0 ;
69266899 for (i = 0 ; i < q -> nr ; i ++ ) {
69276900 struct diff_filepair * p = q -> queue [i ];
69286901 if (check_pair_status (p ))
0 commit comments