git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH V2] git-apply: silence errors for success cases

From
Jerry Zhang <jerry@skydio.com>
Date
Jul 28, 2021, 03:14 UTC
Message-ID
<20210728031437.14257-1-jerry@skydio.com>
In-Reply-To
<xmqqwnsvw5xi.fsf@gitster.g>

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>
---
V1->V2: rebase onto master and rerun tests

I think I addressed previous comments. What are the next steps for this patch?

 apply.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/apply.c b/apply.c
index 44bc31d6eb..fb321c707b 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.32.0.1314.g6ed4fcc4cc
Previous: Junio C HamanoNext: Jerry Zhang
Message 4 of 5 in “git-apply: silence errors for success cases”
  1. git-apply: silence errors for success casesJerry Zhang, Apr 21, 2021
  2. Junio C HamanoApr 21, 2021
  3. Junio C HamanoApr 21, 2021
  4. git-apply: silence errors for success casesJerry Zhang, Jul 28, 2021
  5. Jerry ZhangDec 11, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.