Skip to content

Commit 22cc754

Browse files
pks-tgitster
authored andcommitted
pack-bitmap: expose function to iterate over bitmapped objects
Expose a function that allows the caller to iterate over all bitmapped objects of a specific type. This mechanism allows us to use the object type-specific bitmaps to enumerate all objects of that type without having to scan through a complete packfile. This functionality will be used in a subsequent commit. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a7c0f5c commit 22cc754

File tree

5 files changed

+57
-29
lines changed

5 files changed

+57
-29
lines changed

builtin/pack-objects.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,8 @@ static int add_object_entry(const struct object_id *oid, enum object_type type,
17351735
static int add_object_entry_from_bitmap(const struct object_id *oid,
17361736
enum object_type type,
17371737
int flags UNUSED, uint32_t name_hash,
1738-
struct packed_git *pack, off_t offset)
1738+
struct packed_git *pack, off_t offset,
1739+
void *payload UNUSED)
17391740
{
17401741
display_progress(progress_state, ++nr_seen);
17411742

builtin/rev-list.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ static int show_object_fast(
429429
int exclude UNUSED,
430430
uint32_t name_hash UNUSED,
431431
struct packed_git *found_pack UNUSED,
432-
off_t found_offset UNUSED)
432+
off_t found_offset UNUSED,
433+
void *payload UNUSED)
433434
{
434435
fprintf(stdout, "%s\n", oid_to_hex(oid));
435436
return 1;

pack-bitmap.c

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,50 +1509,45 @@ static void show_extended_objects(struct bitmap_index *bitmap_git,
15091509
(obj->type == OBJ_TAG && !revs->tag_objects))
15101510
continue;
15111511

1512-
show_reach(&obj->oid, obj->type, 0, eindex->hashes[i], NULL, 0);
1512+
show_reach(&obj->oid, obj->type, 0, eindex->hashes[i], NULL, 0, NULL);
15131513
}
15141514
}
15151515

1516-
static void init_type_iterator(struct ewah_iterator *it,
1517-
struct bitmap_index *bitmap_git,
1518-
enum object_type type)
1516+
static struct ewah_bitmap *ewah_for_type(struct bitmap_index *bitmap_git,
1517+
enum object_type type)
15191518
{
15201519
switch (type) {
15211520
case OBJ_COMMIT:
1522-
ewah_iterator_init(it, bitmap_git->commits);
1523-
break;
1524-
1521+
return bitmap_git->commits;
15251522
case OBJ_TREE:
1526-
ewah_iterator_init(it, bitmap_git->trees);
1527-
break;
1528-
1523+
return bitmap_git->trees;
15291524
case OBJ_BLOB:
1530-
ewah_iterator_init(it, bitmap_git->blobs);
1531-
break;
1532-
1525+
return bitmap_git->blobs;
15331526
case OBJ_TAG:
1534-
ewah_iterator_init(it, bitmap_git->tags);
1535-
break;
1536-
1527+
return bitmap_git->tags;
15371528
default:
15381529
BUG("object type %d not stored by bitmap type index", type);
1539-
break;
15401530
}
15411531
}
15421532

1543-
static void show_objects_for_type(
1544-
struct bitmap_index *bitmap_git,
1545-
enum object_type object_type,
1546-
show_reachable_fn show_reach)
1533+
static void init_type_iterator(struct ewah_iterator *it,
1534+
struct bitmap_index *bitmap_git,
1535+
enum object_type type)
1536+
{
1537+
ewah_iterator_init(it, ewah_for_type(bitmap_git, type));
1538+
}
1539+
1540+
static void for_each_bitmapped_object_internal(struct bitmap_index *bitmap_git,
1541+
struct bitmap *objects,
1542+
enum object_type object_type,
1543+
show_reachable_fn show_reach,
1544+
void *payload)
15471545
{
15481546
size_t i = 0;
15491547
uint32_t offset;
1550-
15511548
struct ewah_iterator it;
15521549
eword_t filter;
15531550

1554-
struct bitmap *objects = bitmap_git->result;
1555-
15561551
init_type_iterator(&it, bitmap_git, object_type);
15571552

15581553
for (i = 0; i < objects->word_alloc &&
@@ -1595,11 +1590,31 @@ static void show_objects_for_type(
15951590
if (bitmap_git->hashes)
15961591
hash = get_be32(bitmap_git->hashes + index_pos);
15971592

1598-
show_reach(&oid, object_type, 0, hash, pack, ofs);
1593+
show_reach(&oid, object_type, 0, hash, pack, ofs, payload);
15991594
}
16001595
}
16011596
}
16021597

1598+
static void show_objects_for_type(
1599+
struct bitmap_index *bitmap_git,
1600+
enum object_type object_type,
1601+
show_reachable_fn show_reach)
1602+
{
1603+
for_each_bitmapped_object_internal(bitmap_git, bitmap_git->result,
1604+
object_type, show_reach, NULL);
1605+
}
1606+
1607+
void for_each_bitmapped_object(struct bitmap_index *bitmap_git,
1608+
enum object_type object_type,
1609+
show_reachable_fn show_reach,
1610+
void *payload)
1611+
{
1612+
struct bitmap *bitmap = ewah_to_bitmap(ewah_for_type(bitmap_git, object_type));
1613+
for_each_bitmapped_object_internal(bitmap_git, bitmap,
1614+
object_type, show_reach, payload);
1615+
bitmap_free(bitmap);
1616+
}
1617+
16031618
static int in_bitmapped_pack(struct bitmap_index *bitmap_git,
16041619
struct object_list *roots)
16051620
{

pack-bitmap.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ typedef int (*show_reachable_fn)(
5050
int flags,
5151
uint32_t hash,
5252
struct packed_git *found_pack,
53-
off_t found_offset);
53+
off_t found_offset,
54+
void *payload);
5455

5556
struct bitmap_index;
5657

@@ -78,6 +79,15 @@ int test_bitmap_pseudo_merges(struct repository *r);
7879
int test_bitmap_pseudo_merge_commits(struct repository *r, uint32_t n);
7980
int test_bitmap_pseudo_merge_objects(struct repository *r, uint32_t n);
8081

82+
/*
83+
* Iterate through all bitmapped objects of the given type and execute the
84+
* `show_reach` for each of them.
85+
*/
86+
void for_each_bitmapped_object(struct bitmap_index *bitmap_git,
87+
enum object_type object_type,
88+
show_reachable_fn show_reach,
89+
void *payload);
90+
8191
#define GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL \
8292
"GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL"
8393

reachable.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ static int mark_object_seen(const struct object_id *oid,
337337
int exclude UNUSED,
338338
uint32_t name_hash UNUSED,
339339
struct packed_git *found_pack UNUSED,
340-
off_t found_offset UNUSED)
340+
off_t found_offset UNUSED,
341+
void *payload UNUSED)
341342
{
342343
struct object *obj = lookup_object_by_type(the_repository, oid, type);
343344
if (!obj)

0 commit comments

Comments
 (0)