git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: git@vger.kernel.org
Cc: Stefan Monnier <monnier@iro.umontreal.ca>
Subject: [PATCH 06/10] merge_trees(): add ancestor label parameter for diff3-style output
Date: Mon, 15 Mar 2010 03:00:32 -0500	[thread overview]
Message-ID: <20100315080032.GF8824@progeny.tock> (raw)
In-Reply-To: <20100315074748.GA28827@progeny.tock>

Commands using the merge_trees() machinery will present conflict hunks
in output something like what ‘diff3 -m’ produces if the
merge.conflictstyle configuration option is set to diff3.

Unfortunately, the format is not fully compatible yet.  ‘diff3’
includes the name of the merge base on the ||||||| line of the output,
and tools can misparse the conflict hunks without it.  Add a new
o->ancestor parameter to merge_trees() for use as a label for the
ancestor in conflict hunks to give callers the power to rectify this
situation.

If o->ancestor is NULL, the output format is as before.  All callers
pass NULL, so this patch does not affect the outward behavior of git.

If o->ancestor is non-NULL and both branches renamed the base file
to the same name, that name is included in the conflict hunk labels.
Even if o->ancestor is NULL I think this would be a good change, but
this patch only does it in the non-NULL case to ensure the output
format does not change where it might matter.

Reported-by: Stefan Monnier <monnier@iro.umontreal.ca>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Another no-op.

 merge-recursive.c |   11 ++++++++---
 merge-recursive.h |    1 +
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/merge-recursive.c b/merge-recursive.c
index 3b2cc9d..017cafd 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -608,7 +608,7 @@ static int merge_3way(struct merge_options *o,
 		      const char *branch2)
 {
 	mmfile_t orig, src1, src2;
-	char *name1, *name2;
+	char *base_name, *name1, *name2;
 	int merge_status;
 	int favor;
 
@@ -628,10 +628,15 @@ static int merge_3way(struct merge_options *o,
 		}
 	}
 
-	if (strcmp(a->path, b->path)) {
+	if (strcmp(a->path, b->path) ||
+	    (o->ancestor != NULL && strcmp(a->path, one->path) != 0)) {
+		base_name = o->ancestor == NULL ? NULL :
+			xstrdup(mkpath("%s:%s", o->ancestor, one->path));
 		name1 = xstrdup(mkpath("%s:%s", branch1, a->path));
 		name2 = xstrdup(mkpath("%s:%s", branch2, b->path));
 	} else {
+		base_name = o->ancestor == NULL ? NULL :
+			xstrdup(mkpath("%s", o->ancestor));
 		name1 = xstrdup(mkpath("%s", branch1));
 		name2 = xstrdup(mkpath("%s", branch2));
 	}
@@ -640,7 +645,7 @@ static int merge_3way(struct merge_options *o,
 	read_mmblob(&src1, a->sha1);
 	read_mmblob(&src2, b->sha1);
 
-	merge_status = ll_merge(result_buf, a->path, &orig, NULL,
+	merge_status = ll_merge(result_buf, a->path, &orig, base_name,
 				&src1, name1, &src2, name2,
 				(!!o->call_depth) | (favor << 1));
 
diff --git a/merge-recursive.h b/merge-recursive.h
index be8410a..d1192f5 100644
--- a/merge-recursive.h
+++ b/merge-recursive.h
@@ -4,6 +4,7 @@
 #include "string-list.h"
 
 struct merge_options {
+	const char *ancestor;
 	const char *branch1;
 	const char *branch2;
 	enum {
-- 
1.7.0

  parent reply	other threads:[~2010-03-15  8:00 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20100305215253.364.63583.reportbug@localhost>
2010-03-05 22:19 ` git-core: conflictstyle=diff3 doesn't actually use diff3 compatible format Jonathan Nieder
2010-03-05 22:31   ` Junio C Hamano
2010-03-06 12:57     ` Bert Wesarg
2010-03-06 19:03       ` Junio C Hamano
2010-03-08  4:54     ` Jonathan Nieder
2010-03-15  7:47   ` [PATCH/RFC 0/10] Add label for common ancestor to conflictstyle=diff3 Jonathan Nieder
2010-03-15  7:49     ` [PATCH 01/10] xdl_merge(): add optional ancestor label to diff3-style output Jonathan Nieder
2010-03-15  8:10       ` Junio C Hamano
2010-03-15  8:35         ` Jonathan Nieder
2010-03-15  8:37           ` Junio C Hamano
2010-03-15  7:51     ` [PATCH 02/10] merge-file --diff3: add a label for ancestor Jonathan Nieder
2010-03-15  7:52     ` [PATCH 03/10] ll_merge(): add ancestor label parameter for diff3-style output Jonathan Nieder
2010-03-15  7:55     ` [PATCH 04/10] checkout --conflict=diff3: add a label for ancestor Jonathan Nieder
2010-03-15  8:20       ` Junio C Hamano
2010-03-15  8:32         ` Jonathan Nieder
2010-03-15  7:56     ` [PATCH 05/10] merge_file(): add comment explaining behavior wrt conflict style Jonathan Nieder
2010-03-15  8:00     ` Jonathan Nieder [this message]
2010-03-15  8:00     ` [PATCH 07/10] tests: document format of conflicts from checkout -m Jonathan Nieder
2010-03-15  8:01     ` [PATCH 08/10] checkout -m --conflict=diff3: add a label for ancestor Jonathan Nieder
2010-03-15  8:05     ` [PATCH 09/10] cherry-pick: " Jonathan Nieder
2010-03-15  8:07     ` [PATCH 10/10] merge-recursive: " Jonathan Nieder
2010-03-15  8:29       ` Junio C Hamano
2010-03-15 13:18       ` Stefan Monnier

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=20100315080032.GF8824@progeny.tock \
    --to=jrnieder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=monnier@iro.umontreal.ca \
    /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).