pack-bitmap.c: make object filtering functions generic
In 4f3bd5606a (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 <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Taylor Blau committed
May 4, 2020 at 17:12 UTC
856e12c18a4616bbfbdfd1777577c1182b148519
1 file changed
+24
-11
pack-bitmap.c
+24
-11
@@ -715,8 +715,9 @@ static int in_bitmapped_pack(struct bitmap_index *bitmap_git,
715
return 0;
716
}
717
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)
721
{
722
struct bitmap *result = bitmap_new();
723
struct object_list *p;
@@ -724,7 +725,7 @@ static struct bitmap *find_tip_blobs(struct bitmap_index *bitmap_git,
725
for (p = tip_objects; p; p = p->next) {
726
int pos;
727
727
- if (p->item->type != OBJ_BLOB)
728
+ if (p->item->type != type)
729
continue;
730
731
pos = bitmap_position(bitmap_git, &p->item->oid);
@@ -737,9 +738,10 @@ static struct bitmap *find_tip_blobs(struct bitmap_index *bitmap_git,
738
return result;
739
}
740
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)
745
{
746
struct eindex *eindex = &bitmap_git->ext_index;
747
struct bitmap *tips;
@@ -747,18 +749,21 @@ static void filter_bitmap_blob_none(struct bitmap_index *bitmap_git,
749
eword_t mask;
750
uint32_t i;
751
752
+ if (type != OBJ_BLOB)
753
+ BUG("filter_bitmap_exclude_type: unsupported type '%d'", type);
754
+
755
/*
756
* 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,
758
* so we must match that behavior.
759
*/
755
- tips = find_tip_blobs(bitmap_git, tip_objects);
760
+ tips = find_tip_objects(bitmap_git, tip_objects, type);
761
762
/*
763
* We can use the blob type-bitmap to work in whole words
764
* for the objects that are actually in the bitmapped packfile.
765
*/
761
- for (i = 0, init_type_iterator(&it, bitmap_git, OBJ_BLOB);
766
+ for (i = 0, init_type_iterator(&it, bitmap_git, type);
767
i < to_filter->word_alloc && ewah_iterator_next(&mask, &it);
768
i++) {
769
if (i < tips->word_alloc)
@@ -773,7 +778,7 @@ static void filter_bitmap_blob_none(struct bitmap_index *bitmap_git,
778
*/
779
for (i = 0; i < eindex->count; i++) {
780
uint32_t pos = i + bitmap_git->pack->num_objects;
776
- if (eindex->objects[i]->type == OBJ_BLOB &&
781
+ if (eindex->objects[i]->type == type &&
782
bitmap_get(to_filter, pos) &&
783
!bitmap_get(tips, pos))
784
bitmap_unset(to_filter, pos);
@@ -782,6 +787,14 @@ static void filter_bitmap_blob_none(struct bitmap_index *bitmap_git,
787
bitmap_free(tips);
788
}
789
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
+
798
static unsigned long get_size_by_pos(struct bitmap_index *bitmap_git,
799
uint32_t pos)
800
{
@@ -820,7 +833,7 @@ static void filter_bitmap_blob_limit(struct bitmap_index *bitmap_git,
833
eword_t mask;
834
uint32_t i;
835
823
- tips = find_tip_blobs(bitmap_git, tip_objects);
836
+ tips = find_tip_objects(bitmap_git, tip_objects, OBJ_BLOB);
837
838
for (i = 0, init_type_iterator(&it, bitmap_git, OBJ_BLOB);
839
i < to_filter->word_alloc && ewah_iterator_next(&mask, &it);