[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>
Junio C Hamano committed
Sep 6, 2005 at 12:53 UTC
4d3fe0c5f342d0b00209916cf6951c2f8db414d2
2 files changed
+44
-8
read-tree.c
+28
-8
@@ -3,6 +3,8 @@
3
*
4
* Copyright (C) Linus Torvalds, 2005
5
*/
6
+#define DBRT_DEBUG 1
7
+
8
#include "cache.h"
9
10
#include "object.h"
@@ -47,8 +49,6 @@ static int entcmp(char *name1, int dir1, char *name2, int dir2)
49
return ret;
50
}
51
50
-#define DBRT_DEBUG 0
51
-
52
static int unpack_trees_rec(struct tree_entry_list **posns, int len,
53
const char *base, merge_fn_t fn, int *indpos)
54
{
@@ -101,14 +101,14 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
101
}
102
}
103
104
-#if DBRT_DEBUG
104
+#if DBRT_DEBUG > 1
105
if (first)
106
printf("index %s\n", first);
107
#endif
108
for (i = 0; i < len; i++) {
109
if (!posns[i] || posns[i] == &df_conflict_list)
110
continue;
111
-#if DBRT_DEBUG
111
+#if DBRT_DEBUG > 1
112
printf("%d %s\n", i + 1, posns[i]->name);
113
#endif
114
if (!first || entcmp(first, firstdir,
@@ -188,7 +188,7 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
188
if (merge) {
189
int ret;
190
191
-#if DBRT_DEBUG
191
+#if DBRT_DEBUG > 1
192
printf("%s:\n", first);
193
for (i = 0; i < src_size; i++) {
194
printf(" %d ", i);
@@ -200,7 +200,7 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
200
#endif
201
ret = fn(src);
202
203
-#if DBRT_DEBUG
203
+#if DBRT_DEBUG > 1
204
printf("Added %d entries\n", ret);
205
#endif
206
*indpos += ret;
@@ -353,6 +353,19 @@ static int keep_entry(struct cache_entry *ce)
353
return 1;
354
}
355
356
+#if DBRT_DEBUG
357
+static void show_stage_entry(FILE *o,
358
+ const char *label, const struct cache_entry *ce)
359
+{
360
+ fprintf(stderr, "%s%06o %s %d\t%s\n",
361
+ label,
362
+ ntohl(ce->ce_mode),
363
+ sha1_to_hex(ce->sha1),
364
+ ce_stage(ce),
365
+ ce->name);
366
+}
367
+#endif
368
+
369
static int threeway_merge(struct cache_entry **stages)
370
{
371
struct cache_entry *index;
@@ -392,10 +405,10 @@ static int threeway_merge(struct cache_entry **stages)
405
if (!same(remote, head)) {
406
for (i = 1; i < head_idx; i++) {
407
if (same(stages[i], head)) {
395
- head_match = 1;
408
+ head_match = i;
409
}
410
if (same(stages[i], remote)) {
398
- remote_match = 1;
411
+ remote_match = i;
412
}
413
}
414
}
@@ -450,6 +463,13 @@ static int threeway_merge(struct cache_entry **stages)
463
}
464
}
465
}
466
+#if DBRT_DEBUG
467
+ else {
468
+ fprintf(stderr, "read-tree: warning #16 detected\n");
469
+ show_stage_entry(stderr, "head ", stages[head_match]);
470
+ show_stage_entry(stderr, "remote ", stages[remote_match]);
471
+ }
472
+#endif
473
if (head) { count += keep_entry(head); }
474
if (remote) { count += keep_entry(remote); }
475
return count;
t/t1000-read-tree-m-3way.sh
+16
@@ -218,6 +218,9 @@ currently implemented.
218
or (2) match B.
219
------------------------------------------------------------------
220
15 exists O==A O==B take B must match A if exists.
221
+ ------------------------------------------------------------------
222
+ 16 exists O==A O==B barf must match A if exists.
223
+ *multi* in one in another
224
-------------------------------------------------------------------
225
226
Note: if we want to implement 2ALT and 3ALT we need to be careful.
@@ -514,4 +517,17 @@ test_expect_failure \
517
git-update-index --add NN &&
518
git-read-tree -m $tree_O $tree_A $tree_B"
519
520
+# #16
521
+test_expect_success \
522
+ '16 - A matches in one and B matches in another.' \
523
+ 'rm -f .git/index F16 &&
524
+ echo F16 >F16 &&
525
+ git-update-index --add F16 &&
526
+ tree0=`git-write-tree` &&
527
+ echo E16 >F16 &&
528
+ git-update-index F16 &&
529
+ tree1=`git-write-tree` &&
530
+ git-read-tree -m $tree0 $tree1 $tree1 $tree0 &&
531
+ git-ls-files --stage'
532
+
533
test_done