]> git.ipfire.org Git - thirdparty/git.git/blobdiff - pack-bitmap.c
pack-bitmap.c: support 'tree:0' filtering
[thirdparty/git.git] / pack-bitmap.c
index 49a8d10d0cf99716ea37b78bec578ca96c17de20..195ee8cad02d54d3ea6c38d1bc8afbc733717df5 100644 (file)
@@ -715,8 +715,9 @@ static int in_bitmapped_pack(struct bitmap_index *bitmap_git,
        return 0;
 }
 
-static struct bitmap *find_tip_blobs(struct bitmap_index *bitmap_git,
-                                    struct object_list *tip_objects)
+static struct bitmap *find_tip_objects(struct bitmap_index *bitmap_git,
+                                      struct object_list *tip_objects,
+                                      enum object_type type)
 {
        struct bitmap *result = bitmap_new();
        struct object_list *p;
@@ -724,7 +725,7 @@ static struct bitmap *find_tip_blobs(struct bitmap_index *bitmap_git,
        for (p = tip_objects; p; p = p->next) {
                int pos;
 
-               if (p->item->type != OBJ_BLOB)
+               if (p->item->type != type)
                        continue;
 
                pos = bitmap_position(bitmap_git, &p->item->oid);
@@ -737,9 +738,10 @@ static struct bitmap *find_tip_blobs(struct bitmap_index *bitmap_git,
        return result;
 }
 
-static void filter_bitmap_blob_none(struct bitmap_index *bitmap_git,
-                                   struct object_list *tip_objects,
-                                   struct bitmap *to_filter)
+static void filter_bitmap_exclude_type(struct bitmap_index *bitmap_git,
+                                      struct object_list *tip_objects,
+                                      struct bitmap *to_filter,
+                                      enum object_type type)
 {
        struct eindex *eindex = &bitmap_git->ext_index;
        struct bitmap *tips;
@@ -747,18 +749,21 @@ static void filter_bitmap_blob_none(struct bitmap_index *bitmap_git,
        eword_t mask;
        uint32_t i;
 
+       if (type != OBJ_BLOB && type != OBJ_TREE)
+               BUG("filter_bitmap_exclude_type: unsupported type '%d'", type);
+
        /*
         * The non-bitmap version of this filter never removes
-        * blobs which the other side specifically asked for,
+        * objects which the other side specifically asked for,
         * so we must match that behavior.
         */
-       tips = find_tip_blobs(bitmap_git, tip_objects);
+       tips = find_tip_objects(bitmap_git, tip_objects, type);
 
        /*
         * We can use the blob type-bitmap to work in whole words
         * for the objects that are actually in the bitmapped packfile.
         */
-       for (i = 0, init_type_iterator(&it, bitmap_git, OBJ_BLOB);
+       for (i = 0, init_type_iterator(&it, bitmap_git, type);
             i < to_filter->word_alloc && ewah_iterator_next(&mask, &it);
             i++) {
                if (i < tips->word_alloc)
@@ -773,7 +778,7 @@ static void filter_bitmap_blob_none(struct bitmap_index *bitmap_git,
         */
        for (i = 0; i < eindex->count; i++) {
                uint32_t pos = i + bitmap_git->pack->num_objects;
-               if (eindex->objects[i]->type == OBJ_BLOB &&
+               if (eindex->objects[i]->type == type &&
                    bitmap_get(to_filter, pos) &&
                    !bitmap_get(tips, pos))
                        bitmap_unset(to_filter, pos);
@@ -782,6 +787,14 @@ static void filter_bitmap_blob_none(struct bitmap_index *bitmap_git,
        bitmap_free(tips);
 }
 
+static void filter_bitmap_blob_none(struct bitmap_index *bitmap_git,
+                                   struct object_list *tip_objects,
+                                   struct bitmap *to_filter)
+{
+       filter_bitmap_exclude_type(bitmap_git, tip_objects, to_filter,
+                                  OBJ_BLOB);
+}
+
 static unsigned long get_size_by_pos(struct bitmap_index *bitmap_git,
                                     uint32_t pos)
 {
@@ -820,7 +833,7 @@ static void filter_bitmap_blob_limit(struct bitmap_index *bitmap_git,
        eword_t mask;
        uint32_t i;
 
-       tips = find_tip_blobs(bitmap_git, tip_objects);
+       tips = find_tip_objects(bitmap_git, tip_objects, OBJ_BLOB);
 
        for (i = 0, init_type_iterator(&it, bitmap_git, OBJ_BLOB);
             i < to_filter->word_alloc && ewah_iterator_next(&mask, &it);
@@ -854,6 +867,20 @@ static void filter_bitmap_blob_limit(struct bitmap_index *bitmap_git,
        bitmap_free(tips);
 }
 
+static void filter_bitmap_tree_depth(struct bitmap_index *bitmap_git,
+                                    struct object_list *tip_objects,
+                                    struct bitmap *to_filter,
+                                    unsigned long limit)
+{
+       if (limit)
+               BUG("filter_bitmap_tree_depth given non-zero limit");
+
+       filter_bitmap_exclude_type(bitmap_git, tip_objects, to_filter,
+                                  OBJ_TREE);
+       filter_bitmap_exclude_type(bitmap_git, tip_objects, to_filter,
+                                  OBJ_BLOB);
+}
+
 static int filter_bitmap(struct bitmap_index *bitmap_git,
                         struct object_list *tip_objects,
                         struct bitmap *to_filter,
@@ -877,6 +904,15 @@ static int filter_bitmap(struct bitmap_index *bitmap_git,
                return 0;
        }
 
+       if (filter->choice == LOFC_TREE_DEPTH &&
+           filter->tree_exclude_depth == 0) {
+               if (bitmap_git)
+                       filter_bitmap_tree_depth(bitmap_git, tip_objects,
+                                                to_filter,
+                                                filter->tree_exclude_depth);
+               return 0;
+       }
+
        /* filter choice not handled */
        return -1;
 }