Re: [PATCH v2 20/24] pack-bitmap: factor out 'bitmap_for_commit()'
- From
- Jonathan Tan <jonathantanmy@google.com>
- Date
- Dec 2, 2020, 07:17 UTC
- Message-ID
- <20201202071753.3468604-1-jonathantanmy@google.com>
- In-Reply-To
- <9928b3c7da33edd8d4beae006a74dd682daf5fa5.1605649533.git.me@ttaylorr.com>
Show 9 quoted lines
> +struct ewah_bitmap *bitmap_for_commit(struct bitmap_index *bitmap_git,
> + struct commit *commit)
> +{
> + khiter_t hash_pos = kh_get_oid_map(bitmap_git->bitmaps,
> + commit->object.oid);
> + if (hash_pos >= kh_end(bitmap_git->bitmaps))
> + return NULL;
> + return lookup_stored_bitmap(kh_value(bitmap_git->bitmaps, hash_pos));
> +}The new function.
Show 24 quoted lines
> static int add_to_include_set(struct bitmap_index *bitmap_git,
> struct include_data *data,
> - const struct object_id *oid,
> + struct commit *commit,
> int bitmap_pos)
> {
> - khiter_t hash_pos;
> + struct ewah_bitmap *partial;
>
> if (data->seen && bitmap_get(data->seen, bitmap_pos))
> return 0;
> @@ -476,10 +486,9 @@ static int add_to_include_set(struct bitmap_index *bitmap_git,
> if (bitmap_get(data->base, bitmap_pos))
> return 0;
>
> - hash_pos = kh_get_oid_map(bitmap_git->bitmaps, *oid);
> - if (hash_pos < kh_end(bitmap_git->bitmaps)) {
> - struct stored_bitmap *st = kh_value(bitmap_git->bitmaps, hash_pos);
> - bitmap_or_ewah(data->base, lookup_stored_bitmap(st));
> + partial = bitmap_for_commit(bitmap_git, commit);
> + if (partial) {
> + bitmap_or_ewah(data->base, partial);
> return 0;
> }A straightforward mechanical change. The function invocation replaces conversion from commit to oid (which is why add_to_include_set() now takes a struct commit * instead of a struct object_id *) and all the other deleted lines here.
Show 15 quoted lines
> @@ -1297,12 +1305,9 @@ void test_bitmap_walk(struct rev_info *revs)
> bitmap_git->version, bitmap_git->entry_count);
>
> root = revs->pending.objects[0].item;
> - pos = kh_get_oid_map(bitmap_git->bitmaps, root->oid);
> -
> - if (pos < kh_end(bitmap_git->bitmaps)) {
> - struct stored_bitmap *st = kh_value(bitmap_git->bitmaps, pos);
> - struct ewah_bitmap *bm = lookup_stored_bitmap(st);
> + bm = bitmap_for_commit(bitmap_git, (struct commit *)root);
>
> + if (bm) {
> fprintf(stderr, "Found bitmap for %s. %d bits / %08x checksum\n",
> oid_to_hex(&root->oid), (int)bm->bit_size, ewah_checksum(bm));
> Same here. LGTM.