@matheusbsbs / matheus-bagliano / commits / ba655da537
Fork 0

read-tree --debug-unpack

A debugging patch. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Sep 14, 2009 at 02:22 UTC ba655da537a999670c7b21e0446e774a1f9733ea
3 files changed +72
builtin-read-tree.c
+36
@@ -64,6 +64,34 @@ static int exclude_per_directory_cb(const struct option *opt, const char *arg,
64 return 0;
65 }
66
67 +static void debug_stage(const char *label, struct cache_entry *ce,
68 + struct unpack_trees_options *o)
69 +{
70 + printf("%s ", label);
71 + if (!ce)
72 + printf("(missing)\n");
73 + else if (ce == o->df_conflict_entry)
74 + printf("(conflict)\n");
75 + else
76 + printf("%06o #%d %s %.8s\n",
77 + ce->ce_mode, ce_stage(ce), ce->name,
78 + sha1_to_hex(ce->sha1));
79 +}
80 +
81 +static int debug_merge(struct cache_entry **stages, struct unpack_trees_options *o)
82 +{
83 + int i;
84 +
85 + printf("* %d-way merge\n", o->merge_size);
86 + debug_stage("index", stages[0], o);
87 + for (i = 1; i <= o->merge_size; i++) {
88 + char buf[24];
89 + sprintf(buf, "ent#%d", i);
90 + debug_stage(buf, stages[i], o);
91 + }
92 + return 0;
93 +}
94 +
95 static struct lock_file lock_file;
96
97 int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
@@ -98,6 +126,8 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
126 PARSE_OPT_NONEG, exclude_per_directory_cb },
127 OPT_SET_INT('i', NULL, &opts.index_only,
128 "don't check the working tree after merging", 1),
129 + OPT_SET_INT(0, "debug-unpack", &opts.debug_unpack,
130 + "debug unpack-trees", 1),
131 OPT_END()
132 };
133
@@ -165,6 +195,9 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
195 opts.head_idx = 1;
196 }
197
198 + if (opts.debug_unpack)
199 + opts.fn = debug_merge;
200 +
201 cache_tree_free(&active_cache_tree);
202 for (i = 0; i < nr_trees; i++) {
203 struct tree *tree = trees[i];
@@ -174,6 +207,9 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
207 if (unpack_trees(nr_trees, t, &opts))
208 return 128;
209
210 + if (opts.debug_unpack)
211 + return 0; /* do not write the index out */
212 +
213 /*
214 * When reading only one tree (either the most basic form,
215 * "-m ent" or "--reset ent" form), we can obtain a fully
unpack-trees.c
+35
@@ -501,6 +501,38 @@ static struct cache_entry *find_cache_entry(struct traverse_info *info,
501 return NULL;
502 }
503
504 +static void debug_path(struct traverse_info *info)
505 +{
506 + if (info->prev) {
507 + debug_path(info->prev);
508 + if (*info->prev->name.path)
509 + putchar('/');
510 + }
511 + printf("%s", info->name.path);
512 +}
513 +
514 +static void debug_name_entry(int i, struct name_entry *n)
515 +{
516 + printf("ent#%d %06o %s\n", i,
517 + n->path ? n->mode : 0,
518 + n->path ? n->path : "(missing)");
519 +}
520 +
521 +static void debug_unpack_callback(int n,
522 + unsigned long mask,
523 + unsigned long dirmask,
524 + struct name_entry *names,
525 + struct traverse_info *info)
526 +{
527 + int i;
528 + printf("* unpack mask %lu, dirmask %lu, cnt %d ",
529 + mask, dirmask, n);
530 + debug_path(info);
531 + putchar('\n');
532 + for (i = 0; i < n; i++)
533 + debug_name_entry(i, names + i);
534 +}
535 +
536 static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, struct name_entry *names, struct traverse_info *info)
537 {
538 struct cache_entry *src[MAX_UNPACK_TREES + 1] = { NULL, };
@@ -511,6 +543,9 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str
543 while (!p->mode)
544 p++;
545
546 + if (o->debug_unpack)
547 + debug_unpack_callback(n, mask, dirmask, names, info);
548 +
549 /* Are we supposed to look at the index too? */
550 if (o->merge) {
551 while (1) {
unpack-trees.h
+1
@@ -28,6 +28,7 @@ struct unpack_trees_options {
28 skip_unmerged,
29 initial_checkout,
30 diff_index_cached,
31 + debug_unpack,
32 gently;
33 const char *prefix;
34 int cache_bottom;