serve: advertise object-info feature

In order for a client to know what object-info components a server can provide, advertise supported object-info features. This allows a client to decide whether to query the server for object-info or fetch as a fallback. While at it, update the object-info section in 'gitprotocol-v2.adoc': - Require full obj-oid explicitly. - Fix parentheses. - Define obj-size explicitly. - Make obj-size optional in obj-info and document the behavior for unrecognized object IDs. Helped-by: Jonathan Tan <jonathantanmy@google.com> Helped-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Calvin Wan <calvinwan@google.com> Signed-off-by: Eric Ju <eric.peijian@gmail.com> Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Calvin Wan committed Jul 10, 2026 at 18:41 UTC 45dbeb907bfec6e50f54f99afc4d522b85d3ef38
2 files changed +12 -4
Documentation/gitprotocol-v2.adoc
+8 -3
@@ -568,21 +568,26 @@ An `object-info` request takes the following arguments:
568
569 oid <oid>
570 Indicates to the server an object which the client wants to obtain
571 - information for.
571 + information for. They must be full object IDs.
572
573 The response of `object-info` is a list of the requested object ids
574 and associated requested information, each separated by a single space.
575
576 output = info flush-pkt
577
578 - info = PKT-LINE(attrs) LF)
578 + info = PKT-LINE(attrs LF)
579 *PKT-LINE(obj-info LF)
580
581 attrs = attr | attrs SP attrs
582
583 + obj-size = 1*DIGIT
584 +
585 attr = "size"
586
585 - obj-info = obj-id SP obj-size
587 + obj-info = obj-id SP [obj-size]
588 +
589 + If the server does not recognize the object id, the response will be
590 + `obj-id SP` regardless of the number of attributes requested.
591
592 bundle-uri
593 ~~~~~~~~~~
serve.c
+4 -1
@@ -89,7 +89,7 @@ static void session_id_receive(struct repository *r UNUSED,
89 trace2_data_string("transfer", NULL, "client-sid", client_sid);
90 }
91
92 -static int object_info_advertise(struct repository *r, struct strbuf *value UNUSED)
92 +static int object_info_advertise(struct repository *r, struct strbuf *value)
93 {
94 if (advertise_object_info == -1 &&
95 repo_config_get_bool(r, "transfer.advertiseobjectinfo",
@@ -97,6 +97,9 @@ static int object_info_advertise(struct repository *r, struct strbuf *value UNUS
97 /* disabled by default */
98 advertise_object_info = 0;
99 }
100 + /* Currently only size is supported */
101 + if (value && advertise_object_info)
102 + strbuf_addstr(value, "size");
103 return advertise_object_info;
104 }
105