@@ -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+
6795static struct lock_file lock_file ;
6896
6997int 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
0 commit comments