]> git.99rst.org Git - git.git/commit
cat-file: add remote-object-info to batch-command
authorEric Ju <redacted>
Fri, 24 Jul 2026 10:54:23 +0000 (12:54 +0200)
committerJunio C Hamano <redacted>
Fri, 24 Jul 2026 15:49:09 +0000 (08:49 -0700)
commit0ae93f56ecd792d227149161b57f292a1c909d0c
treebf0f1ce0a6ac3554a0ac8af811d180c609c1b4eb
parent12a19eec1d7c0121e0c82c95a2300fdbad1f18f2
cat-file: add remote-object-info to batch-command

Since the info command in cat-file --batch-command prints object
info for a given object, it is natural to add another command in
cat-file --batch-command to print object info for a given object
from a remote.

Add remote-object-info command to cat-file --batch-command.

While info takes object ids one at a time, this creates overhead when
making requests to a server. So remote-object-info instead can take
multiple object ids at once.

The cat-file --batch-command command is generally implemented in the
following manner:

 - Receive and parse input from user
 - Call respective function attached to command
 - Get object info, print object info

In --buffer mode, this changes to:

 - Receive and parse input from user
 - Store respective function attached to command in a queue
 - After flush, loop through commands in queue
    - Call respective function attached to command
    - Get object info, print object info

Notice how the getting and printing of object info is accomplished one
at a time. As described above, this creates a problem for making
requests to a server. Therefore, remote-object-info is implemented in
the following manner:

 - Receive and parse input from user
 If command is remote-object-info:
    - Get object info from remote
    - Loop through and print each object info
 Else:
    - Call respective function attached to command
    - Parse input, get object info, print object info

And finally for --buffer mode remote-object-info:
 - Receive and parse input from user
 - Store respective function attached to command in a queue
 - After flush, loop through commands in queue:
    If command is remote-object-info:
        - Get object info from remote
        - Loop through and print each object info
    Else:
        - Call respective function attached to command
        - Get object info, print object info

To summarize, remote-object-info gets object info from the remote and
then loops through the object info passed in, printing the info.

In order for remote-object-info to avoid remote communication
overhead in the non-buffer mode, the objects are passed in as such:

remote-object-info <remote> <oid> <oid> ... <oid>

rather than

remote-object-info <remote> <oid>
remote-object-info <remote> <oid>
...
remote-object-info <remote> <oid>

Placeholders in the format are validated against an allow-list of the
atoms the remote path supports: "objectname" and "objectsize".
Unsupported atoms expand to an empty string, honoring how for-each-ref
handles known but inapplicable atoms.
Without this, atoms like %(objecttype) would mark data->info.typep and
because the server only sends size, type_name() would later crash.
As extra safety, even outside of the remote path, initialize
expand_data's type to OBJ_BAD and handle type_name() returning NULL.

Helped-by: Jonathan Tan <redacted>
Helped-by: Christian Couder <redacted>
Mentored-by: Karthik Nayak <redacted>
Mentored-by: Chandra Pratap <redacted>
Signed-off-by: Calvin Wan <redacted>
Signed-off-by: Eric Ju <redacted>
[pablo: added the atom allow-list validation]
Signed-off-by: Pablo Sabater <redacted>
Signed-off-by: Junio C Hamano <redacted>
Documentation/git-cat-file.adoc
builtin/cat-file.c
object-file.c
odb.h
t/meson.build
t/t1017-cat-file-remote-object-info.sh [new file with mode: 0755]
git clone https://git.99rst.org/PROJECT