merge-recursive: flush output buffer even when erroring out
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Mon, 1 Aug 2016 11:44:57 +0000 (13:44 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 1 Aug 2016 18:45:30 +0000 (11:45 -0700)
Ever since 66a155b (Enable output buffering in merge-recursive.,
2007-01-14), we had a problem: When the merge failed in a fatal way, all
regular output was swallowed because we called die() and did not get a
chance to drain the output buffers.

To fix this, several modifications were necessary:

- we needed to stop die()ing, to give callers a chance to do something
when an error occurred (in this case, flush the output buffers),

- we needed to delay printing the error message so that the caller can
print the buffered output before that, and

- we needed to make sure that the output buffers are flushed even when
the return value indicates an error.

The first two changes were introduced through earlier commits in this
patch series, and this commit addresses the third one.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
merge-recursive.c
index 9e527dec62a71940174a31a3a8040f2498ad6c73..c9e4dbc349243caed51ab524edf3d3ebb31a0d2c 100644 (file)
@@ -2069,8 +2069,10 @@ int merge_recursive(struct merge_options *o,
        o->ancestor = "merged common ancestors";
        clean = merge_trees(o, h1->tree, h2->tree, merged_common_ancestors->tree,
                            &mrtree);
-       if (clean < 0)
+       if (clean < 0) {
+               flush_output(o);
                return clean;
+       }
 
        if (o->call_depth) {
                *result = make_virtual_commit(mrtree, "merged tree");