@@ -23,6 +23,13 @@ static int ls_options;
2323static struct pathspec pathspec ;
2424static int chomp_prefix ;
2525static const char * ls_tree_prefix ;
26+ struct show_tree_data {
27+ unsigned mode ;
28+ enum object_type type ;
29+ const struct object_id * oid ;
30+ const char * pathname ;
31+ struct strbuf * base ;
32+ };
2633
2734static const char * const ls_tree_usage [] = {
2835 N_ ("git ls-tree [<options>] <tree-ish> [<path>...]" ),
@@ -64,36 +71,34 @@ static int show_recursive(const char *base, size_t baselen, const char *pathname
6471 return 0 ;
6572}
6673
67- static int show_default (const struct object_id * oid , enum object_type type ,
68- const char * pathname , unsigned mode ,
69- struct strbuf * base )
74+ static int show_default (struct show_tree_data * data )
7075{
71- size_t baselen = base -> len ;
76+ size_t baselen = data -> base -> len ;
7277
7378 if (cmdmode == MODE_LONG ) {
7479 char size_text [24 ];
75- if (type == OBJ_BLOB ) {
80+ if (data -> type == OBJ_BLOB ) {
7681 unsigned long size ;
77- if (oid_object_info (the_repository , oid , & size ) == OBJ_BAD )
82+ if (oid_object_info (the_repository , data -> oid , & size ) == OBJ_BAD )
7883 xsnprintf (size_text , sizeof (size_text ), "BAD" );
7984 else
8085 xsnprintf (size_text , sizeof (size_text ),
8186 "%" PRIuMAX , (uintmax_t )size );
8287 } else {
8388 xsnprintf (size_text , sizeof (size_text ), "-" );
8489 }
85- printf ("%06o %s %s %7s\t" , mode , type_name (type ),
86- find_unique_abbrev (oid , abbrev ), size_text );
90+ printf ("%06o %s %s %7s\t" , data -> mode , type_name (data -> type ),
91+ find_unique_abbrev (data -> oid , abbrev ), size_text );
8792 } else {
88- printf ("%06o %s %s\t" , mode , type_name (type ),
89- find_unique_abbrev (oid , abbrev ));
93+ printf ("%06o %s %s\t" , data -> mode , type_name (data -> type ),
94+ find_unique_abbrev (data -> oid , abbrev ));
9095 }
91- baselen = base -> len ;
92- strbuf_addstr (base , pathname );
93- write_name_quoted_relative (base -> buf ,
96+ baselen = data -> base -> len ;
97+ strbuf_addstr (data -> base , data -> pathname );
98+ write_name_quoted_relative (data -> base -> buf ,
9499 chomp_prefix ? ls_tree_prefix : NULL , stdout ,
95100 line_termination );
96- strbuf_setlen (base , baselen );
101+ strbuf_setlen (data -> base , baselen );
97102 return 1 ;
98103}
99104
@@ -103,6 +108,13 @@ static int show_tree(const struct object_id *oid, struct strbuf *base,
103108 int recurse = 0 ;
104109 size_t baselen ;
105110 enum object_type type = object_type (mode );
111+ struct show_tree_data data = {
112+ .mode = mode ,
113+ .type = type ,
114+ .oid = oid ,
115+ .pathname = pathname ,
116+ .base = base ,
117+ };
106118
107119 if (type == OBJ_BLOB ) {
108120 if (ls_options & LS_TREE_ONLY )
@@ -128,7 +140,7 @@ static int show_tree(const struct object_id *oid, struct strbuf *base,
128140 (!ls_options || (ls_options & LS_RECURSIVE )
129141 || (ls_options & LS_SHOW_TREES )
130142 || (ls_options & LS_TREE_ONLY )))
131- show_default (oid , type , pathname , mode , base );
143+ show_default (& data );
132144
133145 return recurse ;
134146}
0 commit comments