aboutsummaryrefslogtreecommitdiff
path: root/builtin/am.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-11-03 15:32:39 -0800
committerJunio C Hamano <gitster@pobox.com>2015-11-03 15:32:39 -0800
commitced2321a8df8260e7d22e72e2bb5b8c6ab3f2180 (patch)
treed3a03df048d44183f43ae5506f5e5fe43c4154c5 /builtin/am.c
parentf5f76845961f4207b3dc8c186b2356f160276e45 (diff)
parentc63d4b2fe86876cc210d8bf22bd84d617f7815b7 (diff)
downloadgit-ced2321a8df8260e7d22e72e2bb5b8c6ab3f2180.tar.gz
git-ced2321a8df8260e7d22e72e2bb5b8c6ab3f2180.tar.xz
Merge branch 'jc/am-3-fallback-regression-fix' into maint
"git am -3" had a small regression where it is aborted in its error handling codepath when underlying merge-recursive failed in certain ways, as it assumed that the internal call to merge-recursive will never die, which is not the case (yet). * jc/am-3-fallback-regression-fix: am -3: do not let failed merge from completing the error codepath
Diffstat (limited to 'builtin/am.c')
-rw-r--r--builtin/am.c49
1 files changed, 33 insertions, 16 deletions
diff --git a/builtin/am.c b/builtin/am.c
index 98e29e044..4e396c832 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;
}