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

Re: [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 9, 2015, 20:46 UTC
Message-ID
<xmqqsi5jojmk.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<xmqq4mhzq41e.fsf@gitster.mtv.corp.google.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 5 quoted lines
> I think the most sensible regression fix as the first step at this
> point is to call it as a separate process, just like the code calls
> "apply" as a separate process for each patch.  Optimization can come
> later when it is shown that it matters---we need to regain
> correctness first.
And the fix would look like this, I think.

It passes the test Dscho's 3/2 adds to t5520 ;-) but that is not surprising.

---
Subject: [PATCH] am -3: do not let failed merge abort the error codepath

When "am" was rewritten in C, the codepath for falling back to three-way merge was mistakenly made to make an internal call to merge-recursive, disabling the error reporting code for certain types of errors merge-recursive detects and reports by calling die().

This is a quick-fix for correctness. The ideal endgame would be to replace run_command() in run_fallback_merge_recursive() with a direct call after making sure that internal call to merge-recursive does not die().

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/am.c | 49 +++++++++++++++++++++++++++++++++----------------
 1 file changed, 33 insertions(+), 16 deletions(-)
diff --git a/builtin/am.c b/builtin/am.c
index 4f77e07..c869796 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1590,16 +1590,44 @@ static int build_fake_ancestor(const struct am_state *state, const char *index_f
 }
 
 /**
+ * Do the three-way merge using fake ancestor, his tree constructed
+ * from the fake ancestor and the postimage of the patch, and our
+ * state.
+ */
+static int run_fallback_merge_recursive(const struct am_state *state,
+					unsigned char *orig_tree,
+					unsigned char *our_tree,
+					unsigned char *his_tree)
+{
+	struct child_process cp = CHILD_PROCESS_INIT;
+	int status;
+
+	cp.git_cmd = 1;
+
+	argv_array_pushf(&cp.env_array, "GITHEAD_%s=%.*s",
+			 sha1_to_hex(his_tree), linelen(state->msg), state->msg);
+	if (state->quiet)
+		argv_array_push(&cp.env_array, "GIT_MERGE_VERBOSITY=0");
+
+	argv_array_push(&cp.args, "merge-recursive");
+	argv_array_push(&cp.args, sha1_to_hex(orig_tree));
+	argv_array_push(&cp.args, "--");
+	argv_array_push(&cp.args, sha1_to_hex(our_tree));
+	argv_array_push(&cp.args, sha1_to_hex(his_tree));
+
+	status = run_command(&cp) ? (-1) : 0;
+	discard_cache();
+	read_cache();
+	return status;
+}
+
+/**
  * Attempt a threeway merge, using index_path as the temporary index.
  */
 static int fall_back_threeway(const struct am_state *state, const char *index_path)
 {
 	unsigned char orig_tree[GIT_SHA1_RAWSZ], his_tree[GIT_SHA1_RAWSZ],
 		      our_tree[GIT_SHA1_RAWSZ];
-	const unsigned char *bases[1] = {orig_tree};
-	struct merge_options o;
-	struct commit *result;
-	char *his_tree_name;
 
 	if (get_sha1("HEAD", our_tree) < 0)
 		hashcpy(our_tree, EMPTY_TREE_SHA1_BIN);
@@ -1651,22 +1679,11 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
 	 * changes.
 	 */
 
-	init_merge_options(&o);
-
-	o.branch1 = "HEAD";
-	his_tree_name = xstrfmt("%.*s", linelen(state->msg), state->msg);
-	o.branch2 = his_tree_name;
-
-	if (state->quiet)
-		o.verbosity = 0;
-
-	if (merge_recursive_generic(&o, our_tree, his_tree, 1, bases, &result)) {
+	if (run_fallback_merge_recursive(state, orig_tree, our_tree, his_tree)) {
 		rerere(state->allow_rerere_autoupdate);
-		free(his_tree_name);
 		return error(_("Failed to merge in the changes."));
 	}
 
-	free(his_tree_name);
 	return 0;
 }
 
-- 
2.6.1-296-ge15092e
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 19 of 22 in “Reinstate the helpful message when `git pull --rebase` fails”
  1. 0/2 Reinstate the helpful message when `git pull --rebase` failsJohannes Schindelin, Oct 8, 2015
  2. 1/2 merge_recursive_options: introduce the "gentle" flagJohannes Schindelin, Oct 8, 2015
  3. 2/2 pull --rebase: reinstate helpful message on abortJohannes Schindelin, Oct 8, 2015
  4. Junio C HamanoOct 9, 2015
  5. Johannes SchindelinOct 12, 2015
  6. Junio C HamanoOct 12, 2015
  7. Junio C HamanoOct 9, 2015
  8. Paul TanOct 9, 2015
  9. Johannes SchindelinOct 9, 2015
  10. Johannes SchindelinOct 9, 2015
  11. Junio C HamanoOct 9, 2015
  12. Torsten BögershausenOct 10, 2015
  13. Torsten BögershausenOct 10, 2015
  14. Johannes SchindelinOct 12, 2015
  15. Junio C HamanoOct 9, 2015
  16. Junio C HamanoOct 9, 2015
  17. Junio C HamanoOct 9, 2015
  18. Johannes SchindelinOct 12, 2015
  19. Junio C HamanoOct 9, 2015
  20. Johannes SchindelinOct 12, 2015
  21. Junio C HamanoOct 12, 2015
  22. Johannes SchindelinOct 13, 2015

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.