Skip to content

Commit 2528bc9

Browse files
pks-tgitster
authored andcommitted
builtin/cat-file: support "object:type=" objects filter
Implement support for the "object:type=" filter in git-cat-file(1), which causes us to omit all objects that don't match the provided object type. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 647fa83 commit 2528bc9

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

Documentation/git-cat-file.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ The form '--filter=blob:limit=<n>[kmg]' omits blobs of size at least n
9393
bytes or units. n may be zero. The suffixes k, m, and g can be used to name
9494
units in KiB, MiB, or GiB. For example, 'blob:limit=1k' is the same as
9595
'blob:limit=1024'.
96+
+
97+
The form '--filter=object:type=(tag|commit|tree|blob)' omits all objects which
98+
are not of the requested type.
9699

97100
--path=<path>::
98101
For use with `--textconv` or `--filters`, to allow specifying an object

builtin/cat-file.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,8 @@ static void batch_object_write(const char *obj_name,
474474

475475
if (use_mailmap ||
476476
opt->objects_filter.choice == LOFC_BLOB_NONE ||
477-
opt->objects_filter.choice == LOFC_BLOB_LIMIT)
477+
opt->objects_filter.choice == LOFC_BLOB_LIMIT ||
478+
opt->objects_filter.choice == LOFC_OBJECT_TYPE)
478479
data->info.typep = &data->type;
479480
if (opt->objects_filter.choice == LOFC_BLOB_LIMIT)
480481
data->info.sizep = &data->size;
@@ -505,6 +506,10 @@ static void batch_object_write(const char *obj_name,
505506
data->size >= opt->objects_filter.blob_limit_value)
506507
return;
507508
break;
509+
case LOFC_OBJECT_TYPE:
510+
if (data->type != opt->objects_filter.object_type)
511+
return;
512+
break;
508513
default:
509514
BUG("unsupported objects filter");
510515
}
@@ -1047,6 +1052,7 @@ int cmd_cat_file(int argc,
10471052
break;
10481053
case LOFC_BLOB_NONE:
10491054
case LOFC_BLOB_LIMIT:
1055+
case LOFC_OBJECT_TYPE:
10501056
if (!batch.enabled)
10511057
usage(_("objects filter only supported in batch mode"));
10521058
break;

t/t1006-cat-file.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ test_expect_success 'objects filter with unknown option' '
13881388
test_cmp expect err
13891389
'
13901390

1391-
for option in object:type=tag sparse:oid=1234 tree:1 sparse:path=x
1391+
for option in sparse:oid=1234 tree:1 sparse:path=x
13921392
do
13931393
test_expect_success "objects filter with unsupported option $option" '
13941394
case "$option" in
@@ -1425,5 +1425,9 @@ test_objects_filter "blob:limit=1"
14251425
test_objects_filter "blob:limit=500"
14261426
test_objects_filter "blob:limit=1000"
14271427
test_objects_filter "blob:limit=1g"
1428+
test_objects_filter "object:type=blob"
1429+
test_objects_filter "object:type=commit"
1430+
test_objects_filter "object:type=tag"
1431+
test_objects_filter "object:type=tree"
14281432

14291433
test_done

0 commit comments

Comments
 (0)