|
40 | 40 | #include "setup.h" |
41 | 41 | #include "strmap.h" |
42 | 42 | #include "ws.h" |
| 43 | +#include "write-or-die.h" |
43 | 44 |
|
44 | 45 | #ifdef NO_FAST_WORKING_DIRECTORY |
45 | 46 | #define FAST_WORKING_DIRECTORY 0 |
@@ -4404,8 +4405,33 @@ static void run_external_diff(const char *pgm, |
4404 | 4405 | diff_free_filespec_data(one); |
4405 | 4406 | diff_free_filespec_data(two); |
4406 | 4407 | cmd.use_shell = 1; |
4407 | | - if (run_command(&cmd)) |
4408 | | - die(_("external diff died, stopping at %s"), name); |
| 4408 | + if (o->flags.diff_from_contents) { |
| 4409 | + int got_output = 0; |
| 4410 | + cmd.out = -1; |
| 4411 | + if (start_command(&cmd)) |
| 4412 | + die(_("external diff died, stopping at %s"), name); |
| 4413 | + for (;;) { |
| 4414 | + char buffer[8192]; |
| 4415 | + ssize_t len = xread(cmd.out, buffer, sizeof(buffer)); |
| 4416 | + if (!len) |
| 4417 | + break; |
| 4418 | + if (len < 0) |
| 4419 | + die(_("unable to read from external diff," |
| 4420 | + " stopping at %s"), name); |
| 4421 | + got_output = 1; |
| 4422 | + if (write_in_full(1, buffer, len) < 0) |
| 4423 | + die(_("unable to write output of external diff," |
| 4424 | + " stopping at %s"), name); |
| 4425 | + } |
| 4426 | + close(cmd.out); |
| 4427 | + if (finish_command(&cmd)) |
| 4428 | + die(_("external diff died, stopping at %s"), name); |
| 4429 | + if (got_output) |
| 4430 | + o->found_changes = 1; |
| 4431 | + } else { |
| 4432 | + if (run_command(&cmd)) |
| 4433 | + die(_("external diff died, stopping at %s"), name); |
| 4434 | + } |
4409 | 4435 |
|
4410 | 4436 | remove_tempfile(); |
4411 | 4437 | } |
@@ -4555,6 +4581,7 @@ static void run_diff_cmd(const char *pgm, |
4555 | 4581 | o, complete_rewrite); |
4556 | 4582 | } else { |
4557 | 4583 | fprintf(o->file, "* Unmerged path %s\n", name); |
| 4584 | + o->found_changes = 1; |
4558 | 4585 | } |
4559 | 4586 | } |
4560 | 4587 |
|
@@ -4851,6 +4878,7 @@ void diff_setup_done(struct diff_options *options) |
4851 | 4878 | */ |
4852 | 4879 |
|
4853 | 4880 | if ((options->xdl_opts & XDF_WHITESPACE_FLAGS) || |
| 4881 | + options->flags.exit_with_status || |
4854 | 4882 | options->ignore_regex_nr) |
4855 | 4883 | options->flags.diff_from_contents = 1; |
4856 | 4884 | else |
@@ -6741,7 +6769,7 @@ void diff_flush(struct diff_options *options) |
6741 | 6769 | if (output_format & DIFF_FORMAT_CALLBACK) |
6742 | 6770 | options->format_callback(q, options, options->format_callback_data); |
6743 | 6771 |
|
6744 | | - if (output_format & DIFF_FORMAT_NO_OUTPUT && |
| 6772 | + if ((!output_format || output_format & DIFF_FORMAT_NO_OUTPUT) && |
6745 | 6773 | options->flags.exit_with_status && |
6746 | 6774 | options->flags.diff_from_contents) { |
6747 | 6775 | /* |
|
0 commit comments