midx.c: respect 'pack.writeBitmapHashcache' when writing bitmaps

In the previous commit, the bitmap writing code learned to propagate values from an existing hash-cache extension into the bitmap that it is writing. Now that that functionality exists, let's expose it by teaching the 'git multi-pack-index' builtin to respect the `pack.writeBitmapHashCache` option so that the hash-cache may be written at all. Two minor points worth noting here: - The 'git multi-pack-index write' sub-command didn't previously read any configuration (instead this is handled in the base command). A separate handler is added here to respect this write-specific config option. - I briefly considered adding a 'bitmap_flags' field to the static options struct, but decided against it since it would require plumbing through a new parameter to the write_midx_file() function. Instead, a new MIDX-specific flag is added, which is translated to the corresponding bitmap one. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Sep 14, 2021 at 18:06 UTC caca3c9f07f90645e32c284c88c379109abf59be
4 files changed +31 -1
Documentation/config/pack.txt
+4
@@ -159,6 +159,10 @@ pack.writeBitmapHashCache::
159 between an older, bitmapped pack and objects that have been
160 pushed since the last gc). The downside is that it consumes 4
161 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.
166
167 pack.writeReverseIndex::
168 When true, git will write a corresponding .rev file (see:
builtin/multi-pack-index.c
+21
@@ -61,6 +61,23 @@ static struct option *add_common_options(struct option *prev)
61 return parse_options_concat(common_opts, prev);
62 }
63
64 +static int git_multi_pack_index_write_config(const char *var, const char *value,
65 + void *cb)
66 +{
67 + if (!strcmp(var, "pack.writebitmaphashcache")) {
68 + if (git_config_bool(var, value))
69 + opts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;
70 + else
71 + opts.flags &= ~MIDX_WRITE_BITMAP_HASH_CACHE;
72 + }
73 +
74 + /*
75 + * We should never make a fall-back call to 'git_default_config', since
76 + * this was already called in 'cmd_multi_pack_index()'.
77 + */
78 + return 0;
79 +}
80 +
81 static int cmd_multi_pack_index_write(int argc, const char **argv)
82 {
83 struct option *options;
@@ -73,6 +90,10 @@ static int cmd_multi_pack_index_write(int argc, const char **argv)
90 OPT_END(),
91 };
92
93 + opts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;
94 +
95 + git_config(git_multi_pack_index_write_config, NULL);
96 +
97 options = add_common_options(builtin_multi_pack_index_write_options);
98
99 trace2_cmd_mode(argv[0]);
midx.c
+5 -1
@@ -1008,9 +1008,13 @@ static int write_midx_bitmap(char *midx_name, unsigned char *midx_hash,
1008 struct pack_idx_entry **index;
1009 struct commit **commits = NULL;
1010 uint32_t i, commits_nr;
1011 + uint16_t options = 0;
1012 char *bitmap_name = xstrfmt("%s-%s.bitmap", midx_name, hash_to_hex(midx_hash));
1013 int ret;
1014
1015 + if (flags & MIDX_WRITE_BITMAP_HASH_CACHE)
1016 + options |= BITMAP_OPT_HASH_CACHE;
1017 +
1018 prepare_midx_packing_data(&pdata, ctx);
1019
1020 commits = find_commits_for_midx_bitmap(&commits_nr, ctx);
@@ -1049,7 +1053,7 @@ static int write_midx_bitmap(char *midx_name, unsigned char *midx_hash,
1053 goto cleanup;
1054
1055 bitmap_writer_set_checksum(midx_hash);
1052 - bitmap_writer_finish(index, pdata.nr_objects, bitmap_name, 0);
1056 + bitmap_writer_finish(index, pdata.nr_objects, bitmap_name, options);
1057
1058 cleanup:
1059 free(index);
midx.h
+1
@@ -44,6 +44,7 @@ struct multi_pack_index {
44 #define MIDX_PROGRESS (1 << 0)
45 #define MIDX_WRITE_REV_INDEX (1 << 1)
46 #define MIDX_WRITE_BITMAP (1 << 2)
47 +#define MIDX_WRITE_BITMAP_HASH_CACHE (1 << 3)
48
49 const unsigned char *get_midx_checksum(struct multi_pack_index *m);
50 char *get_midx_filename(const char *object_dir);