File tree Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,11 @@ OPTIONS
9191 printed at all. The '<filter-spec>' may be one of the following:
9292+
9393The form '--filter=blob:none' omits all blobs.
94+ +
95+ The form '--filter=blob:limit=<n>[kmg]' omits blobs of size at least n
96+ bytes or units. n may be zero. The suffixes k, m, and g can be used to name
97+ units in KiB, MiB, or GiB. For example, 'blob:limit=1k' is the same as
98+ 'blob:limit=1024' .
9499
95100-- path=<path >::
96101 For use with `--textconv` or `--filters` , to allow specifying an object
Original file line number Diff line number Diff line change @@ -483,8 +483,11 @@ static void batch_object_write(const char *obj_name,
483483 int ret ;
484484
485485 if (use_mailmap ||
486- opt -> objects_filter .choice == LOFC_BLOB_NONE )
486+ opt -> objects_filter .choice == LOFC_BLOB_NONE ||
487+ opt -> objects_filter .choice == LOFC_BLOB_LIMIT )
487488 data -> info .typep = & data -> type ;
489+ if (opt -> objects_filter .choice == LOFC_BLOB_LIMIT )
490+ data -> info .sizep = & data -> size ;
488491
489492 if (pack )
490493 ret = packed_object_info (the_repository , pack , offset ,
@@ -509,6 +512,15 @@ static void batch_object_write(const char *obj_name,
509512 return ;
510513 }
511514 break ;
515+ case LOFC_BLOB_LIMIT :
516+ if (data -> type == OBJ_BLOB &&
517+ data -> size >= opt -> objects_filter .blob_limit_value ) {
518+ if (!opt -> all_objects )
519+ report_object_status (opt , obj_name ,
520+ & data -> oid , "excluded" );
521+ return ;
522+ }
523+ break ;
512524 default :
513525 BUG ("unsupported objects filter" );
514526 }
@@ -1049,6 +1061,7 @@ int cmd_cat_file(int argc,
10491061 case LOFC_DISABLED :
10501062 break ;
10511063 case LOFC_BLOB_NONE :
1064+ case LOFC_BLOB_LIMIT :
10521065 if (!batch .enabled )
10531066 usage (_ ("objects filter only supported in batch mode" ));
10541067 break ;
Original file line number Diff line number Diff line change @@ -1356,19 +1356,27 @@ test_expect_success PERL '--batch-command info is unbuffered by default' '
13561356test_expect_success ' setup for objects filter' '
13571357 git init repo &&
13581358 (
1359- # Seed the repository with three different sets of objects:
1359+ # Seed the repository with four different sets of objects:
13601360 #
13611361 # - The first set is fully packed and has a bitmap.
13621362 # - The second set is packed, but has no bitmap.
13631363 # - The third set is loose.
1364+ # - The fourth set is loose and contains big objects.
13641365 #
13651366 # This ensures that we cover all these types as expected.
13661367 cd repo &&
13671368 test_commit first &&
13681369 git repack -Adb &&
13691370 test_commit second &&
13701371 git repack -d &&
1371- test_commit third
1372+ test_commit third &&
1373+
1374+ for n in 1000 10000
1375+ do
1376+ printf "%"$n"s" X >large.$n || return 1
1377+ done &&
1378+ git add large.* &&
1379+ git commit -m fourth
13721380 )
13731381'
13741382
@@ -1380,7 +1388,7 @@ test_expect_success 'objects filter with unknown option' '
13801388 test_cmp expect err
13811389'
13821390
1383- for option in blob:limit=1 object:type=tag sparse:oid=1234 tree:1 sparse:path=x
1391+ for option in object:type=tag sparse:oid=1234 tree:1 sparse:path=x
13841392do
13851393 test_expect_success " objects filter with unsupported option $option " '
13861394 case "$option" in
@@ -1435,5 +1443,9 @@ test_objects_filter () {
14351443}
14361444
14371445test_objects_filter " blob:none"
1446+ test_objects_filter " blob:limit=1"
1447+ test_objects_filter " blob:limit=500"
1448+ test_objects_filter " blob:limit=1000"
1449+ test_objects_filter " blob:limit=1k"
14381450
14391451test_done
You can’t perform that action at this time.
0 commit comments