midx: replace `get_midx_rev_filename()` with a generic helper

Commit f894081deae (pack-revindex: read multi-pack reverse indexes, 2021-03-30) introduced the `get_midx_rev_filename()` helper (later modified by commit 60980aed786 (midx.c: write MIDX filenames to strbuf, 2021-10-26)). This function returns the location of the classic ".rev" files we used to write for MIDXs (prior to 95e8383bac1 (midx.c: make changing the preferred pack safe, 2022-01-25)), which is always of the form: $GIT_DIR/objects/pack/multi-pack-index-$HASH.rev Replace this function with a generic helper that populates a strbuf with the above form, replacing the ".rev" extension with a caller-provided argument. This will allow us to remove a similarly-defined function in the pack-bitmap code (used to determine the location of a MIDX .bitmap file) by reimplementing it in terms of `get_midx_filename_ext()`. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed May 29, 2024 at 18:55 UTC defba632c1e07eed360a8ba23df9103bbd1b7f9e
3 files changed +13 -6
midx.c
+6 -4
@@ -25,13 +25,15 @@ const unsigned char *get_midx_checksum(struct multi_pack_index *m)
25
26 void get_midx_filename(struct strbuf *out, const char *object_dir)
27 {
28 - strbuf_addf(out, "%s/pack/multi-pack-index", object_dir);
28 + get_midx_filename_ext(out, object_dir, NULL, NULL);
29 }
30
31 -void get_midx_rev_filename(struct strbuf *out, struct multi_pack_index *m)
31 +void get_midx_filename_ext(struct strbuf *out, const char *object_dir,
32 + const unsigned char *hash, const char *ext)
33 {
33 - get_midx_filename(out, m->object_dir);
34 - strbuf_addf(out, "-%s.rev", hash_to_hex(get_midx_checksum(m)));
34 + strbuf_addf(out, "%s/pack/multi-pack-index", object_dir);
35 + if (ext)
36 + strbuf_addf(out, "-%s.%s", hash_to_hex(hash), ext);
37 }
38
39 static int midx_read_oid_fanout(const unsigned char *chunk_start,
midx.h
+5 -1
@@ -74,9 +74,13 @@ struct multi_pack_index {
74 #define MIDX_WRITE_BITMAP_HASH_CACHE (1 << 3)
75 #define MIDX_WRITE_BITMAP_LOOKUP_TABLE (1 << 4)
76
77 +#define MIDX_EXT_REV "rev"
78 +#define MIDX_EXT_BITMAP "bitmap"
79 +
80 const unsigned char *get_midx_checksum(struct multi_pack_index *m);
81 void get_midx_filename(struct strbuf *out, const char *object_dir);
79 -void get_midx_rev_filename(struct strbuf *out, struct multi_pack_index *m);
82 +void get_midx_filename_ext(struct strbuf *out, const char *object_dir,
83 + const unsigned char *hash, const char *ext);
84
85 struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local);
86 int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id);
pack-revindex.c
+2 -1
@@ -381,7 +381,8 @@ int load_midx_revindex(struct multi_pack_index *m)
381 trace2_data_string("load_midx_revindex", the_repository,
382 "source", "rev");
383
384 - get_midx_rev_filename(&revindex_name, m);
384 + get_midx_filename_ext(&revindex_name, m->object_dir,
385 + get_midx_checksum(m), MIDX_EXT_REV);
386
387 ret = load_revindex_from_disk(revindex_name.buf,
388 m->num_objects,