{"thread":{"id":"61938","subject":"[PATCH] midx: drop unused parameters from add_midx_to_chain()","startedAt":"2024-08-13T05:02:18Z","lastAt":"2024-08-13T05:02:18Z","messageCount":1,"participants":["Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"500675","messageId":"20240813050216.GA394231@coredump.intra.peff.net","threadId":"61938","inReplyTo":null,"subject":"[PATCH] midx: drop unused parameters from add_midx_to_chain()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2024-08-13T05:02:16Z","receivedAt":"2024-08-13T05:02:18Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"When loading a chained midx, we build up an array of hashes, one per\nlayer of the chain. But since the chain is also represented by the\nlinked list of multi_pack_index structs, nobody actually reads this\narray. We pass it to add_midx_to_chain(), but the parameters are\ncompletely ignored.\n\nSo we can drop those unused parameters. And then we can see that its\nsole caller, load_midx_chain_fd_st(), only cares about one layer hash at a\ntime (for parsing each line and feeding it to the single-layer midx\ncode). So we can replace the array with a single object_id on the stack.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nThe tb/incremental-midx-part-1 topic hit 'next', so my unused-parameter\ntopic flagged this. Usually I just queue the annotations to send in a\nbatch, but this one made me think for a minute to make sure that it\nwasn't a bug (I think it's just a leftover from early development).\nIt should apply directly on top of what Junio has queued.\n\nI really need to polish up the remainder of those annotations and send\nthem in (I've been waiting a bit because there's a lot of flux around\nt/helper and unit-test migrations, which all need a lot of annotations).\nBut then we could notice this stuff in a more timely manner.\n\n midx.c | 14 +++++---------\n 1 file changed, 5 insertions(+), 9 deletions(-)\n\ndiff --git a/midx.c b/midx.c\nindex c867b2b6c2..ca98bfd7c6 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -264,9 +264,7 @@ static int open_multi_pack_index_chain(const char *chain_file,\n }\n \n static int add_midx_to_chain(struct multi_pack_index *midx,\n-\t\t\t     struct multi_pack_index *midx_chain,\n-\t\t\t     struct object_id *oids,\n-\t\t\t     int n)\n+\t\t\t     struct multi_pack_index *midx_chain)\n {\n \tif (midx_chain) {\n \t\tif (unsigned_add_overflows(midx_chain->num_packs,\n@@ -300,21 +298,20 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,\n {\n \tstruct multi_pack_index *midx_chain = NULL;\n \tstruct strbuf buf = STRBUF_INIT;\n-\tstruct object_id *layers = NULL;\n \tint valid = 1;\n \tuint32_t i, count;\n \tFILE *fp = xfdopen(fd, \"r\");\n \n \tcount = st->st_size / (the_hash_algo->hexsz + 1);\n-\tCALLOC_ARRAY(layers, count);\n \n \tfor (i = 0; i < count; i++) {\n \t\tstruct multi_pack_index *m;\n+\t\tstruct object_id layer;\n \n \t\tif (strbuf_getline_lf(&buf, fp) == EOF)\n \t\t\tbreak;\n \n-\t\tif (get_oid_hex(buf.buf, &layers[i])) {\n+\t\tif (get_oid_hex(buf.buf, &layer)) {\n \t\t\twarning(_(\"invalid multi-pack-index chain: line '%s' \"\n \t\t\t\t  \"not a hash\"),\n \t\t\t\tbuf.buf);\n@@ -325,12 +322,12 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,\n \t\tvalid = 0;\n \n \t\tstrbuf_reset(&buf);\n-\t\tget_split_midx_filename_ext(&buf, object_dir, layers[i].hash,\n+\t\tget_split_midx_filename_ext(&buf, object_dir, layer.hash,\n \t\t\t\t\t    MIDX_EXT_MIDX);\n \t\tm = load_multi_pack_index_one(object_dir, buf.buf, local);\n \n \t\tif (m) {\n-\t\t\tif (add_midx_to_chain(m, midx_chain, layers, i)) {\n+\t\t\tif (add_midx_to_chain(m, midx_chain)) {\n \t\t\t\tmidx_chain = m;\n \t\t\t\tvalid = 1;\n \t\t\t} else {\n@@ -343,7 +340,6 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,\n \t\t}\n \t}\n \n-\tfree(layers);\n \tfclose(fp);\n \tstrbuf_release(&buf);\n \n-- \n2.46.0.419.g66cd00f2b7\n"}]}