git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miklos Vajna <vmiklos@frugalware.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Stephan Beyer <s-beyer@gmx.net>
Subject: Re: What's cooking in git.git (Aug 2008, #05; Tue, 19)
Date: Mon, 1 Sep 2008 03:06:12 +0200	[thread overview]
Message-ID: <20080901010612.GC16514@genesis.frugalware.org> (raw)
In-Reply-To: <7v3al0zmv8.fsf@gitster.siamese.dyndns.org>

[-- Attachment #1: Type: text/plain, Size: 3467 bytes --]

On Tue, Aug 19, 2008 at 03:00:27PM -0700, Junio C Hamano <gitster@pobox.com> wrote:
> and the call chain would become:
> (...)
>     cmd_revert(), cmd_am(), cmd_checkout(), cmd_stash(), ...
>     -> merge_trees()

I tried to let cmd_revert() use merge_trees() only and not
merge_recursive_generic(), but something is fishy with it.

t3501-revert-cherry-pick passes fine, but t3404-rebase-interactive fail,
becase once we have a conflict, git diff --name-status says 'M' for the
given file and not 'U', which is obviously wrong.

I'm sending both patches: the one that works properly using
merge_recursive_generic() - and which one passes the testsuite here, and
the one that is elegant as it uses merge_trees(), but actually not
complete, at least regarding not adding the unmerged entries to the
index.

So, first here is my failed attempt to use merge_trees() inside
builtin-revert:

diff --git a/builtin-revert.c b/builtin-revert.c
index 3667705..3071518 100644
--- a/builtin-revert.c
+++ b/builtin-revert.c
@@ -12,6 +12,7 @@
 #include "diff.h"
 #include "revision.h"
 #include "rerere.h"
+#include "merge-recursive.h"
 
 /*
  * This implements the builtins revert and cherry-pick.
@@ -201,36 +202,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];
@@ -271,6 +242,8 @@ static int revert_or_cherry_pick(int argc, const char **argv)
 	char *oneline, *reencoded_message = NULL;
 	const char *message, *encoding;
 	const char *defmsg = xstrdup(git_path("MERGE_MSG"));
+	struct merge_options o;
+	struct tree *result;
 
 	git_config(git_default_config, NULL);
 	me = action == REVERT ? "revert" : "cherry-pick";
@@ -374,13 +347,16 @@ 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)) {
+	read_cache();
+	init_merge_options(&o);
+	o.branch1 = "HEAD";
+	o.branch2 = oneline;
+	parse_commit(next);
+	parse_commit(base);
+	if (!merge_trees(&o, lookup_commit_reference_gently(head, 0)->tree,
+				next->tree, base->tree, &result) ||
+		write_cache_as_tree(head, 0, NULL)) {
 		add_to_msg("\nConflicts:\n\n");
-		read_cache();
 		for (i = 0; i < active_nr;) {
 			struct cache_entry *ce = active_cache[i++];
 			if (ce_stage(ce)) {

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

  parent reply	other threads:[~2008-09-01  1:07 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-19  9:05 What's cooking in git.git (Aug 2008, #05; Tue, 19) Junio C Hamano
2008-08-19 11:02 ` Johannes Sixt
2008-08-19 12:35   ` Andreas Färber
2008-08-19 12:54 ` Miklos Vajna
2008-08-19 19:19   ` Junio C Hamano
2008-08-19 20:59     ` Miklos Vajna
2008-08-19 22:00       ` Junio C Hamano
2008-08-20 22:42         ` Miklos Vajna
2008-08-25  1:44         ` [PATCH] merge-recursive: introduce merge_options Miklos Vajna
2008-08-25  6:06           ` Junio C Hamano
2008-08-25 14:25             ` Miklos Vajna
2008-08-28  4:50               ` Junio C Hamano
2008-08-30 15:42               ` [PATCH] merge-recursive: fix subtree merge Miklos Vajna
2008-08-30 16:39                 ` Junio C Hamano
2008-08-30 17:55                 ` Junio C Hamano
2008-08-31 23:49                   ` Miklos Vajna
2008-09-01  1:06         ` Miklos Vajna [this message]
2008-09-01  1:09           ` [PATCH] builtin-revert: use merge_recursive_generic() Miklos Vajna
2008-09-02 20:02           ` What's cooking in git.git (Aug 2008, #05; Tue, 19) Junio C Hamano
2008-09-02 20:43             ` Junio C Hamano
2008-09-02 22:05             ` [PATCH 0/2] Move call_depth and index_only to struct merge_options Miklos Vajna
2008-09-02 22:05               ` [PATCH 1/2] merge-recursive: move call_depth " Miklos Vajna
2008-09-02 22:05                 ` [PATCH 2/2] merge-recursive: move index_only " Miklos Vajna
2008-09-02 22:13                 ` [PATCH] Makefile: add merge_recursive.h to LIB_H Miklos Vajna
2008-09-02 22:39                   ` Junio C Hamano
2008-09-02 23:49                     ` Miklos Vajna
2008-09-02 22:39               ` [PATCH 0/2] Move call_depth and index_only to struct merge_options Junio C Hamano
2008-09-03  0:16                 ` [PATCH] merge-recursive: get rid of the index_only global variable Miklos Vajna
2008-09-03  0:39                 ` [PATCH] merge-recursive: move the global obuf to struct merge_options Miklos Vajna
2008-09-03 17:34                   ` Miklos Vajna
2008-09-03 17:34                     ` [PATCH 1/2] merge-recursive: move current_{file,directory}_set " Miklos Vajna
2008-09-03 17:34                       ` [PATCH 2/2] merge-recursive: move make_virtual_commit()'s virtual_id to merge_options Miklos Vajna
2008-09-04 19:03                         ` Junio C Hamano
2008-09-05 17:26                           ` [PATCH] merge-recursive: get rid of virtual_id Miklos Vajna
2008-09-04 19:05                     ` [PATCH] merge-recursive: move the global obuf to struct merge_options 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=20080901010612.GC16514@genesis.frugalware.org \
    --to=vmiklos@frugalware.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=s-beyer@gmx.net \
    /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).