]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pack-bitmap: implement object type filter
authorPatrick Steinhardt <ps@pks.im>
Mon, 19 Apr 2021 11:46:58 +0000 (13:46 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 19 Apr 2021 21:09:11 +0000 (14:09 -0700)
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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pack-bitmap.c
t/t6113-rev-list-bitmap-filters.sh

index b4513f8672607be79020ad7ff861ed9d42baecc3..cd3f5c433eab0427eb1b16a1149ca366d8c305b8 100644 (file)
@@ -779,9 +779,6 @@ static void filter_bitmap_exclude_type(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
         * objects which the other side specifically asked for,
@@ -911,6 +908,24 @@ static void filter_bitmap_tree_depth(struct bitmap_index *bitmap_git,
                                   OBJ_BLOB);
 }
 
+static void filter_bitmap_object_type(struct bitmap_index *bitmap_git,
+                                     struct object_list *tip_objects,
+                                     struct bitmap *to_filter,
+                                     enum object_type object_type)
+{
+       if (object_type < OBJ_COMMIT || object_type > OBJ_TAG)
+               BUG("filter_bitmap_object_type given invalid object");
+
+       if (object_type != OBJ_TAG)
+               filter_bitmap_exclude_type(bitmap_git, tip_objects, to_filter, OBJ_TAG);
+       if (object_type != OBJ_COMMIT)
+               filter_bitmap_exclude_type(bitmap_git, tip_objects, to_filter, OBJ_COMMIT);
+       if (object_type != OBJ_TREE)
+               filter_bitmap_exclude_type(bitmap_git, tip_objects, to_filter, OBJ_TREE);
+       if (object_type != OBJ_BLOB)
+               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,
@@ -943,6 +958,14 @@ static int filter_bitmap(struct bitmap_index *bitmap_git,
                return 0;
        }
 
+       if (filter->choice == LOFC_OBJECT_TYPE) {
+               if (bitmap_git)
+                       filter_bitmap_object_type(bitmap_git, tip_objects,
+                                                 to_filter,
+                                                 filter->object_type);
+               return 0;
+       }
+
        /* filter choice not handled */
        return -1;
 }
index 3f889949ca14dc77eb6b39e5246bea3fe6823fd8..fb66735ac835283d7d68c503a760659fa7ab7052 100755 (executable)
@@ -10,7 +10,8 @@ test_expect_success 'set up bitmapped repo' '
        test_commit much-larger-blob-one &&
        git repack -adb &&
        test_commit two &&
-       test_commit much-larger-blob-two
+       test_commit much-larger-blob-two &&
+       git tag tag
 '
 
 test_expect_success 'filters fallback to non-bitmap traversal' '
@@ -75,4 +76,26 @@ test_expect_success 'tree:1 filter' '
        test_cmp expect actual
 '
 
+test_expect_success 'object:type filter' '
+       git rev-list --objects --filter=object:type=tag tag >expect &&
+       git rev-list --use-bitmap-index \
+                    --objects --filter=object:type=tag tag >actual &&
+       test_cmp expect actual &&
+
+       git rev-list --objects --filter=object:type=commit tag >expect &&
+       git rev-list --use-bitmap-index \
+                    --objects --filter=object:type=commit tag >actual &&
+       test_bitmap_traversal expect actual &&
+
+       git rev-list --objects --filter=object:type=tree tag >expect &&
+       git rev-list --use-bitmap-index \
+                    --objects --filter=object:type=tree tag >actual &&
+       test_bitmap_traversal expect actual &&
+
+       git rev-list --objects --filter=object:type=blob tag >expect &&
+       git rev-list --use-bitmap-index \
+                    --objects --filter=object:type=blob tag >actual &&
+       test_bitmap_traversal expect actual
+'
+
 test_done