fetch-object-info: pass arguments directly instead of a struct

struct object_info_args groups three pointers that already live in the transport and are given to fetch_object_info(). Grouping them into a struct reduces the number of parameters, but it suggests that fetch_object_info() uses all three of them. Drop the struct and pass those parameters directly to fetch_object_info() and send_object_info_request(). This should have no change in behavior. Helped-by: Jeff King <peff@peff.net> Helped-by: Junio C Hamano <gitster@pobox.com> Mentored-by: Karthik Nayak <karthik.188@gmail.com> Mentored-by: Chandra Pratap <chandrapratap3519@gmail.com> Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pablo Sabater committed Aug 3, 2026 at 16:39 UTC 36c1152892648a20f12d3757fb107b737eb44343
3 files changed +44 -37
fetch-object-info.c
+31 -22
@@ -9,20 +9,24 @@
9 #include "string-list.h"
10
11 /* Sends object-info command and its arguments into the request buffer. */
12 -static void send_object_info_request(const int fd_out, struct object_info_args *args)
12 +static void send_object_info_request(const int fd_out,
13 + const struct string_list *server_options,
14 + struct oid_array *oids,
15 + struct string_list *object_info_options)
16 {
17 struct strbuf req_buf = STRBUF_INIT;
18
16 - write_command_and_capabilities(&req_buf, "object-info", args->server_options);
19 + write_command_and_capabilities(&req_buf, "object-info", server_options);
20
18 - if (unsorted_string_list_has_string(args->object_info_options, "size"))
21 + if (unsorted_string_list_has_string(object_info_options, "size"))
22 packet_buf_write(&req_buf, "size");
20 - else if (args->object_info_options->nr)
23 + else if (object_info_options->nr)
24 BUG("only size should be in object_info_options");
25
23 - if (args->oids)
24 - for (size_t i = 0; i < args->oids->nr; i++)
25 - packet_buf_write(&req_buf, "oid %s", oid_to_hex(&args->oids->oid[i]));
26 + if (oids)
27 + for (size_t i = 0; i < oids->nr; i++)
28 + packet_buf_write(&req_buf, "oid %s",
29 + oid_to_hex(&oids->oid[i]));
30
31 packet_buf_flush(&req_buf);
32 if (write_in_full(fd_out, req_buf.buf, req_buf.len) < 0)
@@ -45,8 +49,12 @@ static int parse_object_size(const char *s, size_t *res)
49 return 0;
50 }
51
48 -int fetch_object_info(const enum protocol_version version, struct object_info_args *args,
49 - struct packet_reader *reader, struct object_info *object_info_data,
52 +int fetch_object_info(const enum protocol_version version,
53 + const struct string_list *server_options,
54 + struct oid_array *oids,
55 + struct string_list *object_info_options,
56 + struct packet_reader *reader,
57 + struct object_info *object_info_data,
58 const int stateless_rpc, const int fd_out)
59 {
60 size_t i;
@@ -65,16 +73,17 @@ int fetch_object_info(const enum protocol_version version, struct object_info_ar
73 * because the number of options is a small known number (the
74 * supported placeholders which currently are size and type).
75 */
68 - for (int i = (int)args->object_info_options->nr - 1; i >= 0; i--)
76 + for (int i = (int)object_info_options->nr - 1; i >= 0; i--)
77 if (!server_supports_feature("object-info",
70 - args->object_info_options->items[i].string, 0))
71 - unsorted_string_list_delete_item(args->object_info_options, i, 0);
78 + object_info_options->items[i].string, 0))
79 + unsorted_string_list_delete_item(object_info_options, i, 0);
80
81 /*
82 * Even if no options are left, we still send the oid so we get
83 * at least an existence check.
84 */
77 - send_object_info_request(fd_out, args);
85 + send_object_info_request(fd_out, server_options, oids,
86 + object_info_options);
87 break;
88 case protocol_v1:
89 case protocol_v0:
@@ -83,14 +92,14 @@ int fetch_object_info(const enum protocol_version version, struct object_info_ar
92 BUG("unknown protocol version");
93 }
94
86 - for (i = 0; i < args->object_info_options->nr; i++) {
95 + for (i = 0; i < object_info_options->nr; i++) {
96 if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
97 check_stateless_delimiter(stateless_rpc, reader,
98 "stateless delimiter expected");
99 return -1;
100 }
101
93 - if (!unsorted_string_list_has_string(args->object_info_options, reader->line))
102 + if (!unsorted_string_list_has_string(object_info_options, reader->line))
103 return -1;
104
105 if (!strcmp(reader->line, "size")) {
@@ -99,7 +108,7 @@ int fetch_object_info(const enum protocol_version version, struct object_info_ar
108 * is only size. No risk of overflow.
109 */
110 size_index = (int)i;
102 - for (size_t j = 0; j < args->oids->nr; j++)
111 + for (size_t j = 0; j < oids->nr; j++)
112 object_info_data[j].sizep =
113 xcalloc(1, sizeof(*object_info_data[j].sizep));
114 } else {
@@ -109,16 +118,16 @@ int fetch_object_info(const enum protocol_version version, struct object_info_ar
118
119 for (i = 0;
120 packet_reader_read(reader) == PACKET_READ_NORMAL &&
112 - i < args->oids->nr;
121 + i < oids->nr;
122 i++) {
123 struct string_list object_info_values = STRING_LIST_INIT_DUP;
124
125 string_list_split(&object_info_values, reader->line, " ", -1);
126
127 if (strcmp(object_info_values.items[0].string,
119 - oid_to_hex(&args->oids->oid[i])))
128 + oid_to_hex(&oids->oid[i])))
129 die(_("object-info: expected OID: %s, got %s"),
121 - oid_to_hex(&args->oids->oid[i]),
130 + oid_to_hex(&oids->oid[i]),
131 object_info_values.items[0].string);
132
133 /*
@@ -138,7 +147,7 @@ int fetch_object_info(const enum protocol_version version, struct object_info_ar
147 * the server we expect the server to answer with the same
148 * number of attributes requested.
149 */
141 - if (args->object_info_options->nr + 1 != object_info_values.nr)
150 + if (object_info_options->nr + 1 != object_info_values.nr)
151 die("object-info: unexpected number of attributes: %s",
152 reader->line);
153
@@ -152,9 +161,9 @@ int fetch_object_info(const enum protocol_version version, struct object_info_ar
161 string_list_clear(&object_info_values, 0);
162 }
163
155 - if (i != args->oids->nr)
164 + if (i != oids->nr)
165 die(_("object-info: expected %" PRIuMAX " objects, got %" PRIuMAX),
157 - (uintmax_t)args->oids->nr, (uintmax_t)i);
166 + (uintmax_t)oids->nr, (uintmax_t)i);
167
168 check_stateless_delimiter(stateless_rpc, reader, "stateless delimiter expected");
169
fetch-object-info.h
+8 -9
@@ -4,22 +4,21 @@
4 #include "pkt-line.h"
5 #include "protocol.h"
6
7 -struct object_info_args {
8 - struct string_list *object_info_options;
9 - const struct string_list *server_options;
10 - struct oid_array *oids;
11 -};
12 -
7 struct object_info;
8 +struct oid_array;
9 /*
10 * Sends git-cat-file object-info command into the request buf and read the
11 * results from packets.
12 *
18 - * Modifies args->object_info_options, on return it contains only the supported
13 + * Modifies object_info_options, on return it contains only the supported
14 * options by the server.
15 */
21 -int fetch_object_info(enum protocol_version version, struct object_info_args *args,
22 - struct packet_reader *reader, struct object_info *object_info_data,
16 +int fetch_object_info(enum protocol_version version,
17 + const struct string_list *server_options,
18 + struct oid_array *oids,
19 + struct string_list *object_info_options,
20 + struct packet_reader *reader,
21 + struct object_info *object_info_data,
22 int stateless_rpc, int fd_out);
23
24 #endif /* FETCH_OBJECT_INFO_H */
transport.c
+5 -6
@@ -438,11 +438,6 @@ static int fetch_object_info_via_pack(struct transport *transport)
438 int ret = 0;
439 struct git_transport_data *data = transport->data;
440 struct packet_reader reader;
441 - struct object_info_args args = { 0 };
442 -
443 - args.server_options = transport->server_options;
444 - args.oids = transport->smart_options->object_info_oids;
445 - args.object_info_options = transport->smart_options->object_info_options;
441
442 connect_setup(transport, 0);
443 packet_reader_init(&reader, data->fd[0], NULL, 0,
@@ -453,7 +448,11 @@ static int fetch_object_info_via_pack(struct transport *transport)
448 data->version = discover_version(&reader);
449 transport->hash_algo = reader.hash_algo;
450
456 - ret = fetch_object_info(data->version, &args, &reader,
451 + ret = fetch_object_info(data->version,
452 + transport->server_options,
453 + transport->smart_options->object_info_oids,
454 + transport->smart_options->object_info_options,
455 + &reader,
456 data->options.object_info_data,
457 transport->stateless_rpc, data->fd[1]);
458