summaryrefslogtreecommitdiff
path: root/pack-bitmap.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2020-02-13 02:16:15 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-02-13 17:08:58 (GMT)
commit551cf8b655fa73c90dabea633d41b5f10deffaf2 (patch)
tree383f605a4a3c209ce9935ad38d99f8422207047c /pack-bitmap.c
parentd0654dc308b0ba76dd8ed7bbb33c8d8f7aacd783 (diff)
downloadgit-551cf8b655fa73c90dabea633d41b5f10deffaf2.zip
git-551cf8b655fa73c90dabea633d41b5f10deffaf2.tar.gz
git-551cf8b655fa73c90dabea633d41b5f10deffaf2.tar.bz2
pack-bitmap: factor out type iterator initialization
When count_object_type() wants to iterate over the bitmap of all objects of a certain type, we have to pair up OBJ_COMMIT with bitmap->commits, and so forth. Since we're about to add more code to iterate over these bitmaps, let's pull the initialization into its own function. We can also use this to simplify traverse_bitmap_commit_list(). It accomplishes the same thing by manually passing the object type and the bitmap to show_objects_for_type(), but using our helper we just need the object type. Note there's one small code change here: previously we'd simply return zero when counting an unknown object type, and now we'll BUG(). This shouldn't matter in practice, as all of the callers pass in only usual commit/tree/blob/tag types. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pack-bitmap.c')
-rw-r--r--pack-bitmap.c63
1 files changed, 33 insertions, 30 deletions
diff --git a/pack-bitmap.c b/pack-bitmap.c
index e07c798..9ca356e 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -616,9 +616,35 @@ static void show_extended_objects(struct bitmap_index *bitmap_git,
}
}
+static void init_type_iterator(struct ewah_iterator *it,
+ struct bitmap_index *bitmap_git,
+ enum object_type type)
+{
+ switch (type) {
+ case OBJ_COMMIT:
+ ewah_iterator_init(it, bitmap_git->commits);
+ break;
+
+ case OBJ_TREE:
+ ewah_iterator_init(it, bitmap_git->trees);
+ break;
+
+ case OBJ_BLOB:
+ ewah_iterator_init(it, bitmap_git->blobs);
+ break;
+
+ case OBJ_TAG:
+ ewah_iterator_init(it, bitmap_git->tags);
+ break;
+
+ default:
+ BUG("object type %d not stored by bitmap type index", type);
+ break;
+ }
+}
+
static void show_objects_for_type(
struct bitmap_index *bitmap_git,
- struct ewah_bitmap *type_filter,
enum object_type object_type,
show_reachable_fn show_reach)
{
@@ -633,7 +659,7 @@ static void show_objects_for_type(
if (bitmap_git->reuse_objects == bitmap_git->pack->num_objects)
return;
- ewah_iterator_init(&it, type_filter);
+ init_type_iterator(&it, bitmap_git, object_type);
while (i < objects->word_alloc && ewah_iterator_next(&filter, &it)) {
eword_t word = objects->words[i] & filter;
@@ -835,14 +861,10 @@ void traverse_bitmap_commit_list(struct bitmap_index *bitmap_git,
{
assert(bitmap_git->result);
- show_objects_for_type(bitmap_git, bitmap_git->commits,
- OBJ_COMMIT, show_reachable);
- show_objects_for_type(bitmap_git, bitmap_git->trees,
- OBJ_TREE, show_reachable);
- show_objects_for_type(bitmap_git, bitmap_git->blobs,
- OBJ_BLOB, show_reachable);
- show_objects_for_type(bitmap_git, bitmap_git->tags,
- OBJ_TAG, show_reachable);
+ show_objects_for_type(bitmap_git, OBJ_COMMIT, show_reachable);
+ show_objects_for_type(bitmap_git, OBJ_TREE, show_reachable);
+ show_objects_for_type(bitmap_git, OBJ_BLOB, show_reachable);
+ show_objects_for_type(bitmap_git, OBJ_TAG, show_reachable);
show_extended_objects(bitmap_git, show_reachable);
}
@@ -857,26 +879,7 @@ static uint32_t count_object_type(struct bitmap_index *bitmap_git,
struct ewah_iterator it;
eword_t filter;
- switch (type) {
- case OBJ_COMMIT:
- ewah_iterator_init(&it, bitmap_git->commits);
- break;
-
- case OBJ_TREE:
- ewah_iterator_init(&it, bitmap_git->trees);
- break;
-
- case OBJ_BLOB:
- ewah_iterator_init(&it, bitmap_git->blobs);
- break;
-
- case OBJ_TAG:
- ewah_iterator_init(&it, bitmap_git->tags);
- break;
-
- default:
- return 0;
- }
+ init_type_iterator(&it, bitmap_git, type);
while (i < objects->word_alloc && ewah_iterator_next(&filter, &it)) {
eword_t word = objects->words[i++] & filter;