Skip to content

Commit c35b522

Browse files
ttaylorrderrickstolee
authored andcommitted
path-walk: support combine filter
The `combine` filter takes the intersection of its children, that is: objects are shown only when all child filters would admit the object. The preceding patches added support for many individual filter types. Enable users to compose these filters by implementing support for the `combine` filter type. Mapping intersection onto path_walk_info works because every supported child filter is a monotonic restriction: - `blob:none`, `tree:0` unconditionally clear `info->blobs` and (for `tree:0`) `info->trees`; clearing an already-cleared flag is a no-op. - `object:type=X` is now expressed as an AND of each type flag with the filtered type, so applying multiple such filters only refines the existing set rather than overwrites it. - `blob:limit=N` has to compose too: the intersection of "size < L1" and "size < L2" is "size < min(L1, L2)". Update the `LOFC_BLOB_LIMIT` handler to take the running minimum when `info->blob_limit` is already set, so a combined filter with, e.g., both "blob:limit=10" and "blob:limit=5" produces a limit of 5 regardless of ordering. - `sparse:oid` is left unchanged. A `combine` filter that includes a `sparse:oid` is allowed at most once, since the existing handler refuses to overwrite `info->pl`. Two `sparse:oid` filters in a single `combine` would be unusual and are rejected with a warning, matching the standalone `sparse:oid` behavior. Implementation-wise, the existing `prepare_filters()` called `list_objects_filter_release()` inside each case branch. That works fine for top-level filters, but `combine` filters need to recurse over its child filters without releasing each one in turn (since the parent's release iterates the sub array). Split `prepare_filters()` into a recursive helper that performs only the mutation, plus a thin wrapper that calls the helper and then releases the top-level filter once. The `LOFC_COMBINE` case in the helper just walks `sub_nr` and recurses; child filters are released by the wrapper's single `list_objects_filter_release()` call on the parent (which itself recursively releases each sub-filter, the same way it always has). If any sub-filter is unsupported (e.g. "tree:1", "sparse:<path>", or a not-yet-supported choice), the recursion bubbles a failure up and the existing pack-objects/backfill fallback paths kick in. Add coverage in t6601: - "combine:blob:none+tree:0" collapses to "tree:0" - "combine:object:type=blob+blob:limit=3" yields only the blobs smaller than three bytes - "combine:object:type=blob+object:type=tree" intersects to empty - "combine:tree:1+blob:none" reports the "tree:1" error. Update Documentation/git-pack-objects.adoc to add combine to the list of supported --filter forms. Signed-off-by: Taylor Blau <me@ttaylorr.com>
1 parent 8ce44cd commit c35b522

2 files changed

Lines changed: 86 additions & 10 deletions

File tree

path-walk.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -539,28 +539,26 @@ static int setup_pending_objects(struct path_walk_info *info,
539539
return 0;
540540
}
541541

542-
static int prepare_filters(struct path_walk_info *info,
543-
struct list_objects_filter_options *options)
542+
static int prepare_filters_one(struct path_walk_info *info,
543+
struct list_objects_filter_options *options)
544544
{
545545
switch (options->choice) {
546546
case LOFC_DISABLED:
547547
return 1;
548548

549549
case LOFC_BLOB_NONE:
550-
if (info) {
550+
if (info)
551551
info->blobs = 0;
552-
list_objects_filter_release(options);
553-
}
554552
return 1;
555553

556554
case LOFC_BLOB_LIMIT:
557555
if (info) {
558556
if (!options->blob_limit_value) {
559557
info->blobs = 0;
560-
} else {
558+
} else if (!info->blob_limit ||
559+
options->blob_limit_value < info->blob_limit) {
561560
info->blob_limit = options->blob_limit_value;
562561
}
563-
list_objects_filter_release(options);
564562
}
565563
return 1;
566564

@@ -573,7 +571,6 @@ static int prepare_filters(struct path_walk_info *info,
573571
if (info) {
574572
info->trees = 0;
575573
info->blobs = 0;
576-
list_objects_filter_release(options);
577574
}
578575
return 1;
579576

@@ -583,7 +580,6 @@ static int prepare_filters(struct path_walk_info *info,
583580
info->tags &= options->object_type == OBJ_TAG;
584581
info->trees &= options->object_type == OBJ_TREE;
585582
info->blobs &= options->object_type == OBJ_BLOB;
586-
list_objects_filter_release(options);
587583
}
588584
return 1;
589585

@@ -624,8 +620,13 @@ static int prepare_filters(struct path_walk_info *info,
624620
warning(_("sparse filter is not cone-mode compatible"));
625621
return 0;
626622
}
623+
}
624+
return 1;
627625

628-
list_objects_filter_release(options);
626+
case LOFC_COMBINE:
627+
for (size_t i = 0; i < options->sub_nr; i++) {
628+
if (!prepare_filters_one(info, &options->sub[i]))
629+
return 0;
629630
}
630631
return 1;
631632

@@ -636,6 +637,16 @@ static int prepare_filters(struct path_walk_info *info,
636637
}
637638
}
638639

640+
static int prepare_filters(struct path_walk_info *info,
641+
struct list_objects_filter_options *options)
642+
{
643+
if (!prepare_filters_one(info, options))
644+
return 0;
645+
if (info)
646+
list_objects_filter_release(options);
647+
return 1;
648+
}
649+
639650
int path_walk_filter_compatible(struct list_objects_filter_options *options)
640651
{
641652
return prepare_filters(NULL, options);

t/t6601-path-walk.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,71 @@ test_expect_success 'all, object:type=blob filter' '
721721
test_cmp_sorted expect out
722722
'
723723

724+
test_expect_success 'all, combine:blob:none+tree:0 filter' '
725+
test-tool path-walk \
726+
--filter=combine:blob:none+tree:0 -- --all >out &&
727+
728+
cat >expect <<-EOF &&
729+
0:commit::$(git rev-parse topic)
730+
0:commit::$(git rev-parse base)
731+
0:commit::$(git rev-parse base~1)
732+
0:commit::$(git rev-parse base~2)
733+
1:tag:/tags:$(git rev-parse refs/tags/first)
734+
1:tag:/tags:$(git rev-parse refs/tags/second.1)
735+
1:tag:/tags:$(git rev-parse refs/tags/second.2)
736+
1:tag:/tags:$(git rev-parse refs/tags/third)
737+
1:tag:/tags:$(git rev-parse refs/tags/fourth)
738+
1:tag:/tags:$(git rev-parse refs/tags/tree-tag)
739+
1:tag:/tags:$(git rev-parse refs/tags/blob-tag)
740+
blobs:0
741+
commits:4
742+
tags:7
743+
trees:0
744+
EOF
745+
746+
test_cmp_sorted expect out
747+
'
748+
749+
test_expect_success 'all, combine:object:type=blob+blob:limit=3 filter' '
750+
test-tool path-walk \
751+
--filter=combine:object:type=blob+blob:limit=3 \
752+
-- --all >out &&
753+
754+
cat >expect <<-EOF &&
755+
0:blob:a:$(git rev-parse base~2:a)
756+
1:blob:left/b:$(git rev-parse base~2:left/b)
757+
2:blob:right/c:$(git rev-parse base~2:right/c)
758+
3:blob:right/d:$(git rev-parse base~1:right/d)
759+
blobs:4
760+
commits:0
761+
tags:0
762+
trees:0
763+
EOF
764+
765+
test_cmp_sorted expect out
766+
'
767+
768+
test_expect_success 'all, combine of disjoint object:types is empty' '
769+
test-tool path-walk \
770+
--filter=combine:object:type=blob+object:type=tree \
771+
-- --all >out &&
772+
773+
cat >expect <<-EOF &&
774+
blobs:0
775+
commits:0
776+
tags:0
777+
trees:0
778+
EOF
779+
780+
test_cmp_sorted expect out
781+
'
782+
783+
test_expect_success 'combine: rejects unsupported subfilters' '
784+
test_must_fail test-tool path-walk \
785+
--filter=combine:tree:1+blob:none -- --all 2>err &&
786+
test_grep "tree:1 filter not supported by the path-walk API" err
787+
'
788+
724789
test_expect_success 'setup sparse filter blob' '
725790
# Cone-mode patterns: include root, exclude all dirs, include left/
726791
cat >patterns <<-\EOF &&

0 commit comments

Comments
 (0)