protocol-caps: add type support to object-info
Teach the server-side object-info handler to accept type as a requested field. When the client includes type in its object-info request, the server returns the requested object type. While touching send_info(), wrap an over-long line and fix the bit field style of requested_info.size. 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
1de7fe1111ea01b4717ecff591215ec59908050f
2 files changed
+48
-3
protocol-caps.c
+18
-3
@@ -11,7 +11,8 @@
11
#include "strbuf.h"
12
13
struct requested_info {
14
- unsigned size : 1;
14
+ unsigned size:1;
15
+ unsigned type:1;
16
};
17
18
/*
@@ -73,15 +74,20 @@ static void send_info(struct repository *r, struct packet_writer *writer,
74
if (info->size)
75
packet_writer_write(writer, "size");
76
77
+ if (info->type)
78
+ packet_writer_write(writer, "type");
79
+
80
for_each_string_list_item (item, oid_str_list) {
81
const char *oid_str = item->string;
82
+ enum object_type object_type;
83
struct object_id oid;
84
size_t object_size;
85
86
if (get_oid_hex_algop(oid_str, &oid, r->hash_algo) < 0) {
87
packet_writer_error(
88
writer,
84
- "object-info: protocol error, expected to get oid, not '%s'",
89
+ "object-info: protocol error, expected to get "
90
+ "oid, not '%s'",
91
oid_str);
92
continue;
93
}
@@ -93,7 +99,8 @@ static void send_info(struct repository *r, struct packet_writer *writer,
99
* If an object is not recognized by the server append SP to
100
* the response.
101
*/
96
- if (get_object_info(r->objects, &oid, &object_size) <= OBJ_NONE) {
102
+ object_type = get_object_info(r->objects, &oid, &object_size);
103
+ if (object_type <= OBJ_NONE) {
104
strbuf_addstr(&send_buffer, " ");
105
goto write;
106
}
@@ -103,6 +110,9 @@ static void send_info(struct repository *r, struct packet_writer *writer,
110
(uintmax_t)object_size);
111
}
112
113
+ if (info->type)
114
+ strbuf_addf(&send_buffer, " %s", type_name(object_type));
115
+
116
write:
117
packet_writer_write(writer, "%s", send_buffer.buf);
118
strbuf_reset(&send_buffer);
@@ -124,6 +134,11 @@ int cap_object_info(struct repository *r, struct packet_reader *request)
134
continue;
135
}
136
137
+ if (!strcmp("type", request->line)) {
138
+ info.type = 1;
139
+ continue;
140
+ }
141
+
142
if (parse_oid(request->line, &oid_str_list))
143
continue;
144
t/t5701-git-serve.sh
+30
@@ -369,6 +369,36 @@ test_expect_success 'basics of object-info' '
369
test_cmp expect actual
370
'
371
372
+test_expect_success 'object-info supports type' '
373
+ test_config transfer.advertiseObjectInfo true &&
374
+
375
+ two_oid=$(git rev-parse two:two.t) &&
376
+ two_size=$(test_file_size two.t) &&
377
+
378
+ test-tool pkt-line pack >in <<-EOF &&
379
+ command=object-info
380
+ object-format=$(test_oid algo)
381
+ 0001
382
+ size
383
+ type
384
+ oid $two_oid
385
+ oid $two_oid
386
+ 0000
387
+ EOF
388
+
389
+ cat >expect <<-EOF &&
390
+ size
391
+ type
392
+ $two_oid $two_size blob
393
+ $two_oid $two_size blob
394
+ 0000
395
+ EOF
396
+
397
+ test-tool serve-v2 --stateless-rpc <in >out &&
398
+ test-tool pkt-line unpack <out >actual &&
399
+ test_cmp expect actual
400
+'
401
+
402
test_expect_success 'bare OID request' '
403
test_config transfer.advertiseObjectInfo true &&
404