ls-tree: fold "show_tree_data" into "cb" struct

After the the preceding two commits the only user of the "show_tree_data" struct needed it along with the "options" member, let's instead fold all of that into a "show_tree_data" struct that we'll use only for that callback. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Teng Long <dyroneteng@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jan 12, 2023 at 17:11 UTC 65d1f6c9fa780eab5af6883e309637bddc63d75d
1 file changed +5 -13
builtin/ls-tree.c
+5 -13
@@ -53,6 +53,7 @@ struct ls_tree_options {
53 };
54
55 struct show_tree_data {
56 + struct ls_tree_options *options;
57 unsigned mode;
58 enum object_type type;
59 const struct object_id *oid;
@@ -60,17 +61,11 @@ struct show_tree_data {
61 struct strbuf *base;
62 };
63
63 -struct show_tree_data_cb {
64 - struct ls_tree_options *options;
65 - struct show_tree_data *data;
66 -};
67 -
64 static size_t expand_show_tree(struct strbuf *sb, const char *start,
65 void *context)
66 {
71 - struct show_tree_data_cb *wrapper = context;
72 - struct ls_tree_options *options = wrapper->options;
73 - struct show_tree_data *data = wrapper->data;
67 + struct show_tree_data *data = context;
68 + struct ls_tree_options *options = data->options;
69 const char *end;
70 const char *p;
71 unsigned int errlen;
@@ -153,17 +148,14 @@ static int show_tree_fmt(const struct object_id *oid, struct strbuf *base,
148 int recurse = 0;
149 struct strbuf sb = STRBUF_INIT;
150 enum object_type type = object_type(mode);
156 - struct show_tree_data data = {
151 + struct show_tree_data cb_data = {
152 + .options = options,
153 .mode = mode,
154 .type = type,
155 .oid = oid,
156 .pathname = pathname,
157 .base = base,
158 };
163 - struct show_tree_data_cb cb_data = {
164 - .data = &data,
165 - .options = options,
166 - };
159
160 if (type == OBJ_TREE && show_recursive(options, base->buf, base->len, pathname))
161 recurse = READ_TREE_RECURSIVE;