Skip to content

Commit 7ab6aaf

Browse files
pks-tgitster
authored andcommitted
pack-bitmap: implement object type filter
The preceding commit has added a new object filter for git-rev-list(1) which allows to filter objects by type. Implement the equivalent filter for packfile bitmaps so that we can answer these queries fast. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b0c42a5 commit 7ab6aaf

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

pack-bitmap.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -779,9 +779,6 @@ static void filter_bitmap_exclude_type(struct bitmap_index *bitmap_git,
779779
eword_t mask;
780780
uint32_t i;
781781

782-
if (type != OBJ_BLOB && type != OBJ_TREE)
783-
BUG("filter_bitmap_exclude_type: unsupported type '%d'", type);
784-
785782
/*
786783
* The non-bitmap version of this filter never removes
787784
* objects which the other side specifically asked for,
@@ -911,6 +908,24 @@ static void filter_bitmap_tree_depth(struct bitmap_index *bitmap_git,
911908
OBJ_BLOB);
912909
}
913910

911+
static void filter_bitmap_object_type(struct bitmap_index *bitmap_git,
912+
struct object_list *tip_objects,
913+
struct bitmap *to_filter,
914+
enum object_type object_type)
915+
{
916+
if (object_type < OBJ_COMMIT || object_type > OBJ_TAG)
917+
BUG("filter_bitmap_object_type given invalid object");
918+
919+
if (object_type != OBJ_TAG)
920+
filter_bitmap_exclude_type(bitmap_git, tip_objects, to_filter, OBJ_TAG);
921+
if (object_type != OBJ_COMMIT)
922+
filter_bitmap_exclude_type(bitmap_git, tip_objects, to_filter, OBJ_COMMIT);
923+
if (object_type != OBJ_TREE)
924+
filter_bitmap_exclude_type(bitmap_git, tip_objects, to_filter, OBJ_TREE);
925+
if (object_type != OBJ_BLOB)
926+
filter_bitmap_exclude_type(bitmap_git, tip_objects, to_filter, OBJ_BLOB);
927+
}
928+
914929
static int filter_bitmap(struct bitmap_index *bitmap_git,
915930
struct object_list *tip_objects,
916931
struct bitmap *to_filter,
@@ -943,6 +958,14 @@ static int filter_bitmap(struct bitmap_index *bitmap_git,
943958
return 0;
944959
}
945960

961+
if (filter->choice == LOFC_OBJECT_TYPE) {
962+
if (bitmap_git)
963+
filter_bitmap_object_type(bitmap_git, tip_objects,
964+
to_filter,
965+
filter->object_type);
966+
return 0;
967+
}
968+
946969
/* filter choice not handled */
947970
return -1;
948971
}

t/t6113-rev-list-bitmap-filters.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ test_expect_success 'set up bitmapped repo' '
1010
test_commit much-larger-blob-one &&
1111
git repack -adb &&
1212
test_commit two &&
13-
test_commit much-larger-blob-two
13+
test_commit much-larger-blob-two &&
14+
git tag tag
1415
'
1516

1617
test_expect_success 'filters fallback to non-bitmap traversal' '
@@ -75,4 +76,26 @@ test_expect_success 'tree:1 filter' '
7576
test_cmp expect actual
7677
'
7778

79+
test_expect_success 'object:type filter' '
80+
git rev-list --objects --filter=object:type=tag tag >expect &&
81+
git rev-list --use-bitmap-index \
82+
--objects --filter=object:type=tag tag >actual &&
83+
test_cmp expect actual &&
84+
85+
git rev-list --objects --filter=object:type=commit tag >expect &&
86+
git rev-list --use-bitmap-index \
87+
--objects --filter=object:type=commit tag >actual &&
88+
test_bitmap_traversal expect actual &&
89+
90+
git rev-list --objects --filter=object:type=tree tag >expect &&
91+
git rev-list --use-bitmap-index \
92+
--objects --filter=object:type=tree tag >actual &&
93+
test_bitmap_traversal expect actual &&
94+
95+
git rev-list --objects --filter=object:type=blob tag >expect &&
96+
git rev-list --use-bitmap-index \
97+
--objects --filter=object:type=blob tag >actual &&
98+
test_bitmap_traversal expect actual
99+
'
100+
78101
test_done

0 commit comments

Comments
 (0)