Skip to content

Commit ba655da

Browse files
committed
read-tree --debug-unpack
A debugging patch. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 730f728 commit ba655da

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

builtin-read-tree.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,34 @@ static int exclude_per_directory_cb(const struct option *opt, const char *arg,
6464
return 0;
6565
}
6666

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+
6795
static struct lock_file lock_file;
6896

6997
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)
98126
PARSE_OPT_NONEG, exclude_per_directory_cb },
99127
OPT_SET_INT('i', NULL, &opts.index_only,
100128
"don't check the working tree after merging", 1),
129+
OPT_SET_INT(0, "debug-unpack", &opts.debug_unpack,
130+
"debug unpack-trees", 1),
101131
OPT_END()
102132
};
103133

@@ -165,6 +195,9 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
165195
opts.head_idx = 1;
166196
}
167197

198+
if (opts.debug_unpack)
199+
opts.fn = debug_merge;
200+
168201
cache_tree_free(&active_cache_tree);
169202
for (i = 0; i < nr_trees; i++) {
170203
struct tree *tree = trees[i];
@@ -174,6 +207,9 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
174207
if (unpack_trees(nr_trees, t, &opts))
175208
return 128;
176209

210+
if (opts.debug_unpack)
211+
return 0; /* do not write the index out */
212+
177213
/*
178214
* When reading only one tree (either the most basic form,
179215
* "-m ent" or "--reset ent" form), we can obtain a fully

unpack-trees.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,38 @@ static struct cache_entry *find_cache_entry(struct traverse_info *info,
501501
return NULL;
502502
}
503503

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+
504536
static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, struct name_entry *names, struct traverse_info *info)
505537
{
506538
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
511543
while (!p->mode)
512544
p++;
513545

546+
if (o->debug_unpack)
547+
debug_unpack_callback(n, mask, dirmask, names, info);
548+
514549
/* Are we supposed to look at the index too? */
515550
if (o->merge) {
516551
while (1) {

unpack-trees.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct unpack_trees_options {
2828
skip_unmerged,
2929
initial_checkout,
3030
diff_index_cached,
31+
debug_unpack,
3132
gently;
3233
const char *prefix;
3334
int cache_bottom;

0 commit comments

Comments
 (0)