git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git-apply: silence errors for success cases
@ 2021-04-21  0:47 Jerry Zhang
  2021-04-21  2:14 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Jerry Zhang @ 2021-04-21  0:47 UTC (permalink / raw)
  To: git, gitster; +Cc: ross, abe, brian.kubisiak, Jerry Zhang

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:

When the patch is a rename and no lines have
changed. In this case, "git diff" doesn't
record the blob info, so 3way is neither
possible nor necessary.

When the patch is an addition and there is
no add/add conflict, i.e. direct_to_threeway
is false. In this case, threeway will fail
since the preimage is not in cache, but isn't
necessary anyway since there is no conflict.

Only error messaging is affected and other
behavior does not change.

Signed-off-by: Jerry Zhang <jerry@skydio.com>
---
 apply.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/apply.c b/apply.c
index 8c5b29809b..a36d4002ca 100644
--- a/apply.c
+++ b/apply.c
@@ -3560,7 +3560,9 @@ static int try_threeway(struct apply_state *state,
 
 	/* No point falling back to 3-way merge in these cases */
 	if (patch->is_delete ||
-	    S_ISGITLINK(patch->old_mode) || S_ISGITLINK(patch->new_mode))
+	    S_ISGITLINK(patch->old_mode) || S_ISGITLINK(patch->new_mode) ||
+	    (patch->is_new && !patch->direct_to_threeway) ||
+	    (patch->is_rename && !patch->lines_added && !patch->lines_deleted))
 		return -1;
 
 	/* Preimage the patch was prepared for */
-- 
2.29.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-12-11  2:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-21  0:47 [PATCH] git-apply: silence errors for success cases Jerry Zhang
2021-04-21  2:14 ` Junio C Hamano
2021-04-21 23:53   ` Junio C Hamano
2021-07-28  3:14     ` [PATCH V2] " Jerry Zhang
2021-12-11  2:05       ` Jerry Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).