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>
next
Calvin Wan 2026-07-10 18:41:15 +02:00 committed by Junio C Hamano
parent f14d04f51e
commit 45dbeb907b
2 changed files with 12 additions and 4 deletions

View File

@ -568,21 +568,26 @@ An `object-info` request takes the following arguments:

oid <oid>
Indicates to the server an object which the client wants to obtain
information for.
information for. They must be full object IDs.

The response of `object-info` is a list of the requested object ids
and associated requested information, each separated by a single space.

output = info flush-pkt

info = PKT-LINE(attrs) LF)
info = PKT-LINE(attrs LF)
*PKT-LINE(obj-info LF)

attrs = attr | attrs SP attrs

obj-size = 1*DIGIT

attr = "size"

obj-info = obj-id SP obj-size
obj-info = obj-id SP [obj-size]

If the server does not recognize the object id, the response will be
`obj-id SP` regardless of the number of attributes requested.

bundle-uri
~~~~~~~~~~

View File

@ -89,7 +89,7 @@ static void session_id_receive(struct repository *r UNUSED,
trace2_data_string("transfer", NULL, "client-sid", client_sid);
}

static int object_info_advertise(struct repository *r, struct strbuf *value UNUSED)
static int object_info_advertise(struct repository *r, struct strbuf *value)
{
if (advertise_object_info == -1 &&
repo_config_get_bool(r, "transfer.advertiseobjectinfo",
@ -97,6 +97,9 @@ static int object_info_advertise(struct repository *r, struct strbuf *value UNUS
/* disabled by default */
advertise_object_info = 0;
}
/* Currently only size is supported */
if (value && advertise_object_info)
strbuf_addstr(value, "size");
return advertise_object_info;
}