Skip to content

Commit 69ae8ff

Browse files
committed
Merge branch 'tb/bitmap-walk-with-tree-zero-filter'
The object walk with object filter "--filter=tree:0" can now take advantage of the pack bitmap when available. * tb/bitmap-walk-with-tree-zero-filter: pack-bitmap: pass object filter to fill-in traversal pack-bitmap.c: support 'tree:0' filtering pack-bitmap.c: make object filtering functions generic list-objects-filter: treat NULL filter_options as "disabled"
2 parents 896833b + 9639474 commit 69ae8ff

File tree

4 files changed

+90
-16
lines changed

4 files changed

+90
-16
lines changed

list-objects-filter.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,9 @@ struct filter *list_objects_filter__init(
663663

664664
assert((sizeof(s_filters) / sizeof(s_filters[0])) == LOFC__COUNT);
665665

666+
if (!filter_options)
667+
return NULL;
668+
666669
if (filter_options->choice >= LOFC__COUNT)
667670
BUG("invalid list-objects filter choice: %d",
668671
filter_options->choice);

pack-bitmap.c

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,8 @@ static int should_include(struct commit *commit, void *_data)
506506
static struct bitmap *find_objects(struct bitmap_index *bitmap_git,
507507
struct rev_info *revs,
508508
struct object_list *roots,
509-
struct bitmap *seen)
509+
struct bitmap *seen,
510+
struct list_objects_filter_options *filter)
510511
{
511512
struct bitmap *base = NULL;
512513
int needs_walk = 0;
@@ -599,8 +600,9 @@ static struct bitmap *find_objects(struct bitmap_index *bitmap_git,
599600
show_data.bitmap_git = bitmap_git;
600601
show_data.base = base;
601602

602-
traverse_commit_list(revs, show_commit, show_object,
603-
&show_data);
603+
traverse_commit_list_filtered(filter, revs,
604+
show_commit, show_object,
605+
&show_data, NULL);
604606
}
605607

606608
return base;
@@ -715,16 +717,17 @@ static int in_bitmapped_pack(struct bitmap_index *bitmap_git,
715717
return 0;
716718
}
717719

718-
static struct bitmap *find_tip_blobs(struct bitmap_index *bitmap_git,
719-
struct object_list *tip_objects)
720+
static struct bitmap *find_tip_objects(struct bitmap_index *bitmap_git,
721+
struct object_list *tip_objects,
722+
enum object_type type)
720723
{
721724
struct bitmap *result = bitmap_new();
722725
struct object_list *p;
723726

724727
for (p = tip_objects; p; p = p->next) {
725728
int pos;
726729

727-
if (p->item->type != OBJ_BLOB)
730+
if (p->item->type != type)
728731
continue;
729732

730733
pos = bitmap_position(bitmap_git, &p->item->oid);
@@ -737,28 +740,32 @@ static struct bitmap *find_tip_blobs(struct bitmap_index *bitmap_git,
737740
return result;
738741
}
739742

740-
static void filter_bitmap_blob_none(struct bitmap_index *bitmap_git,
741-
struct object_list *tip_objects,
742-
struct bitmap *to_filter)
743+
static void filter_bitmap_exclude_type(struct bitmap_index *bitmap_git,
744+
struct object_list *tip_objects,
745+
struct bitmap *to_filter,
746+
enum object_type type)
743747
{
744748
struct eindex *eindex = &bitmap_git->ext_index;
745749
struct bitmap *tips;
746750
struct ewah_iterator it;
747751
eword_t mask;
748752
uint32_t i;
749753

754+
if (type != OBJ_BLOB && type != OBJ_TREE)
755+
BUG("filter_bitmap_exclude_type: unsupported type '%d'", type);
756+
750757
/*
751758
* The non-bitmap version of this filter never removes
752-
* blobs which the other side specifically asked for,
759+
* objects which the other side specifically asked for,
753760
* so we must match that behavior.
754761
*/
755-
tips = find_tip_blobs(bitmap_git, tip_objects);
762+
tips = find_tip_objects(bitmap_git, tip_objects, type);
756763

757764
/*
758765
* We can use the blob type-bitmap to work in whole words
759766
* for the objects that are actually in the bitmapped packfile.
760767
*/
761-
for (i = 0, init_type_iterator(&it, bitmap_git, OBJ_BLOB);
768+
for (i = 0, init_type_iterator(&it, bitmap_git, type);
762769
i < to_filter->word_alloc && ewah_iterator_next(&mask, &it);
763770
i++) {
764771
if (i < tips->word_alloc)
@@ -773,7 +780,7 @@ static void filter_bitmap_blob_none(struct bitmap_index *bitmap_git,
773780
*/
774781
for (i = 0; i < eindex->count; i++) {
775782
uint32_t pos = i + bitmap_git->pack->num_objects;
776-
if (eindex->objects[i]->type == OBJ_BLOB &&
783+
if (eindex->objects[i]->type == type &&
777784
bitmap_get(to_filter, pos) &&
778785
!bitmap_get(tips, pos))
779786
bitmap_unset(to_filter, pos);
@@ -782,6 +789,14 @@ static void filter_bitmap_blob_none(struct bitmap_index *bitmap_git,
782789
bitmap_free(tips);
783790
}
784791

792+
static void filter_bitmap_blob_none(struct bitmap_index *bitmap_git,
793+
struct object_list *tip_objects,
794+
struct bitmap *to_filter)
795+
{
796+
filter_bitmap_exclude_type(bitmap_git, tip_objects, to_filter,
797+
OBJ_BLOB);
798+
}
799+
785800
static unsigned long get_size_by_pos(struct bitmap_index *bitmap_git,
786801
uint32_t pos)
787802
{
@@ -820,7 +835,7 @@ static void filter_bitmap_blob_limit(struct bitmap_index *bitmap_git,
820835
eword_t mask;
821836
uint32_t i;
822837

823-
tips = find_tip_blobs(bitmap_git, tip_objects);
838+
tips = find_tip_objects(bitmap_git, tip_objects, OBJ_BLOB);
824839

825840
for (i = 0, init_type_iterator(&it, bitmap_git, OBJ_BLOB);
826841
i < to_filter->word_alloc && ewah_iterator_next(&mask, &it);
@@ -854,6 +869,20 @@ static void filter_bitmap_blob_limit(struct bitmap_index *bitmap_git,
854869
bitmap_free(tips);
855870
}
856871

872+
static void filter_bitmap_tree_depth(struct bitmap_index *bitmap_git,
873+
struct object_list *tip_objects,
874+
struct bitmap *to_filter,
875+
unsigned long limit)
876+
{
877+
if (limit)
878+
BUG("filter_bitmap_tree_depth given non-zero limit");
879+
880+
filter_bitmap_exclude_type(bitmap_git, tip_objects, to_filter,
881+
OBJ_TREE);
882+
filter_bitmap_exclude_type(bitmap_git, tip_objects, to_filter,
883+
OBJ_BLOB);
884+
}
885+
857886
static int filter_bitmap(struct bitmap_index *bitmap_git,
858887
struct object_list *tip_objects,
859888
struct bitmap *to_filter,
@@ -877,6 +906,15 @@ static int filter_bitmap(struct bitmap_index *bitmap_git,
877906
return 0;
878907
}
879908

909+
if (filter->choice == LOFC_TREE_DEPTH &&
910+
filter->tree_exclude_depth == 0) {
911+
if (bitmap_git)
912+
filter_bitmap_tree_depth(bitmap_git, tip_objects,
913+
to_filter,
914+
filter->tree_exclude_depth);
915+
return 0;
916+
}
917+
880918
/* filter choice not handled */
881919
return -1;
882920
}
@@ -963,15 +1001,17 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
9631001

9641002
if (haves) {
9651003
revs->ignore_missing_links = 1;
966-
haves_bitmap = find_objects(bitmap_git, revs, haves, NULL);
1004+
haves_bitmap = find_objects(bitmap_git, revs, haves, NULL,
1005+
filter);
9671006
reset_revision_walk();
9681007
revs->ignore_missing_links = 0;
9691008

9701009
if (haves_bitmap == NULL)
9711010
BUG("failed to perform bitmap walk");
9721011
}
9731012

974-
wants_bitmap = find_objects(bitmap_git, revs, wants, haves_bitmap);
1013+
wants_bitmap = find_objects(bitmap_git, revs, wants, haves_bitmap,
1014+
filter);
9751015

9761016
if (!wants_bitmap)
9771017
BUG("failed to perform bitmap walk");

t/perf/p5310-pack-bitmaps.sh

Lines changed: 10 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
'
@@ -86,4 +91,9 @@ test_perf 'pack to file (partial bitmap)' '
8691
git pack-objects --use-bitmap-index --all pack2b </dev/null >/dev/null
8792
'
8893

94+
test_perf 'rev-list with tree filter (partial bitmap)' '
95+
git rev-list --use-bitmap-index --count --objects --all \
96+
--filter=tree:0 >/dev/null
97+
'
98+
8999
test_done

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)