Skip to content

Commit e599224

Browse files
committed
Merge branch 'ps/cat-file-remote-object-info' into jch
The 'remote-object-info' command has been added to 'git cat-file --batch-command', allowing clients to request object metadata (currently size) from a remote server via protocol v2 without downloading the entire object. Format placeholders are dynamically filtered on the client based on server-advertised capabilities, returning empty strings for inapplicable or unsupported fields. * ps/cat-file-remote-object-info: cat-file: make remote-object-info allow-list dynamic cat-file: validate remote atoms with an allow-list cat-file: add remote-object-info to batch-command transport: add client support for object-info serve: advertise object-info feature fetch-pack: move fetch initialization connect: make write_fetch_command_and_capabilities() more generic fetch-pack: move write_fetch_command_and_capabilities() to connect.c fetch-pack: drop static advertise_sid variable fetch-pack: fix hash_algo variable type t1006: split test utility functions into new 'lib-cat-file.sh' cat-file: declare loop counter inside for() transport-helper: fix memory leak of helper on disconnect
2 parents bc6a6b8 + cc5851c commit e599224

22 files changed

Lines changed: 1255 additions & 86 deletions

Documentation/git-cat-file.adoc

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ info <object>::
169169
Print object info for object reference `<object>`. This corresponds to the
170170
output of `--batch-check`.
171171

172+
remote-object-info <remote> <object>...::
173+
Print object info for object references `<object>` at specified
174+
`<remote>` without downloading objects from the remote.
175+
Raise an error when the `object-info` capability is not supported by the remote.
176+
Raise an error when no object references are provided.
177+
This command may be combined with `--buffer`.
178+
172179
flush::
173180
Used with `--buffer` to execute all preceding commands that were issued
174181
since the beginning or since the last flush was issued. When `--buffer`
@@ -301,7 +308,8 @@ one per line, and print information based on the command given. With
301308
`--batch-command`, the `info` command followed by an object will print
302309
information about the object the same way `--batch-check` would, and the
303310
`contents` command followed by an object prints contents in the same way
304-
`--batch` would.
311+
`--batch` would. The `remote-object-info` command followed by a remote and
312+
objects IDs prints object info from the remote without downloading the objects.
305313

306314
You can specify the information shown for each object by using a custom
307315
`<format>`. The `<format>` is copied literally to stdout for each
@@ -324,24 +332,27 @@ newline. The available atoms are:
324332
reports).
325333

326334
`objectsize:disk`::
327-
The size, in bytes, that the object takes up on disk. See the
328-
note about on-disk sizes in the `CAVEATS` section below.
335+
The size, in bytes, that the object takes up on disk.
329336

330337
`deltabase`::
331338
If the object is stored as a delta on-disk, this expands to the
332339
full hex representation of the delta base object name.
333-
Otherwise, expands to the null OID (all zeroes). See `CAVEATS`
334-
below.
335-
340+
Otherwise, expands to the null OID (all zeroes).
336341
`rest`::
337342
If this atom is used in the output string, input lines are split
338343
at the first whitespace boundary. All characters before that
339344
whitespace are considered to be the object name; characters
340345
after that first run of whitespace (i.e., the "rest" of the
341346
line) are output in place of the `%(rest)` atom.
342347

348+
The command `remote-object-info` only supports the `%(objectname)` and
349+
`%(objectsize)` placeholders. See `CAVEATS` below for more information.
350+
343351
If no format is specified, the default format is `%(objectname)
344-
%(objecttype) %(objectsize)`.
352+
%(objecttype) %(objectsize)`, except for `remote-object-info` commands which
353+
use `%(objectname) %(objectsize)` because "%(objecttype)" is not supported yet.
354+
WARNING: When "%(objecttype)" is supported, the default format WILL be unified,
355+
so DO NOT RELY on the current default format to stay the same!!!
345356

346357
If `--batch` is specified, or if `--batch-command` is used with the `contents`
347358
command, the object information is followed by the object contents (consisting
@@ -438,6 +449,10 @@ scripting purposes.
438449
CAVEATS
439450
-------
440451
452+
Note that since only `%(objectname)` and `%(objectsize)` are currently
453+
supported by the `remote-object-info` command. Using any other placeholder in
454+
the format string will return an empty string in its position.
455+
441456
Note that the sizes of objects on disk are reported accurately, but care
442457
should be taken in drawing conclusions about which refs or objects are
443458
responsible for disk usage. The size of a packed non-delta object may be

Documentation/gitprotocol-v2.adoc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,21 +568,26 @@ An `object-info` request takes the following arguments:
568568
569569
oid <oid>
570570
Indicates to the server an object which the client wants to obtain
571-
information for.
571+
information for. They must be full object IDs.
572572
573573
The response of `object-info` is a list of the requested object ids
574574
and associated requested information, each separated by a single space.
575575
576576
output = info flush-pkt
577577
578-
info = PKT-LINE(attrs) LF)
578+
info = PKT-LINE(attrs LF)
579579
*PKT-LINE(obj-info LF)
580580
581581
attrs = attr | attrs SP attrs
582582
583+
obj-size = 1*DIGIT
584+
583585
attr = "size"
584586
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.
586591
587592
bundle-uri
588593
~~~~~~~~~~

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,7 @@ LIB_OBJS += ewah/ewah_rlw.o
11701170
LIB_OBJS += exec-cmd.o
11711171
LIB_OBJS += fetch-negotiator.o
11721172
LIB_OBJS += fetch-pack.o
1173+
LIB_OBJS += fetch-object-info.o
11731174
LIB_OBJS += fmt-merge-msg.o
11741175
LIB_OBJS += fsck.o
11751176
LIB_OBJS += fsmonitor.o

0 commit comments

Comments
 (0)