serve: advertise type capability

The server and the client can handle type requests but the client won't ask for it until the server advertises it. Add type to the advertised capabilities so the client knows that it can request it. 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 1a1698d8c68ca2ca8de75b43b8c478a11077bf68
2 files changed +24 -6
serve.c
+2 -2
@@ -97,9 +97,9 @@ static int object_info_advertise(struct repository *r, struct strbuf *value)
97 /* disabled by default */
98 advertise_object_info = 0;
99 }
100 - /* Currently only size is supported */
100 + /* Currently only size and type are supported */
101 if (value && advertise_object_info)
102 - strbuf_addstr(value, "size");
102 + strbuf_addstr(value, "size type");
103 return advertise_object_info;
104 }
105
t/t1017-cat-file-remote-object-info.sh
+22 -4
@@ -7,6 +7,7 @@ test_description='git cat-file --batch-command with remote-object-info command'
7
8 hello_content="Hello World"
9 hello_size=$(strlen "$hello_content")
10 +hello_type="blob"
11 hello_oid=$(echo_without_newline "$hello_content" | git hash-object --stdin)
12 hello_short_oid=$(git rev-parse --short "$hello_oid")
13
@@ -19,6 +20,7 @@ unstored_oid=$(echo_without_newline "$unstored_content" | git hash-object --stdi
20 # file name is hello, which is 5 characters
21 # a space is 1 character and a null is 1 character
22 tree_size=$(($(test_oid rawsz) + 13))
23 +tree_type="tree"
24
25 commit_message="Initial commit"
26
@@ -31,6 +33,7 @@ commit_message="Initial commit"
33 # An easier way to calculate is: 1. use `git cat-file commit <commit hash> | wc -c`,
34 # to get 177, 2. then deduct 40 hex characters to get 137
35 commit_size=$(($(test_oid hexsz) + 137))
36 +commit_type="commit"
37
38 tag_header_without_oid="type blob
39 tag hellotag
@@ -44,6 +47,7 @@ $tag_description"
47
48 tag_oid=$(echo_without_newline "$tag_content" | git hash-object -t tag --stdin -w)
49 tag_size=$(strlen "$tag_content")
50 +tag_type="tag"
51
52 set_transport_variables () {
53 hello_oid=$(echo_without_newline "$hello_content" | git hash-object --stdin)
@@ -256,14 +260,12 @@ test_expect_success 'remote-object-info does not die on missing oid like info' '
260 )
261 '
262
259 -# This tests depends on %(objecttype) not being supported yet, once supported
260 -# it needs to be updated.
261 -test_expect_success 'unsupported placeholder on remote returns empty string' '
263 +test_expect_success 'objecttype is supported by remote-object-info' '
264 (
265 set_transport_variables "$daemon_parent" &&
266 cd "$daemon_parent/daemon_client_empty" &&
267
266 - echo "" >expect &&
268 + echo "$hello_type" >expect &&
269 git cat-file --batch-command="%(objecttype)" >actual <<-EOF &&
270 remote-object-info "$GIT_DAEMON_URL/parent" $hello_oid
271 EOF
@@ -271,6 +273,22 @@ test_expect_success 'unsupported placeholder on remote returns empty string' '
273 )
274 '
275
276 +test_expect_success 'unsupported placeholders on remote return empty string' '
277 + (
278 + set_transport_variables "$daemon_parent" &&
279 + cd "$daemon_parent/daemon_client_empty" &&
280 +
281 + fmt="%(objectmode) %(objectsize:disk) %(rest) %(deltabase)" &&
282 +
283 + # The hardcoded SPs between the atoms are respected.
284 + echo " " >expect &&
285 + git cat-file --batch-command="$fmt" >actual <<-EOF &&
286 + remote-object-info "$GIT_DAEMON_URL/parent" $hello_oid
287 + EOF
288 + test_cmp expect actual
289 + )
290 +'
291 +
292 test_expect_success 'requesting only objectname echoes back' '
293 (
294 set_transport_variables "$daemon_parent" &&