Skip to content

Commit 9567a67

Browse files
committed
Merge branch 'tb/midx-write-propagate-namehash'
"git multi-pack-index write --bitmap" learns to propagate the hashcache from original bitmap to resulting bitmap. * tb/midx-write-propagate-namehash: t5326: test propagating hashcache values p5326: generate pack bitmaps before writing the MIDX bitmap p5326: don't set core.multiPackIndex unnecessarily p5326: create missing 'perf-tag' tag midx.c: respect 'pack.writeBitmapHashcache' when writing bitmaps pack-bitmap.c: propagate namehash values from existing bitmaps t/helper/test-bitmap.c: add 'dump-hashes' mode
2 parents 106298f + 54156af commit 9567a67

File tree

9 files changed

+118
-11
lines changed

9 files changed

+118
-11
lines changed

Documentation/config/pack.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ pack.writeBitmapHashCache::
159159
between an older, bitmapped pack and objects that have been
160160
pushed since the last gc). The downside is that it consumes 4
161161
bytes per object of disk space. Defaults to true.
162+
+
163+
When writing a multi-pack reachability bitmap, no new namehashes are
164+
computed; instead, any namehashes stored in an existing bitmap are
165+
permuted into their appropriate location when writing a new bitmap.
162166

163167
pack.writeReverseIndex::
164168
When true, git will write a corresponding .rev file (see:

builtin/multi-pack-index.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@ static struct option *add_common_options(struct option *prev)
6060
return parse_options_concat(common_opts, prev);
6161
}
6262

63+
static int git_multi_pack_index_write_config(const char *var, const char *value,
64+
void *cb)
65+
{
66+
if (!strcmp(var, "pack.writebitmaphashcache")) {
67+
if (git_config_bool(var, value))
68+
opts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;
69+
else
70+
opts.flags &= ~MIDX_WRITE_BITMAP_HASH_CACHE;
71+
}
72+
73+
/*
74+
* We should never make a fall-back call to 'git_default_config', since
75+
* this was already called in 'cmd_multi_pack_index()'.
76+
*/
77+
return 0;
78+
}
79+
6380
static int cmd_multi_pack_index_write(int argc, const char **argv)
6481
{
6582
struct option *options;
@@ -74,6 +91,10 @@ static int cmd_multi_pack_index_write(int argc, const char **argv)
7491
OPT_END(),
7592
};
7693

94+
opts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;
95+
96+
git_config(git_multi_pack_index_write_config, NULL);
97+
7798
options = add_common_options(builtin_multi_pack_index_write_options);
7899

79100
trace2_cmd_mode(argv[0]);

midx.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,9 +993,13 @@ static int write_midx_bitmap(char *midx_name, unsigned char *midx_hash,
993993
struct pack_idx_entry **index;
994994
struct commit **commits = NULL;
995995
uint32_t i, commits_nr;
996+
uint16_t options = 0;
996997
char *bitmap_name = xstrfmt("%s-%s.bitmap", midx_name, hash_to_hex(midx_hash));
997998
int ret;
998999

1000+
if (flags & MIDX_WRITE_BITMAP_HASH_CACHE)
1001+
options |= BITMAP_OPT_HASH_CACHE;
1002+
9991003
prepare_midx_packing_data(&pdata, ctx);
10001004

10011005
commits = find_commits_for_midx_bitmap(&commits_nr, ctx);
@@ -1034,7 +1038,7 @@ static int write_midx_bitmap(char *midx_name, unsigned char *midx_hash,
10341038
goto cleanup;
10351039

10361040
bitmap_writer_set_checksum(midx_hash);
1037-
bitmap_writer_finish(index, pdata.nr_objects, bitmap_name, 0);
1041+
bitmap_writer_finish(index, pdata.nr_objects, bitmap_name, options);
10381042

10391043
cleanup:
10401044
free(index);

midx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct multi_pack_index {
4444
#define MIDX_PROGRESS (1 << 0)
4545
#define MIDX_WRITE_REV_INDEX (1 << 1)
4646
#define MIDX_WRITE_BITMAP (1 << 2)
47+
#define MIDX_WRITE_BITMAP_HASH_CACHE (1 << 3)
4748

4849
const unsigned char *get_midx_checksum(struct multi_pack_index *m);
4950
char *get_midx_filename(const char *object_dir);

pack-bitmap.c

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,6 +1742,33 @@ int test_bitmap_commits(struct repository *r)
17421742
return 0;
17431743
}
17441744

1745+
int test_bitmap_hashes(struct repository *r)
1746+
{
1747+
struct bitmap_index *bitmap_git = prepare_bitmap_git(r);
1748+
struct object_id oid;
1749+
uint32_t i, index_pos;
1750+
1751+
if (!bitmap_git->hashes)
1752+
goto cleanup;
1753+
1754+
for (i = 0; i < bitmap_num_objects(bitmap_git); i++) {
1755+
if (bitmap_is_midx(bitmap_git))
1756+
index_pos = pack_pos_to_midx(bitmap_git->midx, i);
1757+
else
1758+
index_pos = pack_pos_to_index(bitmap_git->pack, i);
1759+
1760+
nth_bitmap_object_oid(bitmap_git, &oid, index_pos);
1761+
1762+
printf("%s %"PRIu32"\n",
1763+
oid_to_hex(&oid), get_be32(bitmap_git->hashes + index_pos));
1764+
}
1765+
1766+
cleanup:
1767+
free_bitmap_index(bitmap_git);
1768+
1769+
return 0;
1770+
}
1771+
17451772
int rebuild_bitmap(const uint32_t *reposition,
17461773
struct ewah_bitmap *source,
17471774
struct bitmap *dest)
@@ -1791,18 +1818,20 @@ uint32_t *create_bitmap_mapping(struct bitmap_index *bitmap_git,
17911818
for (i = 0; i < num_objects; ++i) {
17921819
struct object_id oid;
17931820
struct object_entry *oe;
1821+
uint32_t index_pos;
17941822

17951823
if (bitmap_is_midx(bitmap_git))
1796-
nth_midxed_object_oid(&oid,
1797-
bitmap_git->midx,
1798-
pack_pos_to_midx(bitmap_git->midx, i));
1824+
index_pos = pack_pos_to_midx(bitmap_git->midx, i);
17991825
else
1800-
nth_packed_object_id(&oid, bitmap_git->pack,
1801-
pack_pos_to_index(bitmap_git->pack, i));
1826+
index_pos = pack_pos_to_index(bitmap_git->pack, i);
1827+
nth_bitmap_object_oid(bitmap_git, &oid, index_pos);
18021828
oe = packlist_find(mapping, &oid);
18031829

1804-
if (oe)
1830+
if (oe) {
18051831
reposition[i] = oe_in_pack_pos(mapping, oe) + 1;
1832+
if (bitmap_git->hashes && !oe->hash)
1833+
oe->hash = get_be32(bitmap_git->hashes + index_pos);
1834+
}
18061835
}
18071836

18081837
return reposition;

pack-bitmap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ void traverse_bitmap_commit_list(struct bitmap_index *,
5252
show_reachable_fn show_reachable);
5353
void test_bitmap_walk(struct rev_info *revs);
5454
int test_bitmap_commits(struct repository *r);
55+
int test_bitmap_hashes(struct repository *r);
5556
struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
5657
struct list_objects_filter_options *filter,
5758
int filter_provided_objects);

t/helper/test-bitmap.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ static int bitmap_list_commits(void)
77
return test_bitmap_commits(the_repository);
88
}
99

10+
static int bitmap_dump_hashes(void)
11+
{
12+
return test_bitmap_hashes(the_repository);
13+
}
14+
1015
int cmd__bitmap(int argc, const char **argv)
1116
{
1217
setup_git_directory();
@@ -16,9 +21,12 @@ int cmd__bitmap(int argc, const char **argv)
1621

1722
if (!strcmp(argv[1], "list-commits"))
1823
return bitmap_list_commits();
24+
if (!strcmp(argv[1], "dump-hashes"))
25+
return bitmap_dump_hashes();
1926

2027
usage:
21-
usage("\ttest-tool bitmap list-commits");
28+
usage("\ttest-tool bitmap list-commits\n"
29+
"\ttest-tool bitmap dump-hashes");
2230

2331
return -1;
2432
}

t/perf/p5326-multi-pack-bitmaps.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,24 @@ test_description='Tests performance using midx bitmaps'
66

77
test_perf_large_repo
88

9-
test_expect_success 'enable multi-pack index' '
10-
git config core.multiPackIndex true
9+
# we need to create the tag up front such that it is covered by the repack and
10+
# thus by generated bitmaps.
11+
test_expect_success 'create tags' '
12+
git tag --message="tag pointing to HEAD" perf-tag HEAD
13+
'
14+
15+
test_expect_success 'start with bitmapped pack' '
16+
git repack -adb
1117
'
1218

1319
test_perf 'setup multi-pack index' '
14-
git repack -ad &&
1520
git multi-pack-index write --bitmap
1621
'
1722

23+
test_expect_success 'drop pack bitmap' '
24+
rm -f .git/objects/pack/pack-*.bitmap
25+
'
26+
1827
test_full_bitmap
1928

2029
test_expect_success 'create partial bitmap state' '

t/t5326-multi-pack-bitmaps.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,34 @@ test_expect_success 'pack.preferBitmapTips' '
283283
)
284284
'
285285

286+
test_expect_success 'hash-cache values are propagated from pack bitmaps' '
287+
rm -fr repo &&
288+
git init repo &&
289+
test_when_finished "rm -fr repo" &&
290+
(
291+
cd repo &&
292+
293+
test_commit base &&
294+
test_commit base2 &&
295+
git repack -adb &&
296+
297+
test-tool bitmap dump-hashes >pack.raw &&
298+
test_file_not_empty pack.raw &&
299+
sort pack.raw >pack.hashes &&
300+
301+
test_commit new &&
302+
git repack &&
303+
git multi-pack-index write --bitmap &&
304+
305+
test-tool bitmap dump-hashes >midx.raw &&
306+
sort midx.raw >midx.hashes &&
307+
308+
# ensure that every namehash in the pack bitmap can be found in
309+
# the midx bitmap (i.e., that there are no oid-namehash pairs
310+
# unique to the pack bitmap).
311+
comm -23 pack.hashes midx.hashes >dropped.hashes &&
312+
test_must_be_empty dropped.hashes
313+
)
314+
'
315+
286316
test_done

0 commit comments

Comments
 (0)