Skip to content

Commit 7677417

Browse files
avargitster
authored andcommitted
ls-tree: don't use "show_tree_data" for "fast" callbacks
As noted in [1] the code that made it in as part of 9c4d58f (ls-tree: split up "fast path" callbacks, 2022-03-23) was a "maybe a good idea, maybe not" RFC-quality patch. I hadn't looked very carefully at the resulting patterns. The implementation shared the "struct show_tree_data data", which was introduced in e815171 (ls-tree: introduce struct "show_tree_data", 2022-03-23) both for use in 455923e (ls-tree: introduce "--format" option, 2022-03-23), and because the "fat" callback hadn't been split up as 9c4d58f did. Now that that's been done we can see that most of what show_tree_common() was doing could be done lazily by the callbacks themselves, who in the pre-image were often using an odd mis-match of their own arguments and those same arguments stuck into the "data" structure. Let's also have the callers initialize the "type", rather than grabbing it from the "data" structure afterwards. 1. https://lore.kernel.org/git/[email protected]/ Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Teng Long <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c48035d commit 7677417

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

builtin/ls-tree.c

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,11 @@ static int show_tree_fmt(const struct object_id *oid, struct strbuf *base,
173173
return recurse;
174174
}
175175

176-
static int show_tree_common(struct show_tree_data *data, int *recurse,
177-
const struct object_id *oid, struct strbuf *base,
178-
const char *pathname, unsigned mode)
176+
static int show_tree_common(int *recurse, struct strbuf *base,
177+
const char *pathname, enum object_type type)
179178
{
180-
enum object_type type = object_type(mode);
181179
int ret = -1;
182-
183180
*recurse = 0;
184-
data->mode = mode;
185-
data->type = type;
186-
data->oid = oid;
187-
data->pathname = pathname;
188-
data->base = base;
189181

190182
if (type == OBJ_BLOB) {
191183
if (ls_options & LS_TREE_ONLY)
@@ -217,15 +209,15 @@ static int show_tree_default(const struct object_id *oid, struct strbuf *base,
217209
{
218210
int early;
219211
int recurse;
220-
struct show_tree_data data = { 0 };
212+
enum object_type type = object_type(mode);
221213

222-
early = show_tree_common(&data, &recurse, oid, base, pathname, mode);
214+
early = show_tree_common(&recurse, base, pathname, type);
223215
if (early >= 0)
224216
return early;
225217

226-
printf("%06o %s %s\t", data.mode, type_name(data.type),
227-
find_unique_abbrev(data.oid, abbrev));
228-
show_tree_common_default_long(base, pathname, data.base->len);
218+
printf("%06o %s %s\t", mode, type_name(object_type(mode)),
219+
find_unique_abbrev(oid, abbrev));
220+
show_tree_common_default_long(base, pathname, base->len);
229221
return recurse;
230222
}
231223

@@ -235,16 +227,16 @@ static int show_tree_long(const struct object_id *oid, struct strbuf *base,
235227
{
236228
int early;
237229
int recurse;
238-
struct show_tree_data data = { 0 };
239230
char size_text[24];
231+
enum object_type type = object_type(mode);
240232

241-
early = show_tree_common(&data, &recurse, oid, base, pathname, mode);
233+
early = show_tree_common(&recurse, base, pathname, type);
242234
if (early >= 0)
243235
return early;
244236

245-
if (data.type == OBJ_BLOB) {
237+
if (type == OBJ_BLOB) {
246238
unsigned long size;
247-
if (oid_object_info(the_repository, data.oid, &size) == OBJ_BAD)
239+
if (oid_object_info(the_repository, oid, &size) == OBJ_BAD)
248240
xsnprintf(size_text, sizeof(size_text), "BAD");
249241
else
250242
xsnprintf(size_text, sizeof(size_text),
@@ -253,9 +245,9 @@ static int show_tree_long(const struct object_id *oid, struct strbuf *base,
253245
xsnprintf(size_text, sizeof(size_text), "-");
254246
}
255247

256-
printf("%06o %s %s %7s\t", data.mode, type_name(data.type),
257-
find_unique_abbrev(data.oid, abbrev), size_text);
258-
show_tree_common_default_long(base, pathname, data.base->len);
248+
printf("%06o %s %s %7s\t", mode, type_name(type),
249+
find_unique_abbrev(oid, abbrev), size_text);
250+
show_tree_common_default_long(base, pathname, base->len);
259251
return recurse;
260252
}
261253

@@ -266,9 +258,9 @@ static int show_tree_name_only(const struct object_id *oid, struct strbuf *base,
266258
int early;
267259
int recurse;
268260
const size_t baselen = base->len;
269-
struct show_tree_data data = { 0 };
261+
enum object_type type = object_type(mode);
270262

271-
early = show_tree_common(&data, &recurse, oid, base, pathname, mode);
263+
early = show_tree_common(&recurse, base, pathname, type);
272264
if (early >= 0)
273265
return early;
274266

@@ -286,9 +278,9 @@ static int show_tree_object(const struct object_id *oid, struct strbuf *base,
286278
{
287279
int early;
288280
int recurse;
289-
struct show_tree_data data = { 0 };
281+
enum object_type type = object_type(mode);
290282

291-
early = show_tree_common(&data, &recurse, oid, base, pathname, mode);
283+
early = show_tree_common(&recurse, base, pathname, type);
292284
if (early >= 0)
293285
return early;
294286

0 commit comments

Comments
 (0)