midx: drop unused parameters from add_midx_to_chain()
When loading a chained midx, we build up an array of hashes, one per layer of the chain. But since the chain is also represented by the linked list of multi_pack_index structs, nobody actually reads this array. We pass it to add_midx_to_chain(), but the parameters are completely ignored. So we can drop those unused parameters. And then we can see that its sole caller, load_midx_chain_fd_st(), only cares about one layer hash at a time (for parsing each line and feeding it to the single-layer midx code). So we can replace the array with a single object_id on the stack. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Aug 13, 2024 at 01:02 UTC
1784522a1f3d35195c2c28137ed49f36caa5022e
1 file changed
+5
-9
midx.c
+5
-9
@@ -264,9 +264,7 @@ static int open_multi_pack_index_chain(const char *chain_file,
264
}
265
266
static int add_midx_to_chain(struct multi_pack_index *midx,
267
- struct multi_pack_index *midx_chain,
268
- struct object_id *oids,
269
- int n)
267
+ struct multi_pack_index *midx_chain)
268
{
269
if (midx_chain) {
270
if (unsigned_add_overflows(midx_chain->num_packs,
@@ -300,21 +298,20 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,
298
{
299
struct multi_pack_index *midx_chain = NULL;
300
struct strbuf buf = STRBUF_INIT;
303
- struct object_id *layers = NULL;
301
int valid = 1;
302
uint32_t i, count;
303
FILE *fp = xfdopen(fd, "r");
304
305
count = st->st_size / (the_hash_algo->hexsz + 1);
309
- CALLOC_ARRAY(layers, count);
306
307
for (i = 0; i < count; i++) {
308
struct multi_pack_index *m;
309
+ struct object_id layer;
310
311
if (strbuf_getline_lf(&buf, fp) == EOF)
312
break;
313
317
- if (get_oid_hex(buf.buf, &layers[i])) {
314
+ if (get_oid_hex(buf.buf, &layer)) {
315
warning(_("invalid multi-pack-index chain: line '%s' "
316
"not a hash"),
317
buf.buf);
@@ -325,12 +322,12 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,
322
valid = 0;
323
324
strbuf_reset(&buf);
328
- get_split_midx_filename_ext(&buf, object_dir, layers[i].hash,
325
+ get_split_midx_filename_ext(&buf, object_dir, layer.hash,
326
MIDX_EXT_MIDX);
327
m = load_multi_pack_index_one(object_dir, buf.buf, local);
328
329
if (m) {
333
- if (add_midx_to_chain(m, midx_chain, layers, i)) {
330
+ if (add_midx_to_chain(m, midx_chain)) {
331
midx_chain = m;
332
valid = 1;
333
} else {
@@ -343,7 +340,6 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,
340
}
341
}
342
346
- free(layers);
343
fclose(fp);
344
strbuf_release(&buf);
345