Skip to content

Commit 7b3c8e9

Browse files
ttaylorrpeff
authored andcommitted
pack-bitmap: drop --unpacked non-commit objects from results
When performing revision queries with `--objects` and `--use-bitmap-index`, the output may incorrectly contain objects which are packed, even when the `--unpacked` option is given. This affects traversals, but also other querying operations, like `--count`, `--disk-usage`, etc. Like in the previous commit, the fix is to exclude those objects from the result set before they are shown to the user (or, in this case, before the bitmap containing the result of the traversal is enumerated and its objects listed). This is performed by a new function in pack-bitmap.c, called `filter_packed_objects_from_bitmap()`. Note that we do not have to inspect individual bits in the result bitmap, since we know that the first N (where N is the number of objects in the bitmap's pack/MIDX) bits correspond to objects which packed by definition. In other words, for an object to have a bitmap position (not in the extended index), it must appear in either the bitmap's pack or one of the packs in its MIDX. This presents an appealing optimization to us, which is that we can simply memset() the corresponding number of `eword_t`'s to zero, provided that we handle any objects which spill into the next word (but don't occupy all 64 bits of the word itself). We only have to handle objects in the bitmap's extended index. These objects may (or may not) appear in one or more pack(s). Since these objects are known to not appear in either the bitmap's MIDX or pack, they may be stored as loose, appear in other pack(s), or both. Before returning a bitmap containing the result of the traversal back to the caller, drop any bits from the extended index which appear in one or more packs. This implements the correct behavior for rev-list operations which use the bitmap index to compute their result. Co-authored-by: Jeff King <peff@peff.net> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 4263f92 commit 7b3c8e9

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

pack-bitmap.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,30 @@ static int can_filter_bitmap(struct list_objects_filter_options *filter)
16651665
return !filter_bitmap(NULL, NULL, NULL, filter);
16661666
}
16671667

1668+
1669+
static void filter_packed_objects_from_bitmap(struct bitmap_index *bitmap_git,
1670+
struct bitmap *result)
1671+
{
1672+
struct eindex *eindex = &bitmap_git->ext_index;
1673+
uint32_t objects_nr;
1674+
size_t i, pos;
1675+
1676+
objects_nr = bitmap_num_objects(bitmap_git);
1677+
pos = objects_nr / BITS_IN_EWORD;
1678+
1679+
if (pos > result->word_alloc)
1680+
pos = result->word_alloc;
1681+
1682+
memset(result->words, 0x00, sizeof(eword_t) * pos);
1683+
for (i = pos * BITS_IN_EWORD; i < objects_nr; i++)
1684+
bitmap_unset(result, i);
1685+
1686+
for (i = 0; i < eindex->count; ++i) {
1687+
if (has_object_pack(&eindex->objects[i]->oid))
1688+
bitmap_unset(result, objects_nr + i);
1689+
}
1690+
}
1691+
16681692
struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
16691693
int filter_provided_objects)
16701694
{
@@ -1787,6 +1811,9 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
17871811
wants_bitmap,
17881812
&revs->filter);
17891813

1814+
if (revs->unpacked)
1815+
filter_packed_objects_from_bitmap(bitmap_git, wants_bitmap);
1816+
17901817
bitmap_git->result = wants_bitmap;
17911818
bitmap_git->haves = haves_bitmap;
17921819

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,17 @@ test_expect_success 'combine filter with --filter-provided-objects' '
141141
done <objects
142142
'
143143

144+
test_expect_success 'bitmap traversal with --unpacked' '
145+
git repack -adb &&
146+
test_commit unpacked &&
147+
148+
git rev-list --objects --no-object-names unpacked^.. >expect.raw &&
149+
sort expect.raw >expect &&
150+
151+
git rev-list --use-bitmap-index --objects --all --unpacked >actual.raw &&
152+
sort actual.raw >actual &&
153+
154+
test_cmp expect actual
155+
'
156+
144157
test_done

t/t6115-rev-list-du.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ check_du HEAD
4848
check_du --objects HEAD
4949
check_du --objects HEAD^..HEAD
5050

51+
test_expect_success 'setup for --unpacked tests' '
52+
git repack -adb &&
53+
test_commit unpacked
54+
'
55+
56+
check_du --all --objects --unpacked
57+
5158
# As mentioned above, don't use hardcode sizes as actual size, but use the
5259
# output from git cat-file.
5360
test_expect_success 'rev-list --disk-usage=human' '

0 commit comments

Comments
 (0)