Skip to content

Commit b0a8d48

Browse files
ttaylorrgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 856e12c commit b0a8d48

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

pack-bitmap.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ static void filter_bitmap_exclude_type(struct bitmap_index *bitmap_git,
749749
eword_t mask;
750750
uint32_t i;
751751

752-
if (type != OBJ_BLOB)
752+
if (type != OBJ_BLOB && type != OBJ_TREE)
753753
BUG("filter_bitmap_exclude_type: unsupported type '%d'", type);
754754

755755
/*
@@ -867,6 +867,20 @@ static void filter_bitmap_blob_limit(struct bitmap_index *bitmap_git,
867867
bitmap_free(tips);
868868
}
869869

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+
870884
static int filter_bitmap(struct bitmap_index *bitmap_git,
871885
struct object_list *tip_objects,
872886
struct bitmap *to_filter,
@@ -890,6 +904,15 @@ static int filter_bitmap(struct bitmap_index *bitmap_git,
890904
return 0;
891905
}
892906

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+
893916
/* filter choice not handled */
894917
return -1;
895918
}

t/perf/p5310-pack-bitmaps.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ test_perf 'rev-list count with blob:limit=1k' '
5353
--filter=blob:limit=1k >/dev/null
5454
'
5555

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+
5661
test_perf 'simulated partial clone' '
5762
git pack-objects --stdout --all --filter=blob:none </dev/null >/dev/null
5863
'

t/t6113-rev-list-bitmap-filters.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,25 @@ test_expect_success 'blob:limit filter with specified blob' '
5353
test_bitmap_traversal expect actual
5454
'
5555

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+
5677
test_done

0 commit comments

Comments
 (0)