git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephan Beyer <s-beyer@gmx.net>
To: Miklos Vajna <vmiklos@frugalware.org>,
	Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Stephan Beyer <s-beyer@gmx.net>
Subject: [PATCH (2)] Make builtin-revert.c use merge_recursive_generic()
Date: Tue, 12 Aug 2008 22:14:00 +0200	[thread overview]
Message-ID: <1218572040-23362-2-git-send-email-s-beyer@gmx.net> (raw)
In-Reply-To: <1218572040-23362-1-git-send-email-s-beyer@gmx.net>

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

The GITHEAD_* environment definitions are not needed anymore,
since the names are direct arguments to merge_recursive_generic().

Signed-off-by: Stephan Beyer <s-beyer@gmx.net>
---
	Hi,
	So this is now based on the new merge-recursive.c based on
	(1a) and (1b).
	The number of lines deleted and inserted tells me that we're
	doing something right here.

 builtin-revert.c |   50 +++++++++++++-------------------------------------
 1 files changed, 13 insertions(+), 37 deletions(-)

diff --git a/builtin-revert.c b/builtin-revert.c
index 27881e9..2a724ca 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,36 +201,6 @@ static void set_author_ident_env(const char *message)
 			sha1_to_hex(commit->object.sha1));
 }
 
-static int merge_recursive(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);
-
-	/*
-	 * This three way merge is an interesting one.  We are at
-	 * $head, and would want to apply the change between $commit
-	 * 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);
-}
-
 static char *help_msg(const unsigned char *sha1)
 {
 	static char helpbuf[1024];
@@ -266,12 +237,14 @@ static int revert_or_cherry_pick(int argc, const char **argv)
 {
 	unsigned char head[20];
 	struct commit *base, *next, *parent;
-	int i;
+	int i, fail;
 	char *oneline, *reencoded_message = NULL;
+	const char *base_list[] = { NULL, NULL };
 	const char *message, *encoding;
 	const char *defmsg = xstrdup(git_path("MERGE_MSG"));
 
-	git_config(git_default_config, NULL);
+	git_config(merge_recursive_config, NULL);
+	merge_recursive_setup(0);
 	me = action == REVERT ? "revert" : "cherry-pick";
 	setenv(GIT_REFLOG_ACTION, me, 0);
 	parse_args(argc, argv);
@@ -373,11 +346,14 @@ static int revert_or_cherry_pick(int argc, const char **argv)
 		}
 	}
 
-	if (merge_recursive(base == NULL ?
-				NULL : sha1_to_hex(base->object.sha1),
-				sha1_to_hex(head), "HEAD",
-				sha1_to_hex(next->object.sha1), oneline) ||
-			write_cache_as_tree(head, 0, NULL)) {
+	if (base)
+		base_list[0] = sha1_to_hex(base->object.sha1);
+	fail = merge_recursive_generic(base_list, head, "HEAD",
+						  next->object.sha1, oneline);
+	if (fail < 0)
+		exit(1);
+
+	if (fail || write_cache_as_tree(head, 0, NULL)) {
 		add_to_msg("\nConflicts:\n\n");
 		read_cache();
 		for (i = 0; i < active_nr;) {
-- 
1.6.0.rc2.281.g6f6cf

  reply	other threads:[~2008-08-12 20:15 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-10 13:20 [PATCH 0/2] Avoid run_command() for recursive in builtin-merge Miklos Vajna
2008-08-10 13:20 ` [PATCH 1/2] merge-recursive: prepare merge_recursive() to be called from builtins Miklos Vajna
2008-08-10 13:20   ` [PATCH 2/2] builtin-merge: avoid run_command_v_opt() for recursive Miklos Vajna
2008-08-11 18:47     ` Junio C Hamano
2008-08-11 19:07       ` Miklos Vajna
2008-08-11 20:03         ` Junio C Hamano
2008-08-11 20:45           ` Miklos Vajna
2008-08-11 20:48             ` [PATCH] Add a new test to ensure merging a submodule is handled properly Miklos Vajna
2008-08-11 15:13   ` [PATCH 1/2] merge-recursive: prepare merge_recursive() to be called from builtins Stephan Beyer
2008-08-11 16:46     ` Miklos Vajna
2008-08-11 19:53     ` Junio C Hamano
2008-08-11 20:46       ` Stephan Beyer
2008-08-11 15:03 ` [PATCH] builtin-revert.c: Make use of merge_recursive() Stephan Beyer
2008-08-11 15:47   ` Johannes Schindelin
2008-08-11 19:01     ` Stephan Beyer
2008-08-11 19:09       ` Miklos Vajna
2008-08-11 21:44         ` [PATCH] builtin-revert: " Stephan Beyer
2008-08-11 21:46           ` Stephan Beyer
2008-08-11 22:33             ` Junio C Hamano
2008-08-11 23:27           ` Junio C Hamano
2008-08-11 23:47             ` Stephan Beyer
2008-08-11 23:52               ` Junio C Hamano
2008-08-12 16:45             ` [PATCH] Split out merge_recursive() to merge-recursive.c Miklos Vajna
2008-08-12 17:56               ` Stephan Beyer
2008-08-12 21:40                 ` Miklos Vajna
2008-08-12 20:13               ` [PATCH (1b)] merge-recursive.c: Add more generic merge_recursive_generic() Stephan Beyer
2008-08-12 20:14                 ` Stephan Beyer [this message]
2008-08-12 21:44                 ` Miklos Vajna
2008-08-13 17:26                   ` Stephan Beyer
2008-08-13 20:13                     ` Miklos Vajna
2008-08-13  3:17                 ` Daniel Barkalow
2008-08-13 17:29                   ` Stephan Beyer
2008-08-13 17:54                     ` Daniel Barkalow
2008-08-13 19:55                       ` Junio C Hamano
2008-08-13 20:05                         ` Stephan Beyer
2008-08-13 20:36                         ` Daniel Barkalow
2008-08-13 21:45                           ` Junio C Hamano
2008-08-14  3:17               ` [PATCH] Split out merge_recursive() to merge-recursive.c Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1218572040-23362-2-git-send-email-s-beyer@gmx.net \
    --to=s-beyer@gmx.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=vmiklos@frugalware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).