[PATCH 9/9] merge: use new "reset" function instead of running "git read-tree"

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

 



This simplifies "git merge" code and make it more efficient in some
cases.

Signed-off-by: Christian Couder <chriscool@xxxxxxxxxxxxx>
---
 builtin-merge.c |   31 +++++++++++--------------------
 1 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/builtin-merge.c b/builtin-merge.c
index 3aaec7b..de2343a 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -25,6 +25,7 @@
 #include "help.h"
 #include "merge-recursive.h"
 #include "resolve-undo.h"
+#include "reset.h"
 
 #define DEFAULT_TWOHEAD (1<<0)
 #define DEFAULT_OCTOPUS (1<<1)
@@ -231,24 +232,14 @@ static void save_state(void)
 		die("not a valid object: %s", buffer.buf);
 }
 
-static void reset_hard(unsigned const char *sha1, int verbose)
+static void reset_hard(const char *prefix, unsigned const char *sha1, int verbose)
 {
-	int i = 0;
-	const char *args[6];
-
-	args[i++] = "read-tree";
-	if (verbose)
-		args[i++] = "-v";
-	args[i++] = "--reset";
-	args[i++] = "-u";
-	args[i++] = sha1_to_hex(sha1);
-	args[i] = NULL;
-
-	if (run_command_v_opt(args, RUN_GIT_CMD))
-		die("read-tree failed");
+	int res = reset(sha1_to_hex(sha1), prefix, HARD, !verbose, 0, 0, NULL);
+	if (res)
+		die("hard reset failed");
 }
 
-static void restore_state(void)
+static void restore_state(const char *prefix)
 {
 	struct strbuf sb = STRBUF_INIT;
 	const char *args[] = { "stash", "apply", NULL, NULL };
@@ -256,7 +247,7 @@ static void restore_state(void)
 	if (is_null_sha1(stash))
 		return;
 
-	reset_hard(head, 1);
+	reset_hard(prefix, head, 1);
 
 	args[2] = sha1_to_hex(stash);
 
@@ -970,7 +961,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 			die("%s - not something we can merge", argv[0]);
 		update_ref("initial pull", "HEAD", remote_head->sha1, NULL, 0,
 				DIE_ON_ERR);
-		reset_hard(remote_head->sha1, 0);
+		reset_hard(prefix, remote_head->sha1, 0);
 		return 0;
 	} else {
 		struct strbuf msg = STRBUF_INIT;
@@ -1167,7 +1158,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		int ret;
 		if (i) {
 			printf("Rewinding the tree to pristine...\n");
-			restore_state();
+			restore_state(prefix);
 		}
 		if (use_strategies_nr != 1)
 			printf("Trying merge strategy %s...\n",
@@ -1228,7 +1219,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 	 * it up.
 	 */
 	if (!best_strategy) {
-		restore_state();
+		restore_state(prefix);
 		if (use_strategies_nr > 1)
 			fprintf(stderr,
 				"No merge strategy handled the merge.\n");
@@ -1240,7 +1231,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		; /* We already have its result in the working tree. */
 	else {
 		printf("Rewinding the tree to pristine...\n");
-		restore_state();
+		restore_state(prefix);
 		printf("Using the %s to prepare resolving by hand.\n",
 			best_strategy);
 		try_merge_strategy(best_strategy, common, head_arg);
-- 
1.6.6.1.557.g77031

--
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]