]> git.ipfire.org Git - thirdparty/git.git/commitdiff
midx.c: respect 'pack.writeBitmapHashcache' when writing bitmaps
authorTaylor Blau <me@ttaylorr.com>
Tue, 14 Sep 2021 22:06:06 +0000 (18:06 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 14 Sep 2021 23:34:18 +0000 (16:34 -0700)
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>
Documentation/config/pack.txt
builtin/multi-pack-index.c
midx.c
midx.h

index 763f7af7c4d742423320414c7c3f1fb9d8451cf9..ad7f73a1eade701492ae7b773cc5bb5dc37e5053 100644 (file)
@@ -159,6 +159,10 @@ pack.writeBitmapHashCache::
        between an older, bitmapped pack and objects that have been
        pushed since the last gc). The downside is that it consumes 4
        bytes per object of disk space. Defaults to true.
++
+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.writeReverseIndex::
        When true, git will write a corresponding .rev file (see:
index 73c0113b48b9a435173c62d5612c0db1afb3b184..578ffea6e8c2ea37625b1282736ac01c3cc4496d 100644 (file)
@@ -61,6 +61,23 @@ static struct option *add_common_options(struct option *prev)
        return parse_options_concat(common_opts, prev);
 }
 
+static int git_multi_pack_index_write_config(const char *var, const char *value,
+                                            void *cb)
+{
+       if (!strcmp(var, "pack.writebitmaphashcache")) {
+               if (git_config_bool(var, value))
+                       opts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;
+               else
+                       opts.flags &= ~MIDX_WRITE_BITMAP_HASH_CACHE;
+       }
+
+       /*
+        * We should never make a fall-back call to 'git_default_config', since
+        * this was already called in 'cmd_multi_pack_index()'.
+        */
+       return 0;
+}
+
 static int cmd_multi_pack_index_write(int argc, const char **argv)
 {
        struct option *options;
@@ -73,6 +90,10 @@ static int cmd_multi_pack_index_write(int argc, const char **argv)
                OPT_END(),
        };
 
+       opts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;
+
+       git_config(git_multi_pack_index_write_config, NULL);
+
        options = add_common_options(builtin_multi_pack_index_write_options);
 
        trace2_cmd_mode(argv[0]);
diff --git a/midx.c b/midx.c
index 864034a6ade5fdc61f7287227767de01b31b0267..38c8600458c699e8353e9542e118b52328d9ea62 100644 (file)
--- a/midx.c
+++ b/midx.c
@@ -1008,9 +1008,13 @@ static int write_midx_bitmap(char *midx_name, unsigned char *midx_hash,
        struct pack_idx_entry **index;
        struct commit **commits = NULL;
        uint32_t i, commits_nr;
+       uint16_t options = 0;
        char *bitmap_name = xstrfmt("%s-%s.bitmap", midx_name, hash_to_hex(midx_hash));
        int ret;
 
+       if (flags & MIDX_WRITE_BITMAP_HASH_CACHE)
+               options |= BITMAP_OPT_HASH_CACHE;
+
        prepare_midx_packing_data(&pdata, ctx);
 
        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,
                goto cleanup;
 
        bitmap_writer_set_checksum(midx_hash);
-       bitmap_writer_finish(index, pdata.nr_objects, bitmap_name, 0);
+       bitmap_writer_finish(index, pdata.nr_objects, bitmap_name, options);
 
 cleanup:
        free(index);
diff --git a/midx.h b/midx.h
index aa3da557bb0ae974f3e686c3f0f018161d854651..541d9ac728d59a6eeaa17df9d92e743a43bbd3fc 100644 (file)
--- a/midx.h
+++ b/midx.h
@@ -44,6 +44,7 @@ struct multi_pack_index {
 #define MIDX_PROGRESS     (1 << 0)
 #define MIDX_WRITE_REV_INDEX (1 << 1)
 #define MIDX_WRITE_BITMAP (1 << 2)
+#define MIDX_WRITE_BITMAP_HASH_CACHE (1 << 3)
 
 const unsigned char *get_midx_checksum(struct multi_pack_index *m);
 char *get_midx_filename(const char *object_dir);