[PATCH] builtin-revert.c: Make use of merge_recursive()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Cherry-pick and revert always ran the merging in a separate process.
This patch makes cherry-pick/revert call merge_recursive() instead
of running git-merge-recursive.

Signed-off-by: Stephan Beyer <s-beyer@xxxxxxx>
---
	Hi,
	I wonder if this patch fits in line.

 builtin-merge-recursive.c |    2 +-
 builtin-revert.c          |   41 ++++++++++++++++++++++-------------------
 merge-recursive.h         |    1 +
 3 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/builtin-merge-recursive.c b/builtin-merge-recursive.c
index 09aa830..d8bd21f 100644
--- a/builtin-merge-recursive.c
+++ b/builtin-merge-recursive.c
@@ -1327,7 +1327,7 @@ static const char *better_branch_name(const char *branch)
 	return name ? name : branch;
 }
 
-static struct commit *get_ref(const char *ref)
+struct commit *get_ref(const char *ref)
 {
 	unsigned char sha1[20];
 	struct object *object;
diff --git a/builtin-revert.c b/builtin-revert.c
index 27881e9..c54cf8a 100644
--- a/builtin-revert.c
+++ b/builtin-revert.c
@@ -11,6 +11,7 @@
 #include "cache-tree.h"
 #include "diff.h"
 #include "revision.h"
+#include "merge-recursive.h"
 
 /*
  * This implements the builtins revert and cherry-pick.
@@ -200,18 +201,14 @@ static void set_author_ident_env(const char *message)
 			sha1_to_hex(commit->object.sha1));
 }
 
-static int merge_recursive(const char *base_sha1,
+static int merge_recursive_helper(const char *base_sha1,
 		const char *head_sha1, const char *head_name,
 		const char *next_sha1, const char *next_name)
 {
-	char buffer[256];
-	const char *argv[6];
-	int i = 0;
-
-	sprintf(buffer, "GITHEAD_%s", head_sha1);
-	setenv(buffer, head_name, 1);
-	sprintf(buffer, "GITHEAD_%s", next_sha1);
-	setenv(buffer, next_name, 1);
+	int clean, index_fd;
+	struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
+	struct commit *result, *h1, *h2;
+	struct commit_list *ca = NULL;
 
 	/*
 	 * This three way merge is an interesting one.  We are at
@@ -219,15 +216,21 @@ static int merge_recursive(const char *base_sha1,
 	 * and $prev on top of us (when reverting), or the change between
 	 * $prev and $commit on top of us (when cherry-picking or replaying).
 	 */
-	argv[i++] = "merge-recursive";
-	if (base_sha1)
-		argv[i++] = base_sha1;
-	argv[i++] = "--";
-	argv[i++] = head_sha1;
-	argv[i++] = next_sha1;
-	argv[i++] = NULL;
-
-	return run_command_v_opt(argv, RUN_COMMAND_NO_STDIN | RUN_GIT_CMD);
+	if (base_sha1) {
+		struct commit *base = get_ref(base_sha1);
+		commit_list_insert(base, &ca);
+	}
+	h1 = get_ref(head_sha1);
+	h2 = get_ref(next_sha1);
+
+	index_fd = hold_locked_index(lock, 1);
+	clean = merge_recursive(h1, h2, head_name, next_name, ca, &result);
+	if (active_cache_changed &&
+			(write_cache(index_fd, active_cache, active_nr) ||
+			 commit_locked_index(lock)))
+		die("Unable to write index.");
+
+	return clean ? 0 : 1;
 }
 
 static char *help_msg(const unsigned char *sha1)
@@ -373,7 +376,7 @@ static int revert_or_cherry_pick(int argc, const char **argv)
 		}
 	}
 
-	if (merge_recursive(base == NULL ?
+	if (merge_recursive_helper(base == NULL ?
 				NULL : sha1_to_hex(base->object.sha1),
 				sha1_to_hex(head), "HEAD",
 				sha1_to_hex(next->object.sha1), oneline) ||
diff --git a/merge-recursive.h b/merge-recursive.h
index f37630a..40f329b 100644
--- a/merge-recursive.h
+++ b/merge-recursive.h
@@ -1,6 +1,7 @@
 #ifndef MERGE_RECURSIVE_H
 #define MERGE_RECURSIVE_H
 
+struct commit *get_ref(const char *ref);
 int merge_recursive(struct commit *h1,
 		    struct commit *h2,
 		    const char *branch1,
-- 
1.6.0.rc2.264.g563b6

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux