Skip to content

Commit defba63

Browse files
ttaylorrgitster
authored andcommitted
midx: replace get_midx_rev_filename() with a generic helper
Commit f894081 (pack-revindex: read multi-pack reverse indexes, 2021-03-30) introduced the `get_midx_rev_filename()` helper (later modified by commit 60980ae (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 95e8383 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d6a8c58 commit defba63

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

midx.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ const unsigned char *get_midx_checksum(struct multi_pack_index *m)
2525

2626
void get_midx_filename(struct strbuf *out, const char *object_dir)
2727
{
28-
strbuf_addf(out, "%s/pack/multi-pack-index", object_dir);
28+
get_midx_filename_ext(out, object_dir, NULL, NULL);
2929
}
3030

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)
3233
{
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);
3537
}
3638

3739
static int midx_read_oid_fanout(const unsigned char *chunk_start,

midx.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,13 @@ struct multi_pack_index {
7474
#define MIDX_WRITE_BITMAP_HASH_CACHE (1 << 3)
7575
#define MIDX_WRITE_BITMAP_LOOKUP_TABLE (1 << 4)
7676

77+
#define MIDX_EXT_REV "rev"
78+
#define MIDX_EXT_BITMAP "bitmap"
79+
7780
const unsigned char *get_midx_checksum(struct multi_pack_index *m);
7881
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);
8084

8185
struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local);
8286
int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id);

pack-revindex.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ int load_midx_revindex(struct multi_pack_index *m)
381381
trace2_data_string("load_midx_revindex", the_repository,
382382
"source", "rev");
383383

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);
385386

386387
ret = load_revindex_from_disk(revindex_name.buf,
387388
m->num_objects,

0 commit comments

Comments
 (0)