fetch-object-info: parse type from server response
The server can handle type requests but does not advertise the capability yet. Prepare the client to know how to parse the server response once the server advertises the capability. 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
0f61542dbc563b2eb6dfdca04f598a6c62fdab55
3 files changed
+30
-1
builtin/cat-file.c
+5
@@ -854,6 +854,8 @@ static void parse_cmd_remote_object_info(struct batch_options *opt,
854
string_list_append(&data->remote_allowed_atoms, "objectname");
855
if (results.sizes)
856
string_list_append(&data->remote_allowed_atoms, "objectsize");
857
+ if (results.types)
858
+ string_list_append(&data->remote_allowed_atoms, "objecttype");
859
860
data->skip_object_info = 1;
861
for (size_t i = 0; i < results.nr; i++) {
@@ -872,6 +874,9 @@ static void parse_cmd_remote_object_info(struct batch_options *opt,
874
if (results.sizes)
875
data->size = results.sizes[i];
876
877
+ if (results.types)
878
+ data->type = results.types[i];
879
+
880
opt->batch_mode = BATCH_MODE_INFO;
881
data->is_remote = 1;
882
batch_object_write(argv[i + 1], output, opt, data, NULL, 0);
fetch-object-info.c
+23
-1
@@ -1,6 +1,7 @@
1
#include "git-compat-util.h"
2
#include "gettext.h"
3
#include "hex.h"
4
+#include "object.h"
5
#include "pkt-line.h"
6
#include "connect.h"
7
#include "oid-array.h"
@@ -62,6 +63,7 @@ int fetch_object_info(const enum protocol_version version,
63
unsigned ask_size = 0;
64
unsigned ask_type = 0;
65
int size_index = -1;
66
+ int type_index = -1;
67
size_t wanted;
68
size_t i;
69
@@ -110,8 +112,15 @@ int fetch_object_info(const enum protocol_version version,
112
die(_("object-info: duplicate 'size' attribute"));
113
size_index = (int)i;
114
CALLOC_ARRAY(results->sizes, results->nr);
115
+ } else if (!strcmp(reader->line, "type")) {
116
+ if (!ask_type)
117
+ die(_("object-info: unrequested 'type' attribute"));
118
+ if (results->types)
119
+ die(_("object-info: duplicate 'type' attribute"));
120
+ type_index = (int)i;
121
+ CALLOC_ARRAY(results->types, results->nr);
122
} else {
114
- BUG("only size is supported");
123
+ BUG("unexpected object-info option: %s", reader->line);
124
}
125
}
126
@@ -157,6 +166,18 @@ int fetch_object_info(const enum protocol_version version,
166
object_info_values.items[0].string,
167
object_info_values.items[size_index + 1].string);
168
169
+ if (results->types) {
170
+ const char *type_str =
171
+ object_info_values.items[type_index + 1].string;
172
+ int type = type_from_string_gently(type_str, -1, 1);
173
+
174
+ if (type < 0)
175
+ die(_("object-info: object %s has invalid type '%s'"),
176
+ object_info_values.items[0].string, type_str);
177
+
178
+ results->types[i] = type;
179
+ }
180
+
181
string_list_clear(&object_info_values, 0);
182
}
183
@@ -172,6 +193,7 @@ int fetch_object_info(const enum protocol_version version,
193
void free_fetch_object_info_results(struct fetch_object_info_results *results)
194
{
195
free(results->sizes);
196
+ free(results->types);
197
free(results->unrecognized);
198
memset(results, 0, sizeof(*results));
199
}
fetch-object-info.h
+2
@@ -1,11 +1,13 @@
1
#ifndef FETCH_OBJECT_INFO_H
2
#define FETCH_OBJECT_INFO_H
3
4
+#include "object.h"
5
#include "pkt-line.h"
6
#include "protocol.h"
7
8
struct fetch_object_info_results {
9
size_t *sizes;
10
+ enum object_type *types;
11
uint8_t *unrecognized;
12
size_t nr;
13
unsigned wants_size:1;