git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: Daniel Barkalow <barkalow@iabervon.org>
Cc: git@vger.kernel.org
Subject: Re: Multi-ancestor read-tree notes
Date: Tue, 06 Sep 2005 13:03:28 -0700	[thread overview]
Message-ID: <7vbr36j75b.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: Pine.LNX.4.63.0509061228090.23242@iabervon.org

Daniel Barkalow <barkalow@iabervon.org> writes:

> Do you know if there's anything like case #16 in there? I'd be interested 
> to know if there's anything that gets handled automatically in different 
> ways depending on which single base is used, and doesn't require manual 
> intervention with multiple bases, because that's probably wrong.

Re-running the tests with the attached patch shows there weren't any.

> I didn't want to break the assumption of only one entry per stage in the 
> initial version. I'm also not sure that listing the ancestors is 
> particularly useful in this case. They have to be exactly the contents of 
> stages 2 and 3, plus possibly more stuff that's not been kept by either 
> side.

Ah, I see, that's true.

> Great. Want me to send the patches with better organization, or are you 
> set with what I've sent?

That's up to you.  If you are content with what I have in the pu
branch, there is no need to bother resending.  OTOH if you have
further clean-ups in mind, i.e. "better organization" above, I
do not mind dropping the current ones from "pu" and replace them
with another set from you.

------------
[PATCH] Add debugging help for case #16 to read-tree.c

This will help us detect if real-world example merges have multiple
merge-base candidates and one of them matches one head while another
matches the other head.

Signed-off-by: Junio C Hamano <junkio@cox.net>

---

 read-tree.c                 |   36 ++++++++++++++++++++++++++++--------
 t/t1000-read-tree-m-3way.sh |   16 ++++++++++++++++
 2 files changed, 44 insertions(+), 8 deletions(-)

6405d0aa729f4b060123e1235b3ddc074fdd01b7
diff --git a/read-tree.c b/read-tree.c
--- a/read-tree.c
+++ b/read-tree.c
@@ -3,6 +3,8 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
+#define DBRT_DEBUG 1
+
 #include "cache.h"
 
 #include "object.h"
@@ -47,8 +49,6 @@ static int entcmp(char *name1, int dir1,
 	return ret;
 }
 
-#define DBRT_DEBUG 0
-
 static int unpack_trees_rec(struct tree_entry_list **posns, int len,
 			    const char *base, merge_fn_t fn, int *indpos)
 {
@@ -101,14 +101,14 @@ static int unpack_trees_rec(struct tree_
 			}
 		}
 
-#if DBRT_DEBUG
+#if DBRT_DEBUG > 1
 		if (first)
 			printf("index %s\n", first);
 #endif
 		for (i = 0; i < len; i++) {
 			if (!posns[i] || posns[i] == &df_conflict_list)
 				continue;
-#if DBRT_DEBUG
+#if DBRT_DEBUG > 1
 			printf("%d %s\n", i + 1, posns[i]->name);
 #endif
 			if (!first || entcmp(first, firstdir,
@@ -188,7 +188,7 @@ static int unpack_trees_rec(struct tree_
 			if (merge) {
 				int ret;
 
-#if DBRT_DEBUG
+#if DBRT_DEBUG > 1
 				printf("%s:\n", first);
 				for (i = 0; i < src_size; i++) {
 					printf(" %d ", i);
@@ -200,7 +200,7 @@ static int unpack_trees_rec(struct tree_
 #endif
 				ret = fn(src);
 				
-#if DBRT_DEBUG
+#if DBRT_DEBUG > 1
 				printf("Added %d entries\n", ret);
 #endif
 				*indpos += ret;
@@ -353,6 +353,19 @@ static int keep_entry(struct cache_entry
 	return 1;
 }
 
+#if DBRT_DEBUG
+static void show_stage_entry(FILE *o,
+			     const char *label, const struct cache_entry *ce)
+{
+	fprintf(stderr, "%s%06o %s %d\t%s\n",
+		label,
+		ntohl(ce->ce_mode),
+		sha1_to_hex(ce->sha1),
+		ce_stage(ce),
+		ce->name);
+}
+#endif
+
 static int threeway_merge(struct cache_entry **stages)
 {
 	struct cache_entry *index;
@@ -392,10 +405,10 @@ static int threeway_merge(struct cache_e
 	if (!same(remote, head)) {
 		for (i = 1; i < head_idx; i++) {
 			if (same(stages[i], head)) {
-				head_match = 1;
+				head_match = i;
 			}
 			if (same(stages[i], remote)) {
-				remote_match = 1;
+				remote_match = i;
 			}
 		}
 	}
@@ -450,6 +463,13 @@ static int threeway_merge(struct cache_e
 			}
 		}
 	}
+#if DBRT_DEBUG
+	else {
+		fprintf(stderr, "read-tree: warning #16 detected\n");
+		show_stage_entry(stderr, "head   ", stages[head_match]);
+		show_stage_entry(stderr, "remote ", stages[remote_match]);
+	}
+#endif
 	if (head) { count += keep_entry(head); }
 	if (remote) { count += keep_entry(remote); }
 	return count;
diff --git a/t/t1000-read-tree-m-3way.sh b/t/t1000-read-tree-m-3way.sh
--- a/t/t1000-read-tree-m-3way.sh
+++ b/t/t1000-read-tree-m-3way.sh
@@ -218,6 +218,9 @@ currently implemented.
                                            or (2) match B.
  ------------------------------------------------------------------
  15  exists  O==A    O==B      take B      must match A if exists.
+ ------------------------------------------------------------------
+ 16  exists  O==A    O==B      barf        must match A if exists.
+     *multi* in one  in another
 -------------------------------------------------------------------
 
 Note: if we want to implement 2ALT and 3ALT we need to be careful.
@@ -514,4 +517,17 @@ test_expect_failure \
      git-update-cache --add NN &&
      git-read-tree -m $tree_O $tree_A $tree_B"
 
+# #16
+test_expect_success \
+    '16 - A matches in one and B matches in another.' \
+    'rm -f .git/index F16 &&
+    echo F16 >F16 &&
+    git-update-cache --add F16 &&
+    tree0=`git-write-tree` &&
+    echo E16 >F16 &&
+    git-update-cache F16 &&
+    tree1=`git-write-tree` &&
+    git-read-tree -m $tree0 $tree1 $tree1 $tree0 &&
+    git-ls-files --stage'
+
 test_done

  reply	other threads:[~2005-09-06 20:04 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-05  5:41 Multi-ancestor read-tree notes Daniel Barkalow
2005-09-06  5:42 ` Junio C Hamano
2005-09-06 17:43   ` Daniel Barkalow
2005-09-06 20:03     ` Junio C Hamano [this message]
2005-09-06 20:25       ` Daniel Barkalow
2005-09-06 21:53         ` Junio C Hamano
2005-09-06 22:59           ` Daniel Barkalow
2005-09-10 22:50     ` Junio C Hamano
2005-09-10 22:56       ` Junio C Hamano
2005-09-08 17:16 ` Darrin Thompson
2005-09-08 20:37   ` Fredrik Kuivinen
2005-09-08 21:39   ` Daniel Barkalow
2005-09-08 21:54     ` Darrin Thompson
2005-09-08 22:00     ` Junio C Hamano
2005-09-08 22:10       ` Daniel Barkalow
2005-09-09 17:29 ` Junio C Hamano
2005-09-09 20:44   ` Daniel Barkalow
2005-09-11 16:45     ` Matthias Urlichs

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=7vbr36j75b.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=barkalow@iabervon.org \
    --cc=git@vger.kernel.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).