Junio C Hamano <gitster@xxxxxxxxx> writes: > Jerry Zhang <jerry@xxxxxxxxxx> writes: > >> Certain invocations of "git apply --3way" >> will print error messages even though git >> is able to fall back on apply_fragments and >> apply the patch successfully with a return >> value of 0. To fix, return early from >> try_threeway() in the following cases: > > I suspect that this is a recent breakage after we swapped the order > of 3way fallback. It used to be that we tried the straight > application first (while suppressing the error messages) and then > fell back on 3way (while fully exposing the error messages). The other side of the coin is that we should say, before falling back to non-3way codepath, that we saw 3way application failed, and falling back to the straight patch, if we don't say so already with the recent change, just like we used to say the opposite after seeing the patch application to fail and then fell back to 3way. In other words, we may have said, under the verbose mode, that we are falling back to threeway only after seeing apply-fragments failed, but if we are doing 3-way first, telling that we are doing three-way application in try_threeway() function is actively wrong. The message was there only because try_threeway() was a fallback and sometimes did not happen even when the user asked to do --3way (hence deserved a message). Now we always try 3way first when the user asked, the extra message should be given only after try_threeway() failed and should talk about falling back to the straight application. IOW, a fix something along this line, perhaps, is needed to complete the "swap the order between 3way and direct application" series we earlier worked on. apply.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git i/apply.c w/apply.c index 8c5b29809b..6634305e9e 100644 --- i/apply.c +++ w/apply.c @@ -3570,7 +3570,7 @@ static int try_threeway(struct apply_state *state, read_blob_object(&buf, &pre_oid, patch->old_mode)) return error(_("repository lacks the necessary blob to perform 3-way merge.")); - if (state->apply_verbosity > verbosity_silent) + if (state->apply_verbosity > verbosity_silent && patch->direct_to_threeway) fprintf(stderr, _("Performing three-way merge...\n")); img = strbuf_detach(&buf, &len); @@ -3637,6 +3637,9 @@ static int apply_data(struct apply_state *state, struct patch *patch, return -1; if (!state->threeway || try_threeway(state, &image, patch, st, ce) < 0) { + if (state->threeway && !patch->direct_to_threeway) + fprintf(stderr, _("Falling back to direct application...\n")); + /* Note: with --reject, apply_fragments() returns 0 */ if (patch->direct_to_threeway || apply_fragments(state, &image, patch) < 0) return -1;