Skip to content

Commit e1fb641

Browse files
committed
Merge branch 'ps/cat-file-remote-object-info'
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 adapt to the server cat-file: add remote-object-info to batch-command transport: add client support for object-info serve: advertise object-info feature protocol-caps: check object existence regardless of the attributes requested 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: use unsigned int for hash_algo variable fetch-pack: drop the static advertise_sid variable t1006: extract helper 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 ab7ed92 + dd1968b commit e1fb641

23 files changed

Lines changed: 1444 additions & 91 deletions

‎Documentation/git-cat-file.adoc‎

Lines changed: 21 additions & 2 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+
object 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
@@ -340,8 +348,15 @@ newline. The available atoms are:
340348
after that first run of whitespace (i.e., the "rest" of the
341349
line) are output in place of the `%(rest)` atom.
342350

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

346361
If `--batch` is specified, or if `--batch-command` is used with the `contents`
347362
command, the object information is followed by the object contents (consisting
@@ -438,6 +453,10 @@ scripting purposes.
438453
CAVEATS
439454
-------
440455
456+
Note that only `%(objectname)` and `%(objectsize)` are currently
457+
supported by the `remote-object-info` command. Using any other placeholder in
458+
the format string will return an empty string in its position.
459+
441460
Note that the sizes of objects on disk are reported accurately, but care
442461
should be taken in drawing conclusions about which refs or objects are
443462
responsible for disk usage. The size of a packed non-delta object may be

‎Documentation/gitprotocol-v2.adoc‎

Lines changed: 13 additions & 8 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 OIDs.
572572
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.
573+
The response of `object-info` consists of one pkt-line per requested attribute,
574+
echoing the attributes the server will report, followed by one pkt-line per
575+
requested object id with its information, each field separated by a single
576+
space.
575577
576578
output = info flush-pkt
577579
578-
info = PKT-LINE(attrs) LF)
579-
*PKT-LINE(obj-info LF)
580-
581-
attrs = attr | attrs SP attrs
580+
info = *PKT-LINE(attr LF)
581+
*PKT-LINE(obj-info LF)
582582
583583
attr = "size"
584584
585-
obj-info = obj-id SP obj-size
585+
obj-size = 1*DIGIT
586+
587+
obj-info = obj-id [SP [obj-size]]
588+
589+
If the server does not recognize the OID, the response will be `<oid> SP`
590+
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
@@ -1169,6 +1169,7 @@ LIB_OBJS += ewah/ewah_io.o
11691169
LIB_OBJS += ewah/ewah_rlw.o
11701170
LIB_OBJS += exec-cmd.o
11711171
LIB_OBJS += fetch-negotiator.o
1172+
LIB_OBJS += fetch-object-info.o
11721173
LIB_OBJS += fetch-pack.o
11731174
LIB_OBJS += fmt-merge-msg.o
11741175
LIB_OBJS += fsck.o

0 commit comments

Comments
 (0)