cat-file: unify default format
%(objecttype) is supported both by the client and by the server. Change the temporary default format to the unified version that the other commands use. Update documentation to remove %(objecttype) from the caveats of remote-object-info and show %(objecttype) support. Now that type is supported and the default format unified, update the tests to expect the new default format. Mentored-by: Karthik Nayak <karthik.188@gmail.com> Mentored-by: Chandra Pratap <chandrapratap3519@gmail.com> Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pablo Sabater committed
Aug 3, 2026 at 16:39 UTC
641e7e8c614961c886febfeabffdeecfc16e6e5a
4 files changed
+47
-47
Documentation/git-cat-file.adoc
+7
-10
@@ -348,15 +348,12 @@ newline. The available atoms are:
348
after that first run of whitespace (i.e., the "rest" of the
349
line) are output in place of the `%(rest)` atom.
350
351
-The command `remote-object-info` only supports the `%(objectname)` and
352
-`%(objectsize)` placeholders. See `CAVEATS` below for more information.
351
+The command `remote-object-info` only supports the `%(objectname)`,
352
+`%(objectsize)` and `%(objecttype)` placeholders. See `CAVEATS` below for more
353
+information.
354
355
If no format is specified, the default format is `%(objectname)
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!!!
356
+%(objecttype) %(objectsize)`.
357
358
If `--batch` is specified, or if `--batch-command` is used with the `contents`
359
command, the object information is followed by the object contents (consisting
@@ -453,9 +450,9 @@ scripting purposes.
450
CAVEATS
451
-------
452
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.
453
+Note that only `%(objectname)`, `%(objectsize)` and `%(objecttype)` are
454
+currently supported by the `remote-object-info` command. Using any other
455
+placeholder in the format string will return an empty string in its position.
456
457
Note that the sizes of objects on disk are reported accurately, but care
458
should be taken in drawing conclusions about which refs or objects are
Documentation/gitprotocol-v2.adoc
+14
-4
@@ -558,14 +558,17 @@ object-info
558
559
`object-info` is the command to retrieve information about one or more objects.
560
Its main purpose is to allow a client to make decisions based on this
561
-information without having to fully fetch objects. Object size is the only
562
-information that is currently supported.
561
+information without having to fully fetch objects. Currently only object size
562
+and type are supported.
563
564
An `object-info` request takes the following arguments:
565
566
size
567
Requests size information to be returned for each listed object id.
568
569
+ type
570
+ Requests type information to be returned for each listed object id.
571
+
572
oid <oid>
573
Indicates to the server an object which the client wants to obtain
574
information for. They must be full OIDs.
@@ -580,11 +583,18 @@ space.
583
info = *PKT-LINE(attr LF)
584
*PKT-LINE(obj-info LF)
585
583
- attr = "size"
586
+ attr = "size" | "type"
587
588
obj-size = 1*DIGIT
589
587
- obj-info = obj-id [SP [obj-size]]
590
+ obj-type = "blob" | "tree" | "commit" | "tag"
591
+
592
+ obj-val = obj-size | obj-type
593
+
594
+ obj-info = obj-id [SP [obj-val *(SP obj-val)]]
595
+
596
+The values in `obj-info` appear in the same order as the corresponding `attr`
597
+lines, with exactly one value per requested attribute.
598
599
If the server does not recognize the OID, the response will be `<oid> SP`
600
regardless of the number of attributes requested.
builtin/cat-file.c
-7
@@ -823,15 +823,9 @@ static void parse_cmd_remote_object_info(struct batch_options *opt,
823
char *line_to_split;
824
struct fetch_object_info_results results = FETCH_OBJECT_INFO_RESULTS_INIT;
825
struct oid_array object_info_oids = OID_ARRAY_INIT;
826
- const char *saved_format = opt->format;
826
827
if (strlen(line) >= MAX_REMOTE_OBJ_INFO_LINE)
828
die(_("remote-object-info command too long"));
830
- /*
831
- * TODO: Use the default format once %(objecttype) is supported.
832
- */
833
- if (!opt->format)
834
- opt->format = "%(objectname) %(objectsize)";
829
830
line_to_split = xstrdup(line);
831
count = split_cmdline(line_to_split, &argv);
@@ -883,7 +877,6 @@ static void parse_cmd_remote_object_info(struct batch_options *opt,
877
data->is_remote = 0;
878
}
879
data->skip_object_info = 0;
886
- opt->format = saved_format;
880
881
free_fetch_object_info_results(&results);
882
free(line_to_split);
t/t1017-cat-file-remote-object-info.sh
+26
-26
@@ -139,10 +139,10 @@ test_expect_success 'batch-command remote-object-info git:// default filter' '
139
set_transport_variables "$daemon_parent" &&
140
cd "$daemon_parent/daemon_client_empty" &&
141
142
- echo "$hello_oid $hello_size" >expect &&
143
- echo "$tree_oid $tree_size" >>expect &&
144
- echo "$commit_oid $commit_size" >>expect &&
145
- echo "$tag_oid $tag_size" >>expect &&
142
+ echo "$hello_oid $hello_type $hello_size" >expect &&
143
+ echo "$tree_oid $tree_type $tree_size" >>expect &&
144
+ echo "$commit_oid $commit_type $commit_size" >>expect &&
145
+ echo "$tag_oid $tag_type $tag_size" >>expect &&
146
147
git cat-file --batch-command >actual <<-EOF &&
148
remote-object-info "$GIT_DAEMON_URL/parent" $hello_oid $tree_oid
@@ -152,7 +152,7 @@ test_expect_success 'batch-command remote-object-info git:// default filter' '
152
)
153
'
154
155
-test_expect_success 'remote-object-info does not change the default format of info' '
155
+test_expect_success 'remote-object-info and info can be mixed using the unified default format' '
156
(
157
set_transport_variables "$daemon_parent" &&
158
cd "$daemon_parent/daemon_client_empty" &&
@@ -162,7 +162,7 @@ test_expect_success 'remote-object-info does not change the default format of in
162
local_size=$(strlen "$local_content") &&
163
164
echo "$local_oid blob $local_size" >expect &&
165
- echo "$hello_oid $hello_size" >>expect &&
165
+ echo "$hello_oid blob $hello_size" >>expect &&
166
echo "$local_oid blob $local_size" >>expect &&
167
168
git cat-file --batch-command >actual <<-EOF &&
@@ -209,10 +209,10 @@ test_expect_success 'batch-command -Z remote-object-info git:// default filter'
209
set_transport_variables "$daemon_parent" &&
210
cd "$daemon_parent/daemon_client_empty" &&
211
212
- printf "%s\0" "$hello_oid $hello_size" >expect &&
213
- printf "%s\0" "$tree_oid $tree_size" >>expect &&
214
- printf "%s\0" "$commit_oid $commit_size" >>expect &&
215
- printf "%s\0" "$tag_oid $tag_size" >>expect &&
212
+ printf "%s\0" "$hello_oid $hello_type $hello_size" >expect &&
213
+ printf "%s\0" "$tree_oid $tree_type $tree_size" >>expect &&
214
+ printf "%s\0" "$commit_oid $commit_type $commit_size" >>expect &&
215
+ printf "%s\0" "$tag_oid $tag_type $tag_size" >>expect &&
216
217
printf "%s\0" "$hello_oid missing" >>expect &&
218
printf "%s\0" "$tree_oid missing" >>expect &&
@@ -448,10 +448,10 @@ test_expect_success 'batch-command remote-object-info file:// default filter' '
448
server_path="$(pwd)/server" &&
449
cd file_client_empty &&
450
451
- echo "$hello_oid $hello_size" >expect &&
452
- echo "$tree_oid $tree_size" >>expect &&
453
- echo "$commit_oid $commit_size" >>expect &&
454
- echo "$tag_oid $tag_size" >>expect &&
451
+ echo "$hello_oid $hello_type $hello_size" >expect &&
452
+ echo "$tree_oid $tree_type $tree_size" >>expect &&
453
+ echo "$commit_oid $commit_type $commit_size" >>expect &&
454
+ echo "$tag_oid $tag_type $tag_size" >>expect &&
455
456
git cat-file --batch-command >actual <<-EOF &&
457
remote-object-info "file://${server_path}" $hello_oid $tree_oid
@@ -467,10 +467,10 @@ test_expect_success 'batch-command -Z remote-object-info file:// default filter'
467
server_path="$(pwd)/server" &&
468
cd file_client_empty &&
469
470
- printf "%s\0" "$hello_oid $hello_size" >expect &&
471
- printf "%s\0" "$tree_oid $tree_size" >>expect &&
472
- printf "%s\0" "$commit_oid $commit_size" >>expect &&
473
- printf "%s\0" "$tag_oid $tag_size" >>expect &&
470
+ printf "%s\0" "$hello_oid $hello_type $hello_size" >expect &&
471
+ printf "%s\0" "$tree_oid $tree_type $tree_size" >>expect &&
472
+ printf "%s\0" "$commit_oid $commit_type $commit_size" >>expect &&
473
+ printf "%s\0" "$tag_oid $tag_type $tag_size" >>expect &&
474
475
printf "%s\0" "$hello_oid missing" >>expect &&
476
printf "%s\0" "$tree_oid missing" >>expect &&
@@ -618,10 +618,10 @@ test_expect_success 'batch-command remote-object-info http:// default filter' '
618
set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
619
cd "$HTTPD_DOCUMENT_ROOT_PATH/http_client_empty" &&
620
621
- echo "$hello_oid $hello_size" >expect &&
622
- echo "$tree_oid $tree_size" >>expect &&
623
- echo "$commit_oid $commit_size" >>expect &&
624
- echo "$tag_oid $tag_size" >>expect &&
621
+ echo "$hello_oid $hello_type $hello_size" >expect &&
622
+ echo "$tree_oid $tree_type $tree_size" >>expect &&
623
+ echo "$commit_oid $commit_type $commit_size" >>expect &&
624
+ echo "$tag_oid $tag_type $tag_size" >>expect &&
625
626
git cat-file --batch-command >actual <<-EOF &&
627
remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid $tree_oid
@@ -636,10 +636,10 @@ test_expect_success 'batch-command -Z remote-object-info http:// default filter'
636
set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
637
cd "$HTTPD_DOCUMENT_ROOT_PATH/http_client_empty" &&
638
639
- printf "%s\0" "$hello_oid $hello_size" >expect &&
640
- printf "%s\0" "$tree_oid $tree_size" >>expect &&
641
- printf "%s\0" "$commit_oid $commit_size" >>expect &&
642
- printf "%s\0" "$tag_oid $tag_size" >>expect &&
639
+ printf "%s\0" "$hello_oid $hello_type $hello_size" >expect &&
640
+ printf "%s\0" "$tree_oid $tree_type $tree_size" >>expect &&
641
+ printf "%s\0" "$commit_oid $commit_type $commit_size" >>expect &&
642
+ printf "%s\0" "$tag_oid $tag_type $tag_size" >>expect &&
643
644
batch_input="remote-object-info $HTTPD_URL/smart/http_parent $hello_oid $tree_oid
645
remote-object-info $HTTPD_URL/smart/http_parent $commit_oid $tag_oid