@@ -23,6 +23,13 @@ static int ls_options;
23
23
static struct pathspec pathspec ;
24
24
static int chomp_prefix ;
25
25
static 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
+ };
26
33
27
34
static const char * const ls_tree_usage [] = {
28
35
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
64
71
return 0 ;
65
72
}
66
73
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 )
70
75
{
71
- size_t baselen = base -> len ;
76
+ size_t baselen = data -> base -> len ;
72
77
73
78
if (cmdmode == MODE_LONG ) {
74
79
char size_text [24 ];
75
- if (type == OBJ_BLOB ) {
80
+ if (data -> type == OBJ_BLOB ) {
76
81
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 )
78
83
xsnprintf (size_text , sizeof (size_text ), "BAD" );
79
84
else
80
85
xsnprintf (size_text , sizeof (size_text ),
81
86
"%" PRIuMAX , (uintmax_t )size );
82
87
} else {
83
88
xsnprintf (size_text , sizeof (size_text ), "-" );
84
89
}
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 );
87
92
} 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 ));
90
95
}
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 ,
94
99
chomp_prefix ? ls_tree_prefix : NULL , stdout ,
95
100
line_termination );
96
- strbuf_setlen (base , baselen );
101
+ strbuf_setlen (data -> base , baselen );
97
102
return 1 ;
98
103
}
99
104
@@ -103,6 +108,13 @@ static int show_tree(const struct object_id *oid, struct strbuf *base,
103
108
int recurse = 0 ;
104
109
size_t baselen ;
105
110
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
+ };
106
118
107
119
if (type == OBJ_BLOB ) {
108
120
if (ls_options & LS_TREE_ONLY )
@@ -128,7 +140,7 @@ static int show_tree(const struct object_id *oid, struct strbuf *base,
128
140
(!ls_options || (ls_options & LS_RECURSIVE )
129
141
|| (ls_options & LS_SHOW_TREES )
130
142
|| (ls_options & LS_TREE_ONLY )))
131
- show_default (oid , type , pathname , mode , base );
143
+ show_default (& data );
132
144
133
145
return recurse ;
134
146
}
0 commit comments