@matheusbsbs / matheus-bagliano / commits / b0a8d4820b
Fork 0

pack-bitmap.c: support 'tree:0' filtering

In the previous patch, we made it easy to define other filters that exclude all objects of a certain type. Use that in order to implement bitmap-level filtering for the '--filter=tree:<n>' filter when 'n' is equal to 0. The general case is not helped by bitmaps, since for values of 'n > 0', the object filtering machinery requires a full-blown tree traversal in order to determine the depth of a given tree. Caching this is non-obvious, too, since the same tree object can have a different depth depending on the context (e.g., a tree was moved up in the directory hierarchy between two commits). But, the 'n = 0' case can be helped, and this patch does so. Running p5310.11 in this tree and on master with the kernel, we can see that this case is helped substantially: Test master this tree -------------------------------------------------------------------------------- 5310.11: rev-list count with tree:0 10.68(10.39+0.27) 0.06(0.04+0.01) -99.4% 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 b0a8d4820baa9966511ea9bd8c8b09dab087475f
3 files changed +50 -1
pack-bitmap.c
+24 -1
@@ -749,7 +749,7 @@ static void filter_bitmap_exclude_type(struct bitmap_index *bitmap_git,
749 eword_t mask;
750 uint32_t i;
751
752 - if (type != OBJ_BLOB)
752 + if (type != OBJ_BLOB && type != OBJ_TREE)
753 BUG("filter_bitmap_exclude_type: unsupported type '%d'", type);
754
755 /*
@@ -867,6 +867,20 @@ static void filter_bitmap_blob_limit(struct bitmap_index *bitmap_git,
867 bitmap_free(tips);
868 }
869
870 +static void filter_bitmap_tree_depth(struct bitmap_index *bitmap_git,
871 + struct object_list *tip_objects,
872 + struct bitmap *to_filter,
873 + unsigned long limit)
874 +{
875 + if (limit)
876 + BUG("filter_bitmap_tree_depth given non-zero limit");
877 +
878 + filter_bitmap_exclude_type(bitmap_git, tip_objects, to_filter,
879 + OBJ_TREE);
880 + filter_bitmap_exclude_type(bitmap_git, tip_objects, to_filter,
881 + OBJ_BLOB);
882 +}
883 +
884 static int filter_bitmap(struct bitmap_index *bitmap_git,
885 struct object_list *tip_objects,
886 struct bitmap *to_filter,
@@ -890,6 +904,15 @@ static int filter_bitmap(struct bitmap_index *bitmap_git,
904 return 0;
905 }
906
907 + if (filter->choice == LOFC_TREE_DEPTH &&
908 + filter->tree_exclude_depth == 0) {
909 + if (bitmap_git)
910 + filter_bitmap_tree_depth(bitmap_git, tip_objects,
911 + to_filter,
912 + filter->tree_exclude_depth);
913 + return 0;
914 + }
915 +
916 /* filter choice not handled */
917 return -1;
918 }
t/perf/p5310-pack-bitmaps.sh
+5
@@ -53,6 +53,11 @@ test_perf 'rev-list count with blob:limit=1k' '
53 --filter=blob:limit=1k >/dev/null
54 '
55
56 +test_perf 'rev-list count with tree:0' '
57 + git rev-list --use-bitmap-index --count --objects --all \
58 + --filter=tree:0 >/dev/null
59 +'
60 +
61 test_perf 'simulated partial clone' '
62 git pack-objects --stdout --all --filter=blob:none </dev/null >/dev/null
63 '
t/t6113-rev-list-bitmap-filters.sh
+21
@@ -53,4 +53,25 @@ test_expect_success 'blob:limit filter with specified blob' '
53 test_bitmap_traversal expect actual
54 '
55
56 +test_expect_success 'tree:0 filter' '
57 + git rev-list --objects --filter=tree:0 HEAD >expect &&
58 + git rev-list --use-bitmap-index \
59 + --objects --filter=tree:0 HEAD >actual &&
60 + test_bitmap_traversal expect actual
61 +'
62 +
63 +test_expect_success 'tree:0 filter with specified blob, tree' '
64 + git rev-list --objects --filter=tree:0 HEAD HEAD:two.t >expect &&
65 + git rev-list --use-bitmap-index \
66 + --objects --filter=tree:0 HEAD HEAD:two.t >actual &&
67 + test_bitmap_traversal expect actual
68 +'
69 +
70 +test_expect_success 'tree:1 filter' '
71 + git rev-list --objects --filter=tree:1 HEAD >expect &&
72 + git rev-list --use-bitmap-index \
73 + --objects --filter=tree:1 HEAD >actual &&
74 + test_cmp expect actual
75 +'
76 +
77 test_done