Skip to content

Commit 856e12c

Browse files
ttaylorrgitster
authored andcommitted
pack-bitmap.c: make object filtering functions generic
In 4f3bd56 (pack-bitmap: implement BLOB_NONE filtering, 2020-02-14), filtering support for bitmaps was added for the 'LOFC_BLOB_NONE' filter. In the future, we would like to add support for filters that behave as if they exclude a certain type of object, for e.g., the tree depth filter with depth 0. To prepare for this, make some of the functions used for filtering more generic, such as 'find_tip_blobs' and 'filter_bitmap_blob_none' so that they can work over arbitrary object types. To that end, create 'find_tip_objects' and 'filter_bitmap_exclude_type', and redefine the aforementioned functions in terms of those. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5bf7f1e commit 856e12c

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

pack-bitmap.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -715,16 +715,17 @@ static int in_bitmapped_pack(struct bitmap_index *bitmap_git,
715715
return 0;
716716
}
717717

718-
static struct bitmap *find_tip_blobs(struct bitmap_index *bitmap_git,
719-
struct object_list *tip_objects)
718+
static struct bitmap *find_tip_objects(struct bitmap_index *bitmap_git,
719+
struct object_list *tip_objects,
720+
enum object_type type)
720721
{
721722
struct bitmap *result = bitmap_new();
722723
struct object_list *p;
723724

724725
for (p = tip_objects; p; p = p->next) {
725726
int pos;
726727

727-
if (p->item->type != OBJ_BLOB)
728+
if (p->item->type != type)
728729
continue;
729730

730731
pos = bitmap_position(bitmap_git, &p->item->oid);
@@ -737,28 +738,32 @@ static struct bitmap *find_tip_blobs(struct bitmap_index *bitmap_git,
737738
return result;
738739
}
739740

740-
static void filter_bitmap_blob_none(struct bitmap_index *bitmap_git,
741-
struct object_list *tip_objects,
742-
struct bitmap *to_filter)
741+
static void filter_bitmap_exclude_type(struct bitmap_index *bitmap_git,
742+
struct object_list *tip_objects,
743+
struct bitmap *to_filter,
744+
enum object_type type)
743745
{
744746
struct eindex *eindex = &bitmap_git->ext_index;
745747
struct bitmap *tips;
746748
struct ewah_iterator it;
747749
eword_t mask;
748750
uint32_t i;
749751

752+
if (type != OBJ_BLOB)
753+
BUG("filter_bitmap_exclude_type: unsupported type '%d'", type);
754+
750755
/*
751756
* The non-bitmap version of this filter never removes
752-
* blobs which the other side specifically asked for,
757+
* objects which the other side specifically asked for,
753758
* so we must match that behavior.
754759
*/
755-
tips = find_tip_blobs(bitmap_git, tip_objects);
760+
tips = find_tip_objects(bitmap_git, tip_objects, type);
756761

757762
/*
758763
* We can use the blob type-bitmap to work in whole words
759764
* for the objects that are actually in the bitmapped packfile.
760765
*/
761-
for (i = 0, init_type_iterator(&it, bitmap_git, OBJ_BLOB);
766+
for (i = 0, init_type_iterator(&it, bitmap_git, type);
762767
i < to_filter->word_alloc && ewah_iterator_next(&mask, &it);
763768
i++) {
764769
if (i < tips->word_alloc)
@@ -773,7 +778,7 @@ static void filter_bitmap_blob_none(struct bitmap_index *bitmap_git,
773778
*/
774779
for (i = 0; i < eindex->count; i++) {
775780
uint32_t pos = i + bitmap_git->pack->num_objects;
776-
if (eindex->objects[i]->type == OBJ_BLOB &&
781+
if (eindex->objects[i]->type == type &&
777782
bitmap_get(to_filter, pos) &&
778783
!bitmap_get(tips, pos))
779784
bitmap_unset(to_filter, pos);
@@ -782,6 +787,14 @@ static void filter_bitmap_blob_none(struct bitmap_index *bitmap_git,
782787
bitmap_free(tips);
783788
}
784789

790+
static void filter_bitmap_blob_none(struct bitmap_index *bitmap_git,
791+
struct object_list *tip_objects,
792+
struct bitmap *to_filter)
793+
{
794+
filter_bitmap_exclude_type(bitmap_git, tip_objects, to_filter,
795+
OBJ_BLOB);
796+
}
797+
785798
static unsigned long get_size_by_pos(struct bitmap_index *bitmap_git,
786799
uint32_t pos)
787800
{
@@ -820,7 +833,7 @@ static void filter_bitmap_blob_limit(struct bitmap_index *bitmap_git,
820833
eword_t mask;
821834
uint32_t i;
822835

823-
tips = find_tip_blobs(bitmap_git, tip_objects);
836+
tips = find_tip_objects(bitmap_git, tip_objects, OBJ_BLOB);
824837

825838
for (i = 0, init_type_iterator(&it, bitmap_git, OBJ_BLOB);
826839
i < to_filter->word_alloc && ewah_iterator_next(&mask, &it);

0 commit comments

Comments
 (0)