From: Abhradeep Chakraborty <chakrabortyabhradeep79@xxxxxxxxx> Teach git to provide a way for users to enable/disable bitmap lookup table extension by providing a config option named 'writeBitmapLookupTable'. Default is true. Also add test to verify writting of lookup table. Co-Authored-by: Taylor Blau <me@xxxxxxxxxxxx> Signed-off-by: Abhradeep Chakraborty <chakrabortyabhradeep79@xxxxxxxxx> Mentored-by: Taylor Blau <me@xxxxxxxxxxxx> Co-Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@xxxxxxxxx> --- Documentation/config/pack.txt | 7 +++++++ builtin/multi-pack-index.c | 8 ++++++++ builtin/pack-objects.c | 10 +++++++++- midx.c | 3 +++ midx.h | 1 + pack-bitmap-write.c | 2 ++ t/t5310-pack-bitmaps.sh | 3 ++- t/t5326-multi-pack-bitmaps.sh | 13 +++++++++++++ 8 files changed, 45 insertions(+), 2 deletions(-) diff --git a/Documentation/config/pack.txt b/Documentation/config/pack.txt index ad7f73a1ead..6e1f454c4d6 100644 --- a/Documentation/config/pack.txt +++ b/Documentation/config/pack.txt @@ -164,6 +164,13 @@ When writing a multi-pack reachability bitmap, no new namehashes are computed; instead, any namehashes stored in an existing bitmap are permuted into their appropriate location when writing a new bitmap. +pack.writeBitmapLookupTable:: + When true, git will include a "lookup table" section in the + bitmap index (if one is written). This table is used to defer + loading individual bitmaps as late as possible. This can be + beneficial in repositories which have relatively large bitmap + indexes. Defaults to true. + pack.writeReverseIndex:: When true, git will write a corresponding .rev file (see: link:../technical/pack-format.html[Documentation/technical/pack-format.txt]) diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c index 5edbb7fe86e..3757616f09c 100644 --- a/builtin/multi-pack-index.c +++ b/builtin/multi-pack-index.c @@ -87,6 +87,13 @@ static int git_multi_pack_index_write_config(const char *var, const char *value, opts.flags &= ~MIDX_WRITE_BITMAP_HASH_CACHE; } + if (!strcmp(var, "pack.writebitmaplookuptable")) { + if (git_config_bool(var, value)) + opts.flags |= MIDX_WRITE_BITMAP_LOOKUP_TABLE; + else + opts.flags &= ~MIDX_WRITE_BITMAP_LOOKUP_TABLE; + } + /* * We should never make a fall-back call to 'git_default_config', since * this was already called in 'cmd_multi_pack_index()'. @@ -123,6 +130,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv) }; opts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE; + opts.flags |= MIDX_WRITE_BITMAP_LOOKUP_TABLE; git_config(git_multi_pack_index_write_config, NULL); diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 39e28cfcafc..d6a33fd486c 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -228,7 +228,7 @@ static enum { WRITE_BITMAP_QUIET, WRITE_BITMAP_TRUE, } write_bitmap_index; -static uint16_t write_bitmap_options = BITMAP_OPT_HASH_CACHE; +static uint16_t write_bitmap_options = BITMAP_OPT_HASH_CACHE | BITMAP_OPT_LOOKUP_TABLE; static int exclude_promisor_objects; @@ -3148,6 +3148,14 @@ static int git_pack_config(const char *k, const char *v, void *cb) else write_bitmap_options &= ~BITMAP_OPT_HASH_CACHE; } + + if (!strcmp(k, "pack.writebitmaplookuptable")) { + if (git_config_bool(k, v)) + write_bitmap_options |= BITMAP_OPT_LOOKUP_TABLE; + else + write_bitmap_options &= ~BITMAP_OPT_LOOKUP_TABLE; + } + if (!strcmp(k, "pack.usebitmaps")) { use_bitmap_index_default = git_config_bool(k, v); return 0; diff --git a/midx.c b/midx.c index 5f0dd386b02..9c26d04bfde 100644 --- a/midx.c +++ b/midx.c @@ -1072,6 +1072,9 @@ static int write_midx_bitmap(char *midx_name, unsigned char *midx_hash, if (flags & MIDX_WRITE_BITMAP_HASH_CACHE) options |= BITMAP_OPT_HASH_CACHE; + if (flags & MIDX_WRITE_BITMAP_LOOKUP_TABLE) + options |= BITMAP_OPT_LOOKUP_TABLE; + prepare_midx_packing_data(&pdata, ctx); commits = find_commits_for_midx_bitmap(&commits_nr, refs_snapshot, ctx); diff --git a/midx.h b/midx.h index 22e8e53288e..5578cd7b835 100644 --- a/midx.h +++ b/midx.h @@ -47,6 +47,7 @@ struct multi_pack_index { #define MIDX_WRITE_REV_INDEX (1 << 1) #define MIDX_WRITE_BITMAP (1 << 2) #define MIDX_WRITE_BITMAP_HASH_CACHE (1 << 3) +#define MIDX_WRITE_BITMAP_LOOKUP_TABLE (1 << 4) const unsigned char *get_midx_checksum(struct multi_pack_index *m); void get_midx_filename(struct strbuf *out, const char *object_dir); diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c index 899a4a941e1..79be0cf80e6 100644 --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@ -713,6 +713,7 @@ static void write_lookup_table(struct hashfile *f, for (i = 0; i < writer.selected_nr; i++) table_inv[table[i]] = i; + trace2_region_enter("pack-bitmap-write", "writing_lookup_table", the_repository); for (i = 0; i < writer.selected_nr; i++) { struct bitmapped_commit *selected = &writer.selected[table[i]]; uint32_t xor_offset = selected->xor_offset; @@ -725,6 +726,7 @@ static void write_lookup_table(struct hashfile *f, free(table); free(table_inv); + trace2_region_leave("pack-bitmap-write", "writing_lookup_table", the_repository); } static void write_hash_cache(struct hashfile *f, diff --git a/t/t5310-pack-bitmaps.sh b/t/t5310-pack-bitmaps.sh index f775fc1ce69..c669ed959e9 100755 --- a/t/t5310-pack-bitmaps.sh +++ b/t/t5310-pack-bitmaps.sh @@ -38,7 +38,8 @@ test_expect_success 'full repack creates bitmaps' ' ls .git/objects/pack/ | grep bitmap >output && test_line_count = 1 output && grep "\"key\":\"num_selected_commits\",\"value\":\"106\"" trace && - grep "\"key\":\"num_maximal_commits\",\"value\":\"107\"" trace + grep "\"key\":\"num_maximal_commits\",\"value\":\"107\"" trace && + grep "\"label\":\"writing_lookup_table\"" trace ' basic_bitmap_tests diff --git a/t/t5326-multi-pack-bitmaps.sh b/t/t5326-multi-pack-bitmaps.sh index 4fe57414c13..43be49617b8 100755 --- a/t/t5326-multi-pack-bitmaps.sh +++ b/t/t5326-multi-pack-bitmaps.sh @@ -307,4 +307,17 @@ test_expect_success 'graceful fallback when missing reverse index' ' ) ' +test_expect_success 'multi-pack-index write writes lookup table if enabled' ' + rm -fr repo && + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + test_commit base && + git repack -ad && + GIT_TRACE2_EVENT="$(pwd)/trace" \ + git multi-pack-index write --bitmap && + grep "\"label\":\"writing_lookup_table\"" trace + ) +' test_done -- gitgitgadget