From patchwork Wed Nov 27 16:28:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak X-Patchwork-Id: 13887197 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1BDA2201023 for ; Wed, 27 Nov 2024 16:28:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732724932; cv=none; b=eD4IYiou77FthndlUFJqeNIQ4LsG9BEIzbuy37YUiDB1xHJYp3ZbJjQJmuZcWHJyXazzcIoufB5TZEO3x/Ni67UNyr2iyyi5obrobmPkGxTHRkOeF/NyFrCPKjhaWjUrQTso4E9RAy27O0ZJFb6JTpL7SK/Rlbwn/Jot0njT5tk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732724932; c=relaxed/simple; bh=sx1ryuGozGd99F3zCCNjEUrYsGPUv0as8MJU+JPslDM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=l7pWZkmSbDB5+NsveB3qNt+cPWnVpxsSzlgtdt7wdgiA/1Lm3QLLxmkI2+X6fHmu7XWHJsCZ5r2yWxj9l+Cptt2deyJnhoWDM1p98G3umrpxXhrz2avweGLm2LiJaq6t7Dm2Q8aXa/xL1VG5Ud0UCYBxr7Ji3JuJyyzl2hEf7pE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aXMV2pGP; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aXMV2pGP" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a9ec267b879so994141066b.2 for ; Wed, 27 Nov 2024 08:28:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732724928; x=1733329728; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=CuzciJdDWRMUC08XcaSL/CVBQrMLNMHgY+X0NLG3WsU=; b=aXMV2pGPzIHwyfSGF/qrsKgK/YH6CcIu3VV2EBKW1yaRTYY6LxdE8ih9MEGsfnQcyB TrDVP9F1rmhEFoijcG5yirfyAwD+4OGIEJskRQmrSCMP9nLBd/HHwPNojVzbU8ZQ3JdR PZdfP1BwIUo4hMG2Ng+FJXebA5CbUItRPfZDQ13KgvAKbpLk/NwhWMLwcYx3vgB0+jeG Z8tcUzccFxaJx1BYDuSnFcC1P42H4x/c+zs3sWi+MxAqsSyVgKEmIlIShbX1ZvyhmDv0 A9To07LgDphytaDDdYzS0GPHd8yrmpiYKq+E5FxOZCrFYeqa4uS29h4xKCRW3uia1J1S BwBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732724928; x=1733329728; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CuzciJdDWRMUC08XcaSL/CVBQrMLNMHgY+X0NLG3WsU=; b=Eq7AGvHMydBleARYd8Ifus+1onItaw7ujcHpJQJHnTWSnjII/noBCGUDZkq9DHa8cJ DKXMssWsn7Mo98C5oHMAf+0hc3YDnwwYkU74cmvJPJh+Yl8Q0BGoQg7eZHTsfEt0QgTa tm0bR/Ain7eLtzCQqzNJqpz8cjUmlonqTEd0re1OxkPaJLsOtQIdwVl6geUnOv+6DYsx 5H5m7ig/HQWm45qY1sA+v50/2AxOg2ihSltsrIUuiFGV2g1lGBjT0GOW0kdSl/8umdBd oiGzP0/YcmnFr7TpRuIXhavwIcz6RcMkgTelGw7oWdNVsFpNsQtu7Tc4W6h9TKVOlBaB JROQ== X-Gm-Message-State: AOJu0Yy/5vXlBSQa0gt4gKyrkJU8KpG/xA7GR1TtA6agtdA7l/p6G7nu ifZX6Y/V+SrNmd4SxSZk5PLKdjcguh5VQFQ82ofhfI+QOH4tt6BP X-Gm-Gg: ASbGncvYrOorKRV4vW8354TuuM5ikioZHfEHiOrZNUVbXEnnT01hVexubnMV0mJC+/M 5nZmr18+srmR2Fe4NnjhoT9y0drMguxznvMt0GlLYrIGzhbktx46Vf9HSF5wveliu5anydcRdWs 8m1jbkd7n0HnKexnmzixDM5kWiJFNUrGlQgiUyBk/jkRZ9f7GY0V4jVaFVEHxcB62YeV7kSQgxk Dw7LTC7tOKbHY7L2vDdQqCJZ8LVHxXNai/iaDmsYuFatSGBI8f56Aw0rWYj0g== X-Google-Smtp-Source: AGHT+IFHCrCFqZ+IKDCrl2wLl8sGQ4MprpUeG5Lg62tTeNlTGYQmjmMHMZ5pEEsuo8mVpKQB55BsVg== X-Received: by 2002:a17:906:31d0:b0:aa5:37b4:cd5a with SMTP id a640c23a62f3a-aa580eded57mr276938866b.3.1732724927985; Wed, 27 Nov 2024 08:28:47 -0800 (PST) Received: from [192.168.178.20] ([2a02:2455:825d:6a00:5640:4a6:5555:68ae]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa54e15c169sm420042366b.67.2024.11.27.08.28.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 08:28:47 -0800 (PST) From: Karthik Nayak Date: Wed, 27 Nov 2024 17:28:26 +0100 Subject: [PATCH v3 1/8] midx-write: pass down repository to static functions Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-1-c5a99f85009b@gmail.com> References: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com> In-Reply-To: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , me@ttaylorr.com, shejialuo@gmail.com, gitster@pobox.com, Christian Couder X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=8901; i=karthik.188@gmail.com; h=from:subject:message-id; bh=sx1ryuGozGd99F3zCCNjEUrYsGPUv0as8MJU+JPslDM=; b=owEB7QES/pANAwAIAT7VnySORox/AcsmYgBnR0i8y63XgNWGjlgcFPkbG4Afum1cvq+UkbceC MGzy4TVit2JAbMEAAEIAB0WIQRXzkx/Y3VxD8tlxgY+1Z8kjkaMfwUCZ0dIvAAKCRA+1Z8kjkaM f5iXC/95RHg/tW3LAcBYlqQ029upt0bzAGEUNcUbzrwzOyAL0uPLqxNI349t+dprQPMT2QrGJj9 Lpnwhqvme9etaeUlW/xF4zh1facZxC7XykPkF5msA4CsF1nNH0jAVMrue0F2mz+x/jK+bvmCGlX qCV1VhZVCDMyVIHfAJfj7tQRyvuVvHMHZwP1H8B14JyBEjmPikz6LRBzmovWD2gs48/4IP4XVGb NBZv9ZrkpgeMIsn73PLQpJlB8XVUvKTps/1cublcsvdhUT2h4il/pm9B80TC9KE4m0wLjtfKhyK 9C4GdsW04y79X0HRUnFeRan/rt6ZsSQs4KJ8iidEG1fDdM46Sl0dXshM9R9ETJF5ozVErahz/Sy 7Ue7bS5uyQCLzpNB9/NuSZGEQWXNgalPC/sBg0QBxHmhAKEmg4JLk447GECBenKz6D4pD0ioKnl WdadQC+JCNwrIyY8USJeql9SNZV3p6Qo70v0W36pWefeqL0V9oJTpp++PbAtnyP4+aTuo= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F In 'midx-write.c' there are a lot of static functions which use global variables `the_repository` or `the_hash_algo`. In a follow up commit, the repository variable will be added to `write_midx_context`, which some of the functions can use. But for functions which do not have access to this struct, pass down the required information from non-static functions `write_midx_file` and `write_midx_file_only`. This requires that the function `hash_to_hex` is also replaced with `hash_to_hex_algop` since the former internally accesses the `the_hash_algo` global variable. This ensures that the usage of global variables is limited to these non-static functions, which will be cleaned up in a follow up commit. Signed-off-by: Karthik Nayak --- midx-write.c | 57 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/midx-write.c b/midx-write.c index c57726ef9475df693890d61627ce91409c1def7c..22b5233f51ec6c6d99b8f9613818f1581dca5982 100644 --- a/midx-write.c +++ b/midx-write.c @@ -35,13 +35,13 @@ extern void clear_incremental_midx_files_ext(const char *object_dir, extern int cmp_idx_or_pack_name(const char *idx_or_pack_name, const char *idx_name); -static size_t write_midx_header(struct hashfile *f, - unsigned char num_chunks, +static size_t write_midx_header(const struct git_hash_algo *hash_algo, + struct hashfile *f, unsigned char num_chunks, uint32_t num_packs) { hashwrite_be32(f, MIDX_SIGNATURE); hashwrite_u8(f, MIDX_VERSION); - hashwrite_u8(f, oid_version(the_hash_algo)); + hashwrite_u8(f, oid_version(hash_algo)); hashwrite_u8(f, num_chunks); hashwrite_u8(f, 0); /* unused */ hashwrite_be32(f, num_packs); @@ -702,7 +702,7 @@ static int add_ref_to_pending(const char *refname, const char *referent UNUSED, return 0; } - if (!peel_iterated_oid(the_repository, oid, &peeled)) + if (!peel_iterated_oid(revs->repo, oid, &peeled)) oid = &peeled; object = parse_object_or_die(oid, refname); @@ -827,7 +827,7 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr return cb.commits; } -static int write_midx_bitmap(const char *midx_name, +static int write_midx_bitmap(struct repository *r, const char *midx_name, const unsigned char *midx_hash, struct packing_data *pdata, struct commit **commits, @@ -840,9 +840,9 @@ static int write_midx_bitmap(const char *midx_name, struct bitmap_writer writer; struct pack_idx_entry **index; char *bitmap_name = xstrfmt("%s-%s.bitmap", midx_name, - hash_to_hex(midx_hash)); + hash_to_hex_algop(midx_hash, r->hash_algo)); - trace2_region_enter("midx", "write_midx_bitmap", the_repository); + trace2_region_enter("midx", "write_midx_bitmap", r); if (flags & MIDX_WRITE_BITMAP_HASH_CACHE) options |= BITMAP_OPT_HASH_CACHE; @@ -859,7 +859,7 @@ static int write_midx_bitmap(const char *midx_name, for (i = 0; i < pdata->nr_objects; i++) index[i] = &pdata->objects[i].idx; - bitmap_writer_init(&writer, the_repository, pdata); + bitmap_writer_init(&writer, r, pdata); bitmap_writer_show_progress(&writer, flags & MIDX_PROGRESS); bitmap_writer_build_type_index(&writer, index); @@ -892,7 +892,7 @@ static int write_midx_bitmap(const char *midx_name, free(bitmap_name); bitmap_writer_free(&writer); - trace2_region_leave("midx", "write_midx_bitmap", the_repository); + trace2_region_leave("midx", "write_midx_bitmap", r); return ret; } @@ -1049,7 +1049,7 @@ static void clear_midx_files(const char *object_dir, strbuf_release(&buf); } -static int write_midx_internal(const char *object_dir, +static int write_midx_internal(struct repository *r, const char *object_dir, struct string_list *packs_to_include, struct string_list *packs_to_drop, const char *preferred_pack_name, @@ -1070,7 +1070,8 @@ static int write_midx_internal(const char *object_dir, const char **keep_hashes = NULL; struct chunkfile *cf; - trace2_region_enter("midx", "write_midx_internal", the_repository); + trace2_region_enter("midx", "write_midx_internal", r); + ctx.incremental = !!(flags & MIDX_WRITE_INCREMENTAL); if (ctx.incremental && (flags & MIDX_WRITE_BITMAP)) @@ -1087,8 +1088,7 @@ static int write_midx_internal(const char *object_dir, midx_name.buf); if (!packs_to_include || ctx.incremental) { - struct multi_pack_index *m = lookup_multi_pack_index(the_repository, - object_dir); + struct multi_pack_index *m = lookup_multi_pack_index(r, object_dir); if (m && !midx_checksum_valid(m)) { warning(_("ignoring existing multi-pack-index; checksum mismatch")); m = NULL; @@ -1351,7 +1351,7 @@ static int write_midx_internal(const char *object_dir, add_chunk(cf, MIDX_CHUNKID_OIDFANOUT, MIDX_CHUNK_FANOUT_SIZE, write_midx_oid_fanout); add_chunk(cf, MIDX_CHUNKID_OIDLOOKUP, - st_mult(ctx.entries_nr, the_hash_algo->rawsz), + st_mult(ctx.entries_nr, r->hash_algo->rawsz), write_midx_oid_lookup); add_chunk(cf, MIDX_CHUNKID_OBJECTOFFSETS, st_mult(ctx.entries_nr, MIDX_CHUNK_OFFSET_WIDTH), @@ -1373,7 +1373,8 @@ static int write_midx_internal(const char *object_dir, write_midx_bitmapped_packs); } - write_midx_header(f, get_num_chunks(cf), ctx.nr - dropped_packs); + write_midx_header(r->hash_algo, f, get_num_chunks(cf), + ctx.nr - dropped_packs); write_chunkfile(cf, &ctx); finalize_hashfile(f, midx_hash, FSYNC_COMPONENT_PACK_METADATA, @@ -1405,7 +1406,7 @@ static int write_midx_internal(const char *object_dir, FREE_AND_NULL(ctx.entries); ctx.entries_nr = 0; - if (write_midx_bitmap(midx_name.buf, midx_hash, &pdata, + if (write_midx_bitmap(r, midx_name.buf, midx_hash, &pdata, commits, commits_nr, ctx.pack_order, flags) < 0) { error(_("could not write multi-pack bitmap")); @@ -1449,12 +1450,13 @@ static int write_midx_internal(const char *object_dir, strbuf_release(&final_midx_name); keep_hashes[ctx.num_multi_pack_indexes_before] = - xstrdup(hash_to_hex(midx_hash)); + xstrdup(hash_to_hex_algop(midx_hash, r->hash_algo)); for (i = 0; i < ctx.num_multi_pack_indexes_before; i++) { uint32_t j = ctx.num_multi_pack_indexes_before - i - 1; - keep_hashes[j] = xstrdup(hash_to_hex(get_midx_checksum(m))); + keep_hashes[j] = xstrdup(hash_to_hex_algop(get_midx_checksum(m), + r->hash_algo)); m = m->base_midx; } @@ -1462,7 +1464,7 @@ static int write_midx_internal(const char *object_dir, fprintf(get_lock_file_fp(&lk), "%s\n", keep_hashes[i]); } else { keep_hashes[ctx.num_multi_pack_indexes_before] = - xstrdup(hash_to_hex(midx_hash)); + xstrdup(hash_to_hex_algop(midx_hash, r->hash_algo)); } if (ctx.m || ctx.base_midx) @@ -1495,7 +1497,7 @@ static int write_midx_internal(const char *object_dir, } strbuf_release(&midx_name); - trace2_region_leave("midx", "write_midx_internal", the_repository); + trace2_region_leave("midx", "write_midx_internal", r); return result; } @@ -1505,8 +1507,8 @@ int write_midx_file(const char *object_dir, const char *refs_snapshot, unsigned flags) { - return write_midx_internal(object_dir, NULL, NULL, preferred_pack_name, - refs_snapshot, flags); + return write_midx_internal(the_repository, object_dir, NULL, NULL, + preferred_pack_name, refs_snapshot, flags); } int write_midx_file_only(const char *object_dir, @@ -1515,8 +1517,9 @@ int write_midx_file_only(const char *object_dir, const char *refs_snapshot, unsigned flags) { - return write_midx_internal(object_dir, packs_to_include, NULL, - preferred_pack_name, refs_snapshot, flags); + return write_midx_internal(the_repository, object_dir, packs_to_include, + NULL, preferred_pack_name, refs_snapshot, + flags); } int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags) @@ -1572,7 +1575,8 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla free(count); if (packs_to_drop.nr) - result = write_midx_internal(object_dir, NULL, &packs_to_drop, NULL, NULL, flags); + result = write_midx_internal(r, object_dir, NULL, + &packs_to_drop, NULL, NULL, flags); string_list_clear(&packs_to_drop, 0); @@ -1769,7 +1773,8 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size, goto cleanup; } - result = write_midx_internal(object_dir, NULL, NULL, NULL, NULL, flags); + result = write_midx_internal(r, object_dir, NULL, NULL, NULL, NULL, + flags); cleanup: free(include_pack); From patchwork Wed Nov 27 16:28:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak X-Patchwork-Id: 13887198 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3404B201030 for ; Wed, 27 Nov 2024 16:28:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732724933; cv=none; b=Co5YDuRCX1LWE7mHbjgwCj0evaYn9RcofbdSHUQUNgKACGJGFNAVtwayTUVi5FMiuKXtOuT4URnZDm6Mj91oofof+sD0vLnp2EQzXlr50CNoFfq76eGzyx1mi6vShirlv/G9cd+Qbx4KC+4I7zLGkSaBc6iRXaeG/JGDlarC5Gc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732724933; c=relaxed/simple; bh=ViU8JkW4ZR49GovRN3zlEVxut2zJE8Xl9HpWofIxyqY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fiUrhite2VJQholm9q1DfwLZ2e7nqs6eo2SptxrMN49fu+lieHwYqEM7UfVdM4+v0BUESwOzFdNNQg35OuuSNy0TE5B4sWldxNE6gKiobR6YWS/9+ZBFt9YkcsU3YZ0wsdUpnpldQLZ8eZ40Iue/NK4UBpoDTdPCZiK+o6bUwNc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RzBSmd65; arc=none smtp.client-ip=209.85.208.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RzBSmd65" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2ffc3f2b3a9so55222391fa.1 for ; Wed, 27 Nov 2024 08:28:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732724929; x=1733329729; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=X7dDmM8xmKZjLvLDLK2A8x/QAigchVTAKjdpcKXYtEY=; b=RzBSmd65wzlOW3JsHqfkgmwirJyoNsKgJu048DgyApsIJzKNDXHQADZoxd59p6nK4S t22a/ipNMQ26VmP9qnVrYwziRQhiIW08wg7djvozDPTp/dfmCpP66Hx/uwT0eC/JcWu5 HuU9pQ0sQSZQ+vidt4Zk1rhW7WcGaNibsx/Ri7QeaoZdK+HNyw3yWGWD8+uSqbMlnyCe 4jw22f9BsYwn82MOhHHcyR7I5yFbwoxXDJJ9BPqroGuvdNLzzfwKLlp0E3Hq5Cqwt21K 69uVKuxxA4Ro8qJ0VJyX6vUgiXBLOWI0GRbf8Ax0VJMi1Gx0NFqHTLZeCwb+GDFa/uBa FKvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732724929; x=1733329729; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X7dDmM8xmKZjLvLDLK2A8x/QAigchVTAKjdpcKXYtEY=; b=BaaDI4/yWJ8+ZqB63gVdyFE2L+iHz6RJlzSQCHFRC0jKCjrOGvncujEdzuZrRBc7EP jjSIICVgJILZAOjLNpIRpheKkF5GCp4e8SXppeFlEsNj3ddy1DhtoUsoXqDmrczawFHg OXpLUQFLW7B73oOBotCzGcJjrTx3sclakWKXG7UolMS0JVZkF2/lqPlPc9F8wtCIxCuJ WKtMKGhGHvzwS8OaABXKtQ3EJaTeFQxpWO2WoL6E8w9S8yijUJmyeYSN+pzP8TYJV3gI KPd0ReIwpPSvVxyjAQRWS6/s315/X2jZDt2LsHTOsKcSWcctB6LBhBif8IoKk+k49E3J w0sQ== X-Gm-Message-State: AOJu0Yw3SLFX8PMNq8AGaK2qrwzTmShusntZpGQ4qHZ0jB2Y9XvKP4PC ORHIgwWIKi3F2qrxRMSw/e8qpMZU4YVCu1lVJ2spJjlpc7VJ3ylL X-Gm-Gg: ASbGncsILEi84kKRqSSuJL6rAMfEIi2RZ/0pu7z0mhwPJaKyjVrawIgASgDXw9sponP OQEIY6QAZ6pSiCVmMUYmNHdTpl9o93m5JkRFz62rrumApu8GLGLb4jABTSNwKBoTJj3j2067HFl 7AwjOMuyt6stqrkdws6rdU+qQbxgVCZXZljtrvue74SMXoCFFZz1IiPH/VMlmC9echayOPxcG9u bGYrqQo3m5wPs9MS9AMEbkirEl7G+zz0CIpXBzh5joWXuk+3aYdcZC0zI0R1g== X-Google-Smtp-Source: AGHT+IEkdDsP3zvMZXLqQNxuWYhBxRx7ho88koznROpooWr0vl2mXHbxNMILBIY98z9RgXyEw57Z+A== X-Received: by 2002:a2e:ab0a:0:b0:2fb:5c84:929b with SMTP id 38308e7fff4ca-2ffd60d2b4dmr31526571fa.36.1732724929197; Wed, 27 Nov 2024 08:28:49 -0800 (PST) Received: from [192.168.178.20] ([2a02:2455:825d:6a00:5640:4a6:5555:68ae]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa54e15c169sm420042366b.67.2024.11.27.08.28.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 08:28:48 -0800 (PST) From: Karthik Nayak Date: Wed, 27 Nov 2024 17:28:27 +0100 Subject: [PATCH v3 2/8] midx-write: use `revs->repo` inside `read_refs_snapshot` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-2-c5a99f85009b@gmail.com> References: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com> In-Reply-To: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , me@ttaylorr.com, shejialuo@gmail.com, gitster@pobox.com, Christian Couder X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1235; i=karthik.188@gmail.com; h=from:subject:message-id; bh=ViU8JkW4ZR49GovRN3zlEVxut2zJE8Xl9HpWofIxyqY=; b=owEB7QES/pANAwAIAT7VnySORox/AcsmYgBnR0i8kLXnJBXFv/8HlEEGyiS/sPDyghwQAHiri epdfTEIFaCJAbMEAAEIAB0WIQRXzkx/Y3VxD8tlxgY+1Z8kjkaMfwUCZ0dIvAAKCRA+1Z8kjkaM fwr9DACb6vSoyugrNWE93ZYASNRkLN7C+tG4+ouH6v6vvWwEc5AaRskS9qcBw0kbtowDdO7zvsJ +JXcRPPqhk56XCUj1/LR9ljEEW0KH4+Cbc2mn0tc/eBYi6SARiFDPqOU5inrRpm0iXAxV9VsvxG AVrspDY/P+bsRmzZVPC6ySfc8caAUDDMBEM6fddSYOHCmHEc2lsp0tH2l7qPIFPuhmisaob01t7 RtiofDDZIxVxzFayDW6Rfcg4KO1EArAnSm/OptyPY//T+ikcAbkp5bAKD9hnz2t/NWXQdN1eaVX r+ngtUHOP2nkLyFvffDP3zLRVxcgZl3PhHmHhfj5bIe6H5+uTv63mv7gQiz2s9xCpVQFu8I4D6v QlrPcqFO0XLYrgGJw6omWGxZ8uBenFDyOdhoZulsyYI2cVYX6yrVjw9c0wf7k+RM4Q/lcof6GRT OaeQIXMqHt2yPEQboSf511/cLKaCdZJPjnE0reEqgyDWMDAoww6zFDSEmGmmF/s1stC9A= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F The function `read_refs_snapshot()` uses `parse_oid_hex()`, which relies on the global `the_hash_algo` variable. Let's instead use `parse_oid_hex_algop()` and provide the hash algo via `revs->repo`. Also, while here, fix a missing newline after the function's definition. Signed-off-by: Karthik Nayak --- midx-write.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/midx-write.c b/midx-write.c index 22b5233f51ec6c6d99b8f9613818f1581dca5982..564438f616f59cd24edda956e4af0e0acf167138 100644 --- a/midx-write.c +++ b/midx-write.c @@ -760,7 +760,7 @@ static int read_refs_snapshot(const char *refs_snapshot, hex = &buf.buf[1]; } - if (parse_oid_hex(hex, &oid, &end) < 0) + if (parse_oid_hex_algop(hex, &oid, &end, revs->repo->hash_algo) < 0) die(_("could not parse line: %s"), buf.buf); if (*end) die(_("malformed line: %s"), buf.buf); @@ -776,6 +776,7 @@ static int read_refs_snapshot(const char *refs_snapshot, strbuf_release(&buf); return 0; } + static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr_p, const char *refs_snapshot, struct write_midx_context *ctx) From patchwork Wed Nov 27 16:28:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak X-Patchwork-Id: 13887199 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BB3F2010E9 for ; Wed, 27 Nov 2024 16:28:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732724934; cv=none; b=WDDeA6ZVAX3+Sgc4IVP683MtVPqamskJFaRSW+guv0G6pjPRbTgo0PT3oJdktlsMPMI5RWm3PeRjLaVaHpMYZBDZDLpAc9ypr8SNAzAscJioOg+Xl0ichtIhR2a32myikCewbusfhgh/xmDafYtiNkP8DFHpIgSkuQnhrFJcSxU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732724934; c=relaxed/simple; bh=h3d1YN0mg+7WTli0tfJG7yX2+KjePRbpgfBA0Y8W0J4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kbUqrhlCRqgkPoKc3n3JaEYBUzgBhIGmP+mn4KpG3amcnZzddwU0PCqBfUKFWoWU3/MDZkkbfTxBqQE3B3GWF7XPrYYwN1vW84JhsUK3F4BxwfnKKbObQZQ/JiWwkN2Rhotf9D9a6cUMdJst/ij6Y+iPPpxEZ2e+uMoe6ajqWtk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=V3QrJ0Z4; arc=none smtp.client-ip=209.85.167.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="V3QrJ0Z4" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-53de79c2be4so3632896e87.2 for ; Wed, 27 Nov 2024 08:28:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732724930; x=1733329730; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=qiaMpUjWKqbyruY9egEhMlrHVuLe+9iR5WEHcxqbbsk=; b=V3QrJ0Z4oadYxcoiDmsJRKs/WBwQFER4AkS901+1U1XABux1wPCUm2l9lpDtCFr4ie Zt9GPHl17ygkbt8uu+ZlEwgXffzqrxBfkXKR/ZheugUAe9fLYCuAUprFwSIAOVoXS05A GUCLnLHq+qhbSKr2BLsG/sg2/g47rh8TB/fE162si7zRMTVzdJ5AXqrGErucrWuXvA9+ dMgAlvQZnpBGHyW7iz2XOsSkH05OJCt16m6Cv1rOJUAkiTu7sTFyCDcSIb+16y1JUscS lD59I9rFDItMy5ZWofSBswpbPIIZKozEMat4SiKLJsTLhcwIJu2x/WmONXyS7+IOxkYX K0Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732724930; x=1733329730; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qiaMpUjWKqbyruY9egEhMlrHVuLe+9iR5WEHcxqbbsk=; b=j36gDkpST9nT0Tr+cC18Ai9jcEr93pQVSxHbhw+3U0O/qLU+YidXGsF8bjRTW2N6oi KYnMDTCSmVD8tDC37/aD2ha/l+ThMODdBO6KAUa3rBYTO0oSkWCisLbdgaalbYRqz/+O YJCx1he+QG1OLzGYJR2rJt49VPCFUC1G5nGuQ+mh3a9bPO6pvZ5PKvDFX13M3qNDpAST okf4eI6PkQ4hWtZGXSHtEbNvpCJ9yjOdqYcrzf0Mkzed9e6tejgsLKVOYoit5vMUtSsN GygjAR8VXg16QkObAjY8wG/p6resWXPRrwDtW+d4+3gOde1On5hXTqDVnygf5L3qLknn 1XuQ== X-Gm-Message-State: AOJu0YxRekvA7gOfoGjF8sQZl3su8rnY2fdojnwBx7dg7nmj/bfaUQjF fPOV3GslJb9UrZZyQA+tSwsFg9Ub39zrZAAWhuW9MzSFAKqXOH1t X-Gm-Gg: ASbGnctc/vw/TcSM21qFlirT3mcFskLKa5uP5IO/KY1Q2HSm+T7cC0HRo8CNUtuCAW+ VA3tthoRHJ0OsVc4f0nSj0aPxiBvBNXheiobi0AnbKya8kjUqn5oUl32tfB7H9bmIkGEf6p5X+8 jLmJDMnZLuD3EcuZI6xzmAOkFIhgmeLJ1IQpZg3ubUQQyTn4KkDM49dMv+c5JF5s4Pon2KmqZt6 4QnZmVb66gPrErkhxykTDuGQSYgmwVfnNtsun5hK2/qf+b0H8eRledlYweVgA== X-Google-Smtp-Source: AGHT+IGRKP+2UTIdmxD0dnYlyCrtIpnQh7qAUY8IrINLyXoWKNg/99ezZmbs98+G8SO1QIATdmweIg== X-Received: by 2002:a05:6512:b9c:b0:53d:ed62:e653 with SMTP id 2adb3069b0e04-53df00d102bmr2103987e87.15.1732724930175; Wed, 27 Nov 2024 08:28:50 -0800 (PST) Received: from [192.168.178.20] ([2a02:2455:825d:6a00:5640:4a6:5555:68ae]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa54e15c169sm420042366b.67.2024.11.27.08.28.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 08:28:49 -0800 (PST) From: Karthik Nayak Date: Wed, 27 Nov 2024 17:28:28 +0100 Subject: [PATCH v3 3/8] write-midx: add repository field to `write_midx_context` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-3-c5a99f85009b@gmail.com> References: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com> In-Reply-To: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , me@ttaylorr.com, shejialuo@gmail.com, gitster@pobox.com, Christian Couder X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6085; i=karthik.188@gmail.com; h=from:subject:message-id; bh=h3d1YN0mg+7WTli0tfJG7yX2+KjePRbpgfBA0Y8W0J4=; b=owEB7QES/pANAwAIAT7VnySORox/AcsmYgBnR0i84GdtnzXEsdIRkUoVfVGEJd2uKz2noRYlZ 03KltVqRFaJAbMEAAEIAB0WIQRXzkx/Y3VxD8tlxgY+1Z8kjkaMfwUCZ0dIvAAKCRA+1Z8kjkaM f7/+C/9cAOVFrh5mKDZA60065pevICIwJXTAXsqtp4uV0UVC1T5S3arZObygdKGm1/hGQ4atDoL J+dNOR+SrTXKqSz/8kOy5m2y06CT89oEXzlYTtvfIDL4hKoLKDIYqWKf50/BHUlUWqDrBoFCPfi p8XEVB6NaHYeSXNoWhrVN3v2HkGGeGOkU9Kj8SrtMgwJMWBJ8nscZ7/W0OB7ojwXT3HDPLQk3lZ Cqt1Van7g/uUyaRF+j8FXxzonLm0nVVgO4Oy2U7x+XmFzUL3yF0oI3gURJecPN2VTiPIW0S8K8r TWC+u+gOxFsfS7WIr7iQfEUj5YBP4picZh6UWCPqRXTc5ac9tYcNS5goau/hygg6o/4Ua+8IYAH 1dnimUJg9JC967oawfgKKXl3CXfTTNf+QAdiXbgYI3cUfEbWGhhX+o/s1GALTH3RrI0I4u75iR8 xeFNXNmLE+T72QXrZa0I1oKD1WjsJJH5kvsTQnNgBvg9ZFEYw0w5KxlO2ROxI92dElyj8= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F The struct `write_midx_context` is used to pass context for creating MIDX files. Add the repository field here to ensure that most functions within `midx-write.c` have access to the field and can use that instead of the global `the_repository` variable. Signed-off-by: Karthik Nayak --- midx-write.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/midx-write.c b/midx-write.c index 564438f616f59cd24edda956e4af0e0acf167138..1c355cdf8db4e9fed61a4aabf61a237ad26181ce 100644 --- a/midx-write.c +++ b/midx-write.c @@ -110,6 +110,8 @@ struct write_midx_context { uint32_t num_multi_pack_indexes_before; struct string_list *to_include; + + struct repository *repo; }; static int should_include_pack(const struct write_midx_context *ctx, @@ -154,7 +156,7 @@ static void add_pack_to_midx(const char *full_path, size_t full_path_len, return; ALLOC_GROW(ctx->info, ctx->nr + 1, ctx->alloc); - p = add_packed_git(the_repository, full_path, full_path_len, 0); + p = add_packed_git(ctx->repo, full_path, full_path_len, 0); if (!p) { warning(_("failed to add packfile '%s'"), full_path); @@ -480,7 +482,7 @@ static int write_midx_oid_lookup(struct hashfile *f, void *data) { struct write_midx_context *ctx = data; - unsigned char hash_len = the_hash_algo->rawsz; + unsigned char hash_len = ctx->repo->hash_algo->rawsz; struct pack_midx_entry *list = ctx->entries; uint32_t i; @@ -605,7 +607,7 @@ static uint32_t *midx_pack_order(struct write_midx_context *ctx) uint32_t *pack_order, base_objects = 0; uint32_t i; - trace2_region_enter("midx", "midx_pack_order", the_repository); + trace2_region_enter("midx", "midx_pack_order", ctx->repo); if (ctx->incremental && ctx->base_midx) base_objects = ctx->base_midx->num_objects + @@ -640,7 +642,7 @@ static uint32_t *midx_pack_order(struct write_midx_context *ctx) } free(data); - trace2_region_leave("midx", "midx_pack_order", the_repository); + trace2_region_leave("midx", "midx_pack_order", ctx->repo); return pack_order; } @@ -651,9 +653,10 @@ static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash, struct strbuf buf = STRBUF_INIT; char *tmp_file; - trace2_region_enter("midx", "write_midx_reverse_index", the_repository); + trace2_region_enter("midx", "write_midx_reverse_index", ctx->repo); - strbuf_addf(&buf, "%s-%s.rev", midx_name, hash_to_hex(midx_hash)); + strbuf_addf(&buf, "%s-%s.rev", midx_name, hash_to_hex_algop(midx_hash, + ctx->repo->hash_algo)); tmp_file = write_rev_file_order(NULL, ctx->pack_order, ctx->entries_nr, midx_hash, WRITE_REV); @@ -664,7 +667,7 @@ static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash, strbuf_release(&buf); free(tmp_file); - trace2_region_leave("midx", "write_midx_reverse_index", the_repository); + trace2_region_leave("midx", "write_midx_reverse_index", ctx->repo); } static void prepare_midx_packing_data(struct packing_data *pdata, @@ -672,10 +675,10 @@ static void prepare_midx_packing_data(struct packing_data *pdata, { uint32_t i; - trace2_region_enter("midx", "prepare_midx_packing_data", the_repository); + trace2_region_enter("midx", "prepare_midx_packing_data", ctx->repo); memset(pdata, 0, sizeof(struct packing_data)); - prepare_packing_data(the_repository, pdata); + prepare_packing_data(ctx->repo, pdata); for (i = 0; i < ctx->entries_nr; i++) { uint32_t pos = ctx->pack_order[i]; @@ -686,7 +689,7 @@ static void prepare_midx_packing_data(struct packing_data *pdata, ctx->info[ctx->pack_perm[from->pack_int_id]].p); } - trace2_region_leave("midx", "prepare_midx_packing_data", the_repository); + trace2_region_leave("midx", "prepare_midx_packing_data", ctx->repo); } static int add_ref_to_pending(const char *refname, const char *referent UNUSED, @@ -784,17 +787,16 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr struct rev_info revs; struct bitmap_commit_cb cb = {0}; - trace2_region_enter("midx", "find_commits_for_midx_bitmap", - the_repository); + trace2_region_enter("midx", "find_commits_for_midx_bitmap", ctx->repo); cb.ctx = ctx; - repo_init_revisions(the_repository, &revs, NULL); + repo_init_revisions(ctx->repo, &revs, NULL); if (refs_snapshot) { read_refs_snapshot(refs_snapshot, &revs); } else { setup_revisions(0, NULL, &revs, NULL); - refs_for_each_ref(get_main_ref_store(the_repository), + refs_for_each_ref(get_main_ref_store(ctx->repo), add_ref_to_pending, &revs); } @@ -822,8 +824,7 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr release_revisions(&revs); - trace2_region_leave("midx", "find_commits_for_midx_bitmap", - the_repository); + trace2_region_leave("midx", "find_commits_for_midx_bitmap", ctx->repo); return cb.commits; } @@ -945,7 +946,7 @@ static int fill_packs_from_midx(struct write_midx_context *ctx, */ if (flags & MIDX_WRITE_REV_INDEX || preferred_pack_name) { - if (prepare_midx_pack(the_repository, m, + if (prepare_midx_pack(ctx->repo, m, m->num_packs_in_base + i)) { error(_("could not load pack")); return 1; @@ -1073,6 +1074,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir, trace2_region_enter("midx", "write_midx_internal", r); + ctx.repo = r; ctx.incremental = !!(flags & MIDX_WRITE_INCREMENTAL); if (ctx.incremental && (flags & MIDX_WRITE_BITMAP)) @@ -1469,7 +1471,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir, } if (ctx.m || ctx.base_midx) - close_object_store(the_repository->objects); + close_object_store(ctx.repo->objects); if (commit_lock_file(&lk) < 0) die_errno(_("could not write multi-pack-index")); From patchwork Wed Nov 27 16:28:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak X-Patchwork-Id: 13887200 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D93E62010F2 for ; Wed, 27 Nov 2024 16:28:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732724934; cv=none; b=QKnrUPJ8JTLf/9ktr6R0w8AHo91/OScxu0wWBGayn1GwzeK1PGFjk3cxgj4UZl9Gb5v12EUlVjUtzU9zpwtNwsSVsi0f3RdteGFns6odVuE/PVLhGBhFbkUJ3jP06JZ5JSHQoA+kOd0+QiNmRIym8wwG5ny9+SDjCSx1hIKu4oY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732724934; c=relaxed/simple; bh=XswBKIEYVgzBzr7Zn3z0ELPX7Dim66xK7iLqybRKUKU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rgB60mzQaqWu29r+PkwMHRgom6d602bKGG8RgnZhuEUKlQu4sEq9TIikHR8SihNbFeAFH195ZZOvk86aUwVDwZSjmrixFTA46sJgp8tTayJlhQaQ0tGh4hnzQgGqea6n2wcjML726pwZVNit9Ze0iK7fR1qNMQFKzYua/Xo3OBA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=efqugE0E; arc=none smtp.client-ip=209.85.218.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="efqugE0E" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-aa51bf95ce1so858942166b.3 for ; Wed, 27 Nov 2024 08:28:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732724931; x=1733329731; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=1r7ySIMkMP2E3CKpRumrzTuZwI4S8S3VQBRTXzSrfGU=; b=efqugE0EiCJVrLfh4JSvrdnTB6RgyfbHEEw0wY0Co+Uzrh17nBIsZBakkoHf/4hs8v HEwqpLNx4i5ejVvTEwUDbLPwA9eGtdHfsFRHRuz/IA7Y3mcJUyRCM5MDjTekZxgkHwIF KZ27afzB8ePhfQRtNvFuyeWVPK8mKM+fxgtiDsQ2H1EyjoRUC0g8l9T3n3JAkCHeJOHo aS4rtosub47Yu1H+R2upGLfmyKkVEPZsk+V9zRJxlNByDLi/olmew6iCnsVu0b1/fdY+ REdR/kLWf7Jz2SIHoGSgXx5CJTO7hBNgiPbY9VmqafyG8MXp4k4EB+47M4tEWNzXqkwF RvFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732724931; x=1733329731; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1r7ySIMkMP2E3CKpRumrzTuZwI4S8S3VQBRTXzSrfGU=; b=omrd+pBQZOBrMu5+1KyO0B7XWnHAQsLgO6vfmBVbGWIo7O/yDiTREdDR13Lg4FEIJx Fkv3qdqtu3sUm5rPy0xwkAGfms5OTEH+oMqnxJPxbowm+8pDtuvN7ISU2FHMjqsdHvy4 5Tk4fwN+nkxnvB99hlHAL7MSy7aqowL83D3nSocGWCHEfu4u9ImH9NaOKC578Xtu6wI0 TPn+DA70Ev/lkDjko1Nu3zQRPp74UlVJcjOdTJsT16QmAtvri1V3BaLOOms0WV4b8E/v ssAMg40JKRb0Dl3IhINGfjNuDWKnsoSxdnI06t93EbwCFRcEtDMEnWt74kHl1ZrzoVUU QCmg== X-Gm-Message-State: AOJu0YwfwKm7Z8ceBXZEJI0egve5gM3sUBdwMIq6y9t/ant4iTSfhs7W GYTLdUmiK+wf104tAfSi6nYqnc/B243bOsEbLRHrG1CT8RpKi3JZ X-Gm-Gg: ASbGnct3xZFwh0YDpvA2WH5C5UeyR+wPkzIcP+e7CWuhhej5/DZKFMKiCzfKXiZV88x 90ylfgb/+DG9+1qf+mvaejLpimZ4sZ5PZy5HNZb1m80qGy4+xmrmFR9/kWHZQRMchDMIDVtjTSq f4Fw1xRTR59zZswy0L9UyM2mbyoip8H1PxfG+1jy19e+q4gX+oawuxXAv7ks4U9uMpI/mSWg7D3 gKNtWjZGeOWAgKYzauW0ObhY0avZTPfnHgr/cuXAZ+JJ8fCa+ZEKsl5wKPCeA== X-Google-Smtp-Source: AGHT+IGwTvXPNmneVRxdE1btt+xpoPW7TJ4XHaGxPxQzma1PIYatfRsCEoEHmyHg+xOcmI1LWhwqOg== X-Received: by 2002:a17:906:32ce:b0:aa5:3591:420f with SMTP id a640c23a62f3a-aa580f1b93emr410819966b.16.1732724931068; Wed, 27 Nov 2024 08:28:51 -0800 (PST) Received: from [192.168.178.20] ([2a02:2455:825d:6a00:5640:4a6:5555:68ae]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa54e15c169sm420042366b.67.2024.11.27.08.28.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 08:28:50 -0800 (PST) From: Karthik Nayak Date: Wed, 27 Nov 2024 17:28:29 +0100 Subject: [PATCH v3 4/8] midx-write: pass down repository to `write_midx_file[_only]` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-4-c5a99f85009b@gmail.com> References: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com> In-Reply-To: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , me@ttaylorr.com, shejialuo@gmail.com, gitster@pobox.com, Christian Couder X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5314; i=karthik.188@gmail.com; h=from:subject:message-id; bh=XswBKIEYVgzBzr7Zn3z0ELPX7Dim66xK7iLqybRKUKU=; b=owEB7QES/pANAwAIAT7VnySORox/AcsmYgBnR0i8Ucu2fHvXCepJjiRfWJFzNJZdZj9aPsS0C /6AzNSOj+6JAbMEAAEIAB0WIQRXzkx/Y3VxD8tlxgY+1Z8kjkaMfwUCZ0dIvAAKCRA+1Z8kjkaM f9+zC/0RDC6SWIjHnedN3oGH5EWi73LxsujlFsqcYcRUL8hAbRA5WF0O3zPq87IFNJ51GnzMJxp KHKQ9tjGt27KJz9jAf1+myNesxqtSG5i/0+bL7tLddNpAGkRPgqK3abKnEFYok7hEtArbCMro33 bwRJml7BUgzBHLokOBlBhFogm6mGOlVlOOnvrqZh2pAyxYyuMlEctlWhdHndPWNeyV/6Nwzc3DY KA5/LRByE43wns+pcJ98nuzRFCiyTS+6AojPZ1ZOG5RmcJbE1PrUvC+tQS2LxTLVeXGD5QY3VfB kZuMplr1dNg/wdG3kknpuAuzVR6R+eqz9BZbYIzJ4qcL6Iz0LgoZt/UplqmLigKO3RnLDyB07on 8z9drryOIXQyfUSPangLptpK9BsNZxD/8sNvoTdWnpt/vpCkbUKfKNZNpQYNNNFprCTBt2D4Yh9 q14WMHaWGAC8ujzEC4F+m7Y8Ycb8YwFnEpzZ+QfOLc9tcL90Amv8DfFRwF4km77+3GzSk= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F In a previous commit, we passed the repository field to all subcommands in the `builtin/` directory. Utilize this to pass the repository field down to the `write_midx_file[_only]` functions to remove the usage of `the_repository` global variables. With this, all usage of global variables in `midx-write.c` is removed, hence, remove the `USE_THE_REPOSITORY_VARIABLE` guard from the file. Signed-off-by: Karthik Nayak --- builtin/multi-pack-index.c | 6 +++--- builtin/repack.c | 2 +- midx-write.c | 22 +++++++++------------- midx.h | 10 ++++------ 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c index 85e40a4b6d3e47e9ec1ec27c094455e5ba75b5b0..2a938466f53aaa11096170554fe11a4ed46a25e4 100644 --- a/builtin/multi-pack-index.c +++ b/builtin/multi-pack-index.c @@ -120,7 +120,7 @@ static void read_packs_from_stdin(struct string_list *to) static int cmd_multi_pack_index_write(int argc, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { struct option *options; static struct option builtin_multi_pack_index_write_options[] = { @@ -165,7 +165,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv, read_packs_from_stdin(&packs); - ret = write_midx_file_only(opts.object_dir, &packs, + ret = write_midx_file_only(repo, opts.object_dir, &packs, opts.preferred_pack, opts.refs_snapshot, opts.flags); @@ -176,7 +176,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv, } - ret = write_midx_file(opts.object_dir, opts.preferred_pack, + ret = write_midx_file(repo, opts.object_dir, opts.preferred_pack, opts.refs_snapshot, opts.flags); free(opts.refs_snapshot); diff --git a/builtin/repack.c b/builtin/repack.c index 96a4fa234bddfd2b63c8d9733379d9b1012a4014..9c21fc482dfb387c818c0d0a74f781848b5a0953 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -1569,7 +1569,7 @@ int cmd_repack(int argc, unsigned flags = 0; if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL, 0)) flags |= MIDX_WRITE_INCREMENTAL; - write_midx_file(repo_get_object_directory(the_repository), + write_midx_file(the_repository, repo_get_object_directory(the_repository), NULL, NULL, flags); } diff --git a/midx-write.c b/midx-write.c index 1c355cdf8db4e9fed61a4aabf61a237ad26181ce..1bc2f5256916e69924245951f654c1047ffeab84 100644 --- a/midx-write.c +++ b/midx-write.c @@ -1,5 +1,3 @@ -#define USE_THE_REPOSITORY_VARIABLE - #include "git-compat-util.h" #include "abspath.h" #include "config.h" @@ -1505,24 +1503,22 @@ static int write_midx_internal(struct repository *r, const char *object_dir, return result; } -int write_midx_file(const char *object_dir, +int write_midx_file(struct repository *r, const char *object_dir, const char *preferred_pack_name, - const char *refs_snapshot, - unsigned flags) + const char *refs_snapshot, unsigned flags) { - return write_midx_internal(the_repository, object_dir, NULL, NULL, - preferred_pack_name, refs_snapshot, flags); + return write_midx_internal(r, object_dir, NULL, NULL, + preferred_pack_name, refs_snapshot, + flags); } -int write_midx_file_only(const char *object_dir, +int write_midx_file_only(struct repository *r, const char *object_dir, struct string_list *packs_to_include, const char *preferred_pack_name, - const char *refs_snapshot, - unsigned flags) + const char *refs_snapshot, unsigned flags) { - return write_midx_internal(the_repository, object_dir, packs_to_include, - NULL, preferred_pack_name, refs_snapshot, - flags); + return write_midx_internal(r, object_dir, packs_to_include, NULL, + preferred_pack_name, refs_snapshot, flags); } int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags) diff --git a/midx.h b/midx.h index 3b0ac4d8788b373c59fe69ca2d78e9d914702bc0..c37ad5b5242b56d21fd76bd59957a1bdb82786ec 100644 --- a/midx.h +++ b/midx.h @@ -123,15 +123,13 @@ int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, i * Variant of write_midx_file which writes a MIDX containing only the packs * specified in packs_to_include. */ -int write_midx_file(const char *object_dir, - const char *preferred_pack_name, - const char *refs_snapshot, +int write_midx_file(struct repository *r, const char *object_dir, + const char *preferred_pack_name, const char *refs_snapshot, unsigned flags); -int write_midx_file_only(const char *object_dir, +int write_midx_file_only(struct repository *r, const char *object_dir, struct string_list *packs_to_include, const char *preferred_pack_name, - const char *refs_snapshot, - unsigned flags); + const char *refs_snapshot, unsigned flags); void clear_midx_file(struct repository *r); int verify_midx_file(struct repository *r, const char *object_dir, unsigned flags); int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags); From patchwork Wed Nov 27 16:28:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak X-Patchwork-Id: 13887201 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3328200BA7 for ; Wed, 27 Nov 2024 16:28:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732724935; cv=none; b=UCZHqkaHfvIQfGA1Y5dI26md9qRV8kX74y0iT+N6eSRu954zDOSc9ti87oHLGFsUqpKyinxaoAAwC9go4cXo0JNaMpa///JDuoBKPXrF7fElS0/49jdzcqawbzbH8tabn8BykQ9TV75c+2dmpt//XqyHBn4T96ab0Q+GaFwP2Bo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732724935; c=relaxed/simple; bh=388Q7IBxjvwIlJsOIxbdq2Kro5QoNip+705J8adNuP4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FjYvFUDPU1h4KQR+2W/JsiGapEMiyzEn9JYB/ncJwjo/1GGPcQWH6eIkgzh1jNpvBzzErL2sjSpQVLv14ihHWNecUuNmZ/HVWdA83gQrM/M3SBOjFXLRS18eSkgXvd4jKbe8VEQHxKDwT1iZKkHHt3WggUVZIZ3ivHRNIp9g16E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WwEh8oZk; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WwEh8oZk" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-aa578d10d50so281616666b.1 for ; Wed, 27 Nov 2024 08:28:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732724932; x=1733329732; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=G5FksHJzH0Hty2G2uuMj9yVEOCFUPREVcLvufz8AueE=; b=WwEh8oZk/7DpzNR2aX/wf6X4IXQfiU/87fXK1xuFpO/lA1KSqvsVxCM5WlEBX7+qho +4lPUMupuN7ji/t/xcBQb5/cvGe/IlQ7VbP8TOO6k8xMAt/A/RYGO/glbz8R0USRn1Rq Z52sQzaYl9bgXqGRmR2/kooeV9ACoTJFjjjvfvqZdZPlrU2uNJrzhotI9RJ9NL3xJZFG Hg7p6S5jZ8dP2ORqHgN4X3K3lcGPJsIjVOG4hRaBONozqbg2lDtDjZB6zvCY2b/KJvpW jdxTSSvn1qbXBfbfDnVV5zNYYAoa5/hXgqbrw5zWeZtnjaGpPQm8vBXegnrwCFEzVqWG YHGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732724932; x=1733329732; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G5FksHJzH0Hty2G2uuMj9yVEOCFUPREVcLvufz8AueE=; b=qzSMuXktuAvCQeuOOl8OUXOf+23+EVovejIIICB2dvt5JvhwKGYR9wxwok5P9d+nzV W58/Rj7/c9MT7EunAHzuz3nAQzMxOsUbLiKtFu0fHE0TiT2hhR/cjwP2gaFmNjjYs+et Ld8+K/RQtFuPGdkUirrM7ySCk2GocVls0rI7srumHopCN0K+vmNgaboGN7cdDRCp6MF3 wlyJIKPNAOdBhjxhJFhEfX9FPwkW248B/9VmmMf3dVnlT/zVN6eVc7VxQs1gqpZplBs7 dN2indBOot0vncMwBaW+IfcPtAYKZ+P9gJfdhfHqfqSL/pjjBfKX5tB0mgX/8NK0EPTT 0bUA== X-Gm-Message-State: AOJu0Yy7ABmuO66utqqta/Ju3nMyGY2BdgdUoO1WGOj2Ds1UvncTVpqt iOWBWMuaok2EMrU2RWx3V1U+Lyg0UOBr7LzRi1a8SWgWei+iTsRuDrDhTQLS X-Gm-Gg: ASbGncvft/FZMDusEd96Owvl5+cHKkclSF3940gkc2nl90T/Lrg6QGK1C9Gdn8sYC0l MrLlDyAHcaBhQk584Xbf/vaqYCcK5WuLPRQ/DZNuie0ghBL5wxuM8/wn1IuXEWJElkcCH4IWfmj YywjFISzQ7OeA8x55cbDw3ZAYGzPwlIGx/OEzSvgMkUbNVDZhJvSHBBlTwKuSk8tTM5J7j3VPy9 goBpDj2KLcWntJ912TYFGwZ1XF9kthbV85wbxVWHkKBtThdCXGb0+VYYoFkvg== X-Google-Smtp-Source: AGHT+IEWTQOaksKavQRfS7E2jVPcmsr3xAL6Cp0tv0VqJm16bGhFRL9ldZfG8AcPW33HE/XSDFUfJg== X-Received: by 2002:a17:906:3143:b0:aa5:11fa:626d with SMTP id a640c23a62f3a-aa580ee013dmr357967266b.3.1732724931947; Wed, 27 Nov 2024 08:28:51 -0800 (PST) Received: from [192.168.178.20] ([2a02:2455:825d:6a00:5640:4a6:5555:68ae]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa54e15c169sm420042366b.67.2024.11.27.08.28.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 08:28:51 -0800 (PST) From: Karthik Nayak Date: Wed, 27 Nov 2024 17:28:30 +0100 Subject: [PATCH v3 5/8] midx: cleanup internal usage of `the_repository` and `the_hash_algo` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-5-c5a99f85009b@gmail.com> References: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com> In-Reply-To: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , me@ttaylorr.com, shejialuo@gmail.com, gitster@pobox.com, Christian Couder X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=7347; i=karthik.188@gmail.com; h=from:subject:message-id; bh=388Q7IBxjvwIlJsOIxbdq2Kro5QoNip+705J8adNuP4=; b=owEB7QES/pANAwAIAT7VnySORox/AcsmYgBnR0i9kltlbAEXQxUqgU31+dMBYZJp2yZu0J2ol UG6rZj/GemJAbMEAAEIAB0WIQRXzkx/Y3VxD8tlxgY+1Z8kjkaMfwUCZ0dIvQAKCRA+1Z8kjkaM f16zC/0TrVRHgTmGZ7OV5MbOxGd+kPGcH6KTHL2mc6Pq4FO4B0HCclRVu3rmhWczw4w/SW4EEfG /WwCwdqPXUlB3KbNsWTKeH6mA1J/ALjS0JMkxbQMEcQT6gXM8OKxuCq0mzdFEJA3DXKYJBdot1n 7MJ8c4JfP7RCitiChgvqCW51wGKEp6Sb/fT0HfyGAC18uvewCVGPHOSI3PLIk5p1nzBAMt2OfJK eDagVI+qWGBl8RN4J6Wj+KhcKjL9YWJnRPtaF0CsbB3REsbltncG57G+BHiliPD1vaXhG9eT7I4 7bmLIBmKy5LXZSiOqKcFwwML0u2sZl9+mPLFAovg4F57byWkzCAxMECojCvORnmJUlXA2l4pU1i pv+VD8Nzl+0zpcHAj0ILhcEXc1DfqHOKi6rDUCTWK6SQlAi1XOcCBZwJMnwKEK0tJvOfajrjBmM 88jUwWUuCP0JVAfpttrOBQcboFRuA3+SZOO2LVV76G/1X5EsBKJbOLCCWAkhMFu4/3GJY= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F In the `midx.c` file, there are multiple usages of `the_repository` and `the_hash_algo` within static functions of the file. Some of the usages can be simply swapped out with the available `repository` struct. While some of them can be swapped out by passing the repository to the required functions. This leaves out only some other usages of `the_repository` and `the_hash_algo` in the file in non-static functions, which we'll tackle in upcoming commits. Signed-off-by: Karthik Nayak --- midx.c | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/midx.c b/midx.c index 079c45a1aafb658a7b887ac216cc6ecf5f0fb6ff..6f0fb8285af14843da132ef1b0c3a8bdd06732c9 100644 --- a/midx.c +++ b/midx.c @@ -25,7 +25,7 @@ int cmp_idx_or_pack_name(const char *idx_or_pack_name, const unsigned char *get_midx_checksum(struct multi_pack_index *m) { - return m->data + m->data_len - the_hash_algo->rawsz; + return m->data + m->data_len - m->repo->hash_algo->rawsz; } void get_midx_filename(struct strbuf *out, const char *object_dir) @@ -94,7 +94,8 @@ static int midx_read_object_offsets(const unsigned char *chunk_start, #define MIDX_MIN_SIZE (MIDX_HEADER_SIZE + the_hash_algo->rawsz) -static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir, +static struct multi_pack_index *load_multi_pack_index_one(struct repository *r, + const char *object_dir, const char *midx_name, int local) { @@ -131,7 +132,7 @@ static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir m->data = midx_map; m->data_len = midx_size; m->local = local; - m->repo = the_repository; + m->repo = r; m->signature = get_be32(m->data); if (m->signature != MIDX_SIGNATURE) @@ -144,12 +145,12 @@ static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir m->version); hash_version = m->data[MIDX_BYTE_HASH_VERSION]; - if (hash_version != oid_version(the_hash_algo)) { + if (hash_version != oid_version(r->hash_algo)) { error(_("multi-pack-index hash version %u does not match version %u"), - hash_version, oid_version(the_hash_algo)); + hash_version, oid_version(r->hash_algo)); goto cleanup_fail; } - m->hash_len = the_hash_algo->rawsz; + m->hash_len = r->hash_algo->rawsz; m->num_chunks = m->data[MIDX_BYTE_NUM_CHUNKS]; @@ -206,8 +207,8 @@ static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir m->pack_names[i]); } - trace2_data_intmax("midx", the_repository, "load/num_packs", m->num_packs); - trace2_data_intmax("midx", the_repository, "load/num_objects", m->num_objects); + trace2_data_intmax("midx", r, "load/num_packs", m->num_packs); + trace2_data_intmax("midx", r, "load/num_objects", m->num_objects); free_chunkfile(cf); return m; @@ -240,8 +241,9 @@ void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir, strbuf_addf(buf, "/multi-pack-index-%s.%s", hash_to_hex(hash), ext); } -static int open_multi_pack_index_chain(const char *chain_file, - int *fd, struct stat *st) +static int open_multi_pack_index_chain(const struct git_hash_algo *hash_algo, + const char *chain_file, int *fd, + struct stat *st) { *fd = git_open(chain_file); if (*fd < 0) @@ -250,7 +252,7 @@ static int open_multi_pack_index_chain(const char *chain_file, close(*fd); return 0; } - if (st->st_size < the_hash_algo->hexsz) { + if (st->st_size < hash_algo->hexsz) { close(*fd); if (!st->st_size) { /* treat empty files the same as missing */ @@ -292,7 +294,8 @@ static int add_midx_to_chain(struct multi_pack_index *midx, return 1; } -static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir, +static struct multi_pack_index *load_midx_chain_fd_st(struct repository *r, + const char *object_dir, int local, int fd, struct stat *st, int *incomplete_chain) @@ -303,7 +306,7 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir, uint32_t i, count; FILE *fp = xfdopen(fd, "r"); - count = st->st_size / (the_hash_algo->hexsz + 1); + count = st->st_size / (r->hash_algo->hexsz + 1); for (i = 0; i < count; i++) { struct multi_pack_index *m; @@ -312,7 +315,7 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir, if (strbuf_getline_lf(&buf, fp) == EOF) break; - if (get_oid_hex(buf.buf, &layer)) { + if (get_oid_hex_algop(buf.buf, &layer, r->hash_algo)) { warning(_("invalid multi-pack-index chain: line '%s' " "not a hash"), buf.buf); @@ -325,7 +328,7 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir, strbuf_reset(&buf); get_split_midx_filename_ext(&buf, object_dir, layer.hash, MIDX_EXT_MIDX); - m = load_multi_pack_index_one(object_dir, buf.buf, local); + m = load_multi_pack_index_one(r, object_dir, buf.buf, local); if (m) { if (add_midx_to_chain(m, midx_chain)) { @@ -348,7 +351,8 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir, return midx_chain; } -static struct multi_pack_index *load_multi_pack_index_chain(const char *object_dir, +static struct multi_pack_index *load_multi_pack_index_chain(struct repository *r, + const char *object_dir, int local) { struct strbuf chain_file = STRBUF_INIT; @@ -357,10 +361,10 @@ static struct multi_pack_index *load_multi_pack_index_chain(const char *object_d struct multi_pack_index *m = NULL; get_midx_chain_filename(&chain_file, object_dir); - if (open_multi_pack_index_chain(chain_file.buf, &fd, &st)) { + if (open_multi_pack_index_chain(r->hash_algo, chain_file.buf, &fd, &st)) { int incomplete; /* ownership of fd is taken over by load function */ - m = load_midx_chain_fd_st(object_dir, local, fd, &st, + m = load_midx_chain_fd_st(r, object_dir, local, fd, &st, &incomplete); } @@ -376,9 +380,10 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, get_midx_filename(&midx_name, object_dir); - m = load_multi_pack_index_one(object_dir, midx_name.buf, local); + m = load_multi_pack_index_one(the_repository, object_dir, + midx_name.buf, local); if (!m) - m = load_multi_pack_index_chain(object_dir, local); + m = load_multi_pack_index_chain(the_repository, object_dir, local); strbuf_release(&midx_name); @@ -520,7 +525,7 @@ int bsearch_one_midx(const struct object_id *oid, struct multi_pack_index *m, uint32_t *result) { int ret = bsearch_hash(oid->hash, m->chunk_oid_fanout, - m->chunk_oid_lookup, the_hash_algo->rawsz, + m->chunk_oid_lookup, m->repo->hash_algo->rawsz, result); if (result) *result += m->num_objects_in_base; @@ -551,7 +556,7 @@ struct object_id *nth_midxed_object_oid(struct object_id *oid, n = midx_for_object(&m, n); oidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n), - the_repository->hash_algo); + m->repo->hash_algo); return oid; } From patchwork Wed Nov 27 16:28:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak X-Patchwork-Id: 13887202 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFE5F20110A for ; Wed, 27 Nov 2024 16:28:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732724936; cv=none; b=FvmMfaimN26GxYHka8aLNyzTcBuS74o027ugJsn5WI4PbQ1sZ0AuZ7RZrA8F15DRzjatpz+PhzIxGSapcYjp6R1AAEV1e+u6kY+h+9a1WIjhv/KQYEBzvAqCYvbpYCoY1ytNp0njPVpgjNCLqI4AUBruXuIQWZvztQaUnCnhbgc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732724936; c=relaxed/simple; bh=6a1VFJPVXDs5jabZQCbDZTOicBHDx9PUoLnrc0lGE08=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ez9O42Vmv/IaF2NpFwFew6RqoU0W6OjSPMcnaGATHPsoeb7+pzZ5tMeGK7rt6rCSnkUqvYQM1YqRU6HE454zszHBFZ6q+o4FLnst7UvAkaIUjy5S5HG1zljaXbHPW5TEsLgiZU5ovIsult+83p2LOgkggVyyYdhVpiH4qStuW5E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DI1/gcF7; arc=none smtp.client-ip=209.85.218.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DI1/gcF7" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-aa55171d73cso188350666b.0 for ; Wed, 27 Nov 2024 08:28:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732724933; x=1733329733; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=zmhvgX5BH9CzW1HnudCRhcXTQ7nywhYaIjRkUW8X3hQ=; b=DI1/gcF7mu1lRhH2QLIDJ07r5WJUSKerK9TVSjpSGLfupf4xW3VxyAFrE5oHSGJigG 1e69716roNyytZYL5iKtzcBpaOc/7bbCmyzt/H1yZIeMqzHlAr1dlCtX5CSLXGLc6Z7D qDJJcWKWzkl9SgcZ1Wd8xHfkMcitE9Ss7vGlL4Y18NftHTOoZiSbquUkrgIB6nyQjduR cB+loVM8dyqqz+8mv4VSJoq8dnzlA0JsHnPoL6iZT7kTWVZmEUlGgEpcTLu2kQSO04XK tuuRRQQT0S1LQfgBeZv5O0NcF7eXSZbapulCATR0I8LGf83OcEzrBp0QTiYpSENRe8fe XTJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732724933; x=1733329733; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zmhvgX5BH9CzW1HnudCRhcXTQ7nywhYaIjRkUW8X3hQ=; b=aAQk2v42/q6agOsHSgw1zk/Zld0JezEjBjOthZgboEhgeiPmyjpV/syac5xYB1CdYu XzluZiIVhRWqjSKxb5pw/+AQX3vSrzJnelDnE9uAd9kzGFfsw7K4yh92XeGYyX/X13pg xmmB/Y66xYXqXV2usKWwvJ31UlLvkK0ZiIMBbEZNKYYCgkdd18zQYeOV3Z1HD2fprPgq PjV7dLuOD68hF2yA7938TmsjrGIe4wpgNligOHA7RplRGKFxmpzEVXe93vXH9LKgkajm kehafiTZOUG6icIrcMmBz44KLVigZ2pYvh8qPjYtp9Ymd5Z2H2qabS9S44pvMrf0Thu+ R6jA== X-Gm-Message-State: AOJu0YxC72sHq6o29et5kOvsF5ZaukC3K/NcCksNgTUfabL8IF4soudu cTWeAUJhWp3+wno7ssrnOoNCOjLpZ73O7qRABZiyZVZ/53OwFRlR X-Gm-Gg: ASbGncuFXElpuwbFPYGaqv6qi7ZqcCQxvsGN30GUAnbtsSZlf4U6VJq2bONIfM/MIOW dK8NhUT59CQCPni6sF83/lYak4m8/PRStR2WHqU7vvpaEAwmHJSE8/HnYvP3d+6BLGRgNBpyxUD UV4Ntr6/blxKIN5cMTIfOF75+m53YHHdfZOksj9Sk2qvs4qpHWnLmZ8MbKRTCw0ZnzIAMEX0Bw2 JkEF6qmDBRaar0RK8VNIsXOHYfhL4cFtDlyEFZodrb/pbxt7Ixy/7Elvl2KPg== X-Google-Smtp-Source: AGHT+IEmmX4dhWcTyAFwKhp0C26iSzKhpSdJPYQ01t2+bsKazNvTnJTWQnG0+fPixf8YCNfy7qwjHA== X-Received: by 2002:a17:906:3147:b0:aa5:4d1c:78aa with SMTP id a640c23a62f3a-aa57fa9a3e5mr309955166b.5.1732724932854; Wed, 27 Nov 2024 08:28:52 -0800 (PST) Received: from [192.168.178.20] ([2a02:2455:825d:6a00:5640:4a6:5555:68ae]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa54e15c169sm420042366b.67.2024.11.27.08.28.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 08:28:52 -0800 (PST) From: Karthik Nayak Date: Wed, 27 Nov 2024 17:28:31 +0100 Subject: [PATCH v3 6/8] midx: pass `repository` to `load_multi_pack_index` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-6-c5a99f85009b@gmail.com> References: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com> In-Reply-To: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , me@ttaylorr.com, shejialuo@gmail.com, gitster@pobox.com, Christian Couder X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4558; i=karthik.188@gmail.com; h=from:subject:message-id; bh=6a1VFJPVXDs5jabZQCbDZTOicBHDx9PUoLnrc0lGE08=; b=owEB7QES/pANAwAIAT7VnySORox/AcsmYgBnR0i93yidHj62B6JEkhTM9it3KmqGTT9mpV71W f4+4CN7VsqJAbMEAAEIAB0WIQRXzkx/Y3VxD8tlxgY+1Z8kjkaMfwUCZ0dIvQAKCRA+1Z8kjkaM f0kjDACLad5qRmJXbjvvh9XRgErI3UEDNhJkxCHY070P24dXH+HcUqnkkyqjHg0CakDhcWE1iyW HC5xWl8UNv6Pb4jes0EYhVWWfNu9tZFNuyPTJqWj01VJAl4SDsUBFZlGYMgjEq+VttB0wiwv1YK Inl2oq7wxelE+hRqSBtWiHLU17v5Wu9plnQToG5UvX113SJySsu4TnehHJnVfyXRkdrkTkQ61OW tR8OlFEOHzABwyQC92V+lxKKVUWY9mQ7nB/IH/OE+FU/oZcyKiR07Ytu4OI04vxyjTnwlH4mM90 KTsCwzGXOYjjC9NzFnJnb/LNA9xTz7u7TE+nnL7BjE9MeS26G2h2i7i/m5dxXvj3tr8hMN6Hdyc zMmtoJ4TF//daOmEP4+fkqdjVbdbSDVmLFDn9JOPouTZnmSBSVpblbi4x0PhkKwOeaZsv4SJnuj jq3m50q36hjU79lLQ1pKjEQLEzC9OKmnaVYc8tE5wV3iq/cJYTxb5EDGiviCRNgvESSD0= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F The `load_multi_pack_index` function in midx uses `the_repository` variable to access the `repository` struct. Modify the function and its callee's to send the `repository` field. This moves usage of `the_repository` to the `test-read-midx.c` file. While that is not optimal, it is okay, since the upcoming commits will slowly move the usage of `the_repository` up the layers and remove it eventually. Signed-off-by: Karthik Nayak --- midx.c | 11 ++++++----- midx.h | 4 +++- t/helper/test-read-midx.c | 8 ++++---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/midx.c b/midx.c index 6f0fb8285af14843da132ef1b0c3a8bdd06732c9..98ee84d4a8bf388906634ad695ff39acdaa2c6d5 100644 --- a/midx.c +++ b/midx.c @@ -372,7 +372,8 @@ static struct multi_pack_index *load_multi_pack_index_chain(struct repository *r return m; } -struct multi_pack_index *load_multi_pack_index(const char *object_dir, +struct multi_pack_index *load_multi_pack_index(struct repository *r, + const char *object_dir, int local) { struct strbuf midx_name = STRBUF_INIT; @@ -380,10 +381,10 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, get_midx_filename(&midx_name, object_dir); - m = load_multi_pack_index_one(the_repository, object_dir, + m = load_multi_pack_index_one(r, object_dir, midx_name.buf, local); if (!m) - m = load_multi_pack_index_chain(the_repository, object_dir, local); + m = load_multi_pack_index_chain(r, object_dir, local); strbuf_release(&midx_name); @@ -727,7 +728,7 @@ int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, i if (!strcmp(object_dir, m_search->object_dir)) return 1; - m = load_multi_pack_index(object_dir, local); + m = load_multi_pack_index(r, object_dir, local); if (m) { struct multi_pack_index *mp = r->objects->multi_pack_index; @@ -881,7 +882,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag struct pair_pos_vs_id *pairs = NULL; uint32_t i; struct progress *progress = NULL; - struct multi_pack_index *m = load_multi_pack_index(object_dir, 1); + struct multi_pack_index *m = load_multi_pack_index(r, object_dir, 1); struct multi_pack_index *curr; verify_midx_error = 0; diff --git a/midx.h b/midx.h index c37ad5b5242b56d21fd76bd59957a1bdb82786ec..78efa28d35371795fa33c68660278182debb60ab 100644 --- a/midx.h +++ b/midx.h @@ -97,7 +97,9 @@ void get_midx_chain_filename(struct strbuf *buf, const char *object_dir); void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir, const unsigned char *hash, const char *ext); -struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local); +struct multi_pack_index *load_multi_pack_index(struct repository *r, + const char *object_dir, + int local); int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id); struct packed_git *nth_midxed_pack(struct multi_pack_index *m, uint32_t pack_int_id); diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c index 438fb9fc6197fc465f79d9a65b719ae315fed373..fc632369618917e2d8cdcb77bd9073c61e1544c1 100644 --- a/t/helper/test-read-midx.c +++ b/t/helper/test-read-midx.c @@ -18,7 +18,7 @@ static int read_midx_file(const char *object_dir, const char *checksum, struct multi_pack_index *m; setup_git_directory(); - m = load_multi_pack_index(object_dir, 1); + m = load_multi_pack_index(the_repository, object_dir, 1); if (!m) return 1; @@ -82,7 +82,7 @@ static int read_midx_checksum(const char *object_dir) struct multi_pack_index *m; setup_git_directory(); - m = load_multi_pack_index(object_dir, 1); + m = load_multi_pack_index(the_repository, object_dir, 1); if (!m) return 1; printf("%s\n", hash_to_hex(get_midx_checksum(m))); @@ -98,7 +98,7 @@ static int read_midx_preferred_pack(const char *object_dir) setup_git_directory(); - midx = load_multi_pack_index(object_dir, 1); + midx = load_multi_pack_index(the_repository, object_dir, 1); if (!midx) return 1; @@ -121,7 +121,7 @@ static int read_midx_bitmapped_packs(const char *object_dir) setup_git_directory(); - midx = load_multi_pack_index(object_dir, 1); + midx = load_multi_pack_index(the_repository, object_dir, 1); if (!midx) return 1; From patchwork Wed Nov 27 16:28:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak X-Patchwork-Id: 13887203 Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 096A7201254 for ; Wed, 27 Nov 2024 16:28:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732724938; cv=none; b=r4ZYexQP6A+ITDx+jDSc/UEzdeh+xlUG/XUB8CrWUMLyT7tRX7PWwnzAWEB7L1gtgUNCodCGmpdkNmMQ10zGaXYAQFp8y2kqsSuW1wQYvOJqai+Wud94MR7gKI608Z8utjfdTkzwqlOmBxR5fhweTrpbDVbpTYmowVpZXi3N/R8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732724938; c=relaxed/simple; bh=n19tvsNW1npTe5NQigUJDHmot0AeqiD8X2PFNQEfTMQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lZoWlnpCkOl189ul9gxbBKJWddrbchirTDmI1INcQolhi40lh4DW+HVJTRvEEEiS7rDPtKLbbJnJKNxhqWaZ1qbQHxJseW8pvQEQG5dgG+8yePATRdUOB+o5tAMPOpNqMi1ONU7BxuCbvm+S0nR0sXZVxsnxcaVEjKnStrnpLZU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TQHCRm7b; arc=none smtp.client-ip=209.85.208.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TQHCRm7b" Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-2ffc76368c6so57273541fa.0 for ; Wed, 27 Nov 2024 08:28:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732724934; x=1733329734; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=AhNLTWXd1NC9bu1omIgB7Do6rMNk3uMqDdx7Y//kVQs=; b=TQHCRm7bwjKo/+JBGmeUUXs20/Y9OD+WsfPEu/4Mpjw9sCKjF7cgAwJUhG8VtG8ufP VILOFrPQfTpwNr9heXPJYsgSPu8iyDQsYN2QAtruiK3m53EKL4B5rMF98baDl37SJFxF HLC1WsT2Wn9wnKhwNHZhA4FMSNRZGd6rj5LZ4w1MuHAfOhwEuzqBQJ+kzXEQJYWcEttu OFQU/Ttui1j6ifOVBe+Zmoha6wEhA0LL5mFd3mlcdXO/SXEd86+1a2/7FYRt2ALxuRpU nzOjtbbsc+rHwEfCtBwYVGLvdGuhHqX/v/mAFJK3o9kfxF1Wo4oJDkAFL/GiybrgKQan FmeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732724934; x=1733329734; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AhNLTWXd1NC9bu1omIgB7Do6rMNk3uMqDdx7Y//kVQs=; b=XeyuquovrViNLe0OIUnwlJACm5NA/nPS2RkFjSkMIScTQbH1AovwlUJPQbjb5+Reaj BCuBvdayJ32tG6reLClANUtIB7ucQgQ8rKLVp/6iZAytOLT5YXB+h9uUk2ev8q1sun/i wfKaLl3n2pP15rT+23CPe9X8HDY9ecE4cX2LnEn1Z0t6Fh5go/a0JwLqh1ZSGttyLziM JW1qoovmUxF1H6oc4p74YK0XF65HkT9yrQhHwQDRJOFDK1WwrVsNk2O/4/EtICnykKUW tqLfYI4kssWKDtJ+EQdjKy/RXcAfdDpzegMmtjE+M3Y4jHETgc2JpAINdnewYxNw1wfX emsw== X-Gm-Message-State: AOJu0YzsIokJ+VHA1VazTf6Q6w3+OtZkBCK6W5Zjmm039+xDgp9u4KaQ 4OuSQr/RXHJwjuq4nHCBQNhIVkaa7gyOth4qzi1U0ZReiicytSwg X-Gm-Gg: ASbGncuTMyiiqMzIJ8d/Kv9+O0CejGTsuVoEe1AQTNgl0cCtyVBfioQtntDkg77bURH pph27hzpa7o3xisdxRyoCwEalCN9FObF/nVp4u7+J+gQUJa59MriRZTeIePQz0GE0gjVj1OZQVY 6BbCFSta1kq5e+JUnMTGHsnK3fKVP3Ei+G1AYrAnpFdD8Nstmdt51GTAfPFITIcno1nnfVtxPYw Oq0WAljkczsEF4W2AIjHXRmVGNGUu29AoWUkrmesqbUoHmZ34o7LgcuSwQ0ag== X-Google-Smtp-Source: AGHT+IEEveiI27v2KWj5JuTExYbq9T5i7DPkAOYJOgA2bZpZKwiMn6apgQhog95lr9dj2FcptCx9IQ== X-Received: by 2002:a05:651c:1142:b0:2fa:fcf0:7c2a with SMTP id 38308e7fff4ca-2ffd6050a56mr30147731fa.24.1732724933941; Wed, 27 Nov 2024 08:28:53 -0800 (PST) Received: from [192.168.178.20] ([2a02:2455:825d:6a00:5640:4a6:5555:68ae]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa54e15c169sm420042366b.67.2024.11.27.08.28.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 08:28:53 -0800 (PST) From: Karthik Nayak Date: Wed, 27 Nov 2024 17:28:32 +0100 Subject: [PATCH v3 7/8] midx: pass down `hash_algo` to functions using global variables Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-7-c5a99f85009b@gmail.com> References: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com> In-Reply-To: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , me@ttaylorr.com, shejialuo@gmail.com, gitster@pobox.com, Christian Couder X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=9860; i=karthik.188@gmail.com; h=from:subject:message-id; bh=n19tvsNW1npTe5NQigUJDHmot0AeqiD8X2PFNQEfTMQ=; b=owEB7QES/pANAwAIAT7VnySORox/AcsmYgBnR0i9H9j6MkbPF1+TJTfNLMBvQz+fH8VdGo6Q+ 6bIRuwr4bGJAbMEAAEIAB0WIQRXzkx/Y3VxD8tlxgY+1Z8kjkaMfwUCZ0dIvQAKCRA+1Z8kjkaM f0BFC/44m3p4ooCW0Z/rkLApOfkPEpQhuCfhrf8Rs3BNkYLfFKDTz8GgJZzSotlnQJPCdbbwIe3 ZLbUrrVN8E0pP2sOHCV7Uo8E3KAsoCOlnG2TdE0FGeUnm3kXI1VKN3Bd33nSJpVUXH7UQBAjJYJ /5AdFM+sEH2FhOtY+qVjZeF4TGJVUGODUuSDwtcSAQ5+es4BZiqGUQ+Q0BmCjEGWY8zenL9ju3f 2YBj28aIk0TmQmNj48BfHbRB6yeRejNFaY/eX5L96Zwb4/5Z8ldOzHlcfon2bYGYoF4Wcv0HsCi DB2e3rMTlcgqHP9MitVkT2vnvEz5S/0eVCOjq9J9PrbEO2dCVS8cTUvOpPEa5D+w0LYAntjFN66 Kekss1YHjy5uvubcEPO0TREUwiPTAYicN5O+ID/IVfqiC73d97CoTCmkrd55djI8fHOAusZ/rlW rOzUAl7iASq0ePtpsNxD+ssDqueSmB8BcJ8JW4iyCA2dwsdXd3hWhcejyZgdR7pTEPF2c= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F The functions `get_split_midx_filename_ext()`, `get_midx_filename()` and `get_midx_filename_ext()` use `hash_to_hex()` which internally uses the `the_hash_algo` global variable. Remove this dependency on global variables by passing down the `hash_algo` through to the functions mentioned and instead calling `hash_to_hex_algop()` along with the obtained `hash_algo`. Signed-off-by: Karthik Nayak --- midx-write.c | 22 +++++++++++----------- midx.c | 26 +++++++++++++++----------- midx.h | 10 +++++++--- pack-bitmap.c | 6 +++--- pack-revindex.c | 2 +- 5 files changed, 37 insertions(+), 29 deletions(-) diff --git a/midx-write.c b/midx-write.c index 1bc2f5256916e69924245951f654c1047ffeab84..bcd1d50eb0f5c292c904a38f13279b1ebec9c855 100644 --- a/midx-write.c +++ b/midx-write.c @@ -991,9 +991,10 @@ static int link_midx_to_chain(struct multi_pack_index *m) for (i = 0; i < ARRAY_SIZE(midx_exts); i++) { const unsigned char *hash = get_midx_checksum(m); - get_midx_filename_ext(&from, m->object_dir, hash, - midx_exts[i].non_split); - get_split_midx_filename_ext(&to, m->object_dir, hash, + get_midx_filename_ext(m->repo->hash_algo, &from, m->object_dir, + hash, midx_exts[i].non_split); + get_split_midx_filename_ext(m->repo->hash_algo, &to, + m->object_dir, hash, midx_exts[i].split); if (link(from.buf, to.buf) < 0 && errno != ENOENT) { @@ -1012,9 +1013,8 @@ static int link_midx_to_chain(struct multi_pack_index *m) return ret; } -static void clear_midx_files(const char *object_dir, - const char **hashes, - uint32_t hashes_nr, +static void clear_midx_files(struct repository *r, const char *object_dir, + const char **hashes, uint32_t hashes_nr, unsigned incremental) { /* @@ -1039,7 +1039,7 @@ static void clear_midx_files(const char *object_dir, } if (incremental) - get_midx_filename(&buf, object_dir); + get_midx_filename(r->hash_algo, &buf, object_dir); else get_midx_chain_filename(&buf, object_dir); @@ -1083,7 +1083,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir, "%s/pack/multi-pack-index.d/tmp_midx_XXXXXX", object_dir); else - get_midx_filename(&midx_name, object_dir); + get_midx_filename(r->hash_algo, &midx_name, object_dir); if (safe_create_leading_directories(midx_name.buf)) die_errno(_("unable to create leading directories of %s"), midx_name.buf); @@ -1440,8 +1440,8 @@ static int write_midx_internal(struct repository *r, const char *object_dir, if (link_midx_to_chain(ctx.base_midx) < 0) return -1; - get_split_midx_filename_ext(&final_midx_name, object_dir, - midx_hash, MIDX_EXT_MIDX); + get_split_midx_filename_ext(r->hash_algo, &final_midx_name, + object_dir, midx_hash, MIDX_EXT_MIDX); if (rename_tempfile(&incr, final_midx_name.buf) < 0) { error_errno(_("unable to rename new multi-pack-index layer")); @@ -1474,7 +1474,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir, if (commit_lock_file(&lk) < 0) die_errno(_("could not write multi-pack-index")); - clear_midx_files(object_dir, keep_hashes, + clear_midx_files(r, object_dir, keep_hashes, ctx.num_multi_pack_indexes_before + 1, ctx.incremental); diff --git a/midx.c b/midx.c index 98ee84d4a8bf388906634ad695ff39acdaa2c6d5..f45ea842cd6eda23d2eadc9deaae43839aef24c1 100644 --- a/midx.c +++ b/midx.c @@ -28,17 +28,19 @@ const unsigned char *get_midx_checksum(struct multi_pack_index *m) return m->data + m->data_len - m->repo->hash_algo->rawsz; } -void get_midx_filename(struct strbuf *out, const char *object_dir) +void get_midx_filename(const struct git_hash_algo *hash_algo, + struct strbuf *out, const char *object_dir) { - get_midx_filename_ext(out, object_dir, NULL, NULL); + get_midx_filename_ext(hash_algo, out, object_dir, NULL, NULL); } -void get_midx_filename_ext(struct strbuf *out, const char *object_dir, +void get_midx_filename_ext(const struct git_hash_algo *hash_algo, + struct strbuf *out, const char *object_dir, const unsigned char *hash, const char *ext) { strbuf_addf(out, "%s/pack/multi-pack-index", object_dir); if (ext) - strbuf_addf(out, "-%s.%s", hash_to_hex(hash), ext); + strbuf_addf(out, "-%s.%s", hash_to_hex_algop(hash, hash_algo), ext); } static int midx_read_oid_fanout(const unsigned char *chunk_start, @@ -234,11 +236,13 @@ void get_midx_chain_filename(struct strbuf *buf, const char *object_dir) strbuf_addstr(buf, "/multi-pack-index-chain"); } -void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir, +void get_split_midx_filename_ext(const struct git_hash_algo *hash_algo, + struct strbuf *buf, const char *object_dir, const unsigned char *hash, const char *ext) { get_midx_chain_dirname(buf, object_dir); - strbuf_addf(buf, "/multi-pack-index-%s.%s", hash_to_hex(hash), ext); + strbuf_addf(buf, "/multi-pack-index-%s.%s", + hash_to_hex_algop(hash, hash_algo), ext); } static int open_multi_pack_index_chain(const struct git_hash_algo *hash_algo, @@ -326,8 +330,8 @@ static struct multi_pack_index *load_midx_chain_fd_st(struct repository *r, valid = 0; strbuf_reset(&buf); - get_split_midx_filename_ext(&buf, object_dir, layer.hash, - MIDX_EXT_MIDX); + get_split_midx_filename_ext(r->hash_algo, &buf, object_dir, + layer.hash, MIDX_EXT_MIDX); m = load_multi_pack_index_one(r, object_dir, buf.buf, local); if (m) { @@ -379,7 +383,7 @@ struct multi_pack_index *load_multi_pack_index(struct repository *r, struct strbuf midx_name = STRBUF_INIT; struct multi_pack_index *m; - get_midx_filename(&midx_name, object_dir); + get_midx_filename(r->hash_algo, &midx_name, object_dir); m = load_multi_pack_index_one(r, object_dir, midx_name.buf, local); @@ -822,7 +826,7 @@ void clear_midx_file(struct repository *r) { struct strbuf midx = STRBUF_INIT; - get_midx_filename(&midx, r->objects->odb->path); + get_midx_filename(r->hash_algo, &midx, r->objects->odb->path); if (r->objects && r->objects->multi_pack_index) { close_midx(r->objects->multi_pack_index); @@ -891,7 +895,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag struct stat sb; struct strbuf filename = STRBUF_INIT; - get_midx_filename(&filename, object_dir); + get_midx_filename(r->hash_algo, &filename, object_dir); if (!stat(filename.buf, &sb)) { error(_("multi-pack-index file exists, but failed to parse")); diff --git a/midx.h b/midx.h index 78efa28d35371795fa33c68660278182debb60ab..9d1374cbd58d016bb82338337b2a4e5ba7234092 100644 --- a/midx.h +++ b/midx.h @@ -7,6 +7,7 @@ struct object_id; struct pack_entry; struct repository; struct bitmapped_pack; +struct git_hash_algo; #define MIDX_SIGNATURE 0x4d494458 /* "MIDX" */ #define MIDX_VERSION 1 @@ -89,12 +90,15 @@ struct multi_pack_index { #define MIDX_EXT_MIDX "midx" const unsigned char *get_midx_checksum(struct multi_pack_index *m); -void get_midx_filename(struct strbuf *out, const char *object_dir); -void get_midx_filename_ext(struct strbuf *out, const char *object_dir, +void get_midx_filename(const struct git_hash_algo *hash_algo, + struct strbuf *out, const char *object_dir); +void get_midx_filename_ext(const struct git_hash_algo *hash_algo, + struct strbuf *out, const char *object_dir, const unsigned char *hash, const char *ext); void get_midx_chain_dirname(struct strbuf *buf, const char *object_dir); void get_midx_chain_filename(struct strbuf *buf, const char *object_dir); -void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir, +void get_split_midx_filename_ext(const struct git_hash_algo *hash_algo, + struct strbuf *buf, const char *object_dir, const unsigned char *hash, const char *ext); struct multi_pack_index *load_multi_pack_index(struct repository *r, diff --git a/pack-bitmap.c b/pack-bitmap.c index 0cb1b56c9d5a55936ba53e2ff904ffe46cdcbafc..7b62d099cab5729a60a36b3ad15276fdc351aa97 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -375,8 +375,8 @@ static int load_bitmap_entries_v1(struct bitmap_index *index) char *midx_bitmap_filename(struct multi_pack_index *midx) { struct strbuf buf = STRBUF_INIT; - get_midx_filename_ext(&buf, midx->object_dir, get_midx_checksum(midx), - MIDX_EXT_BITMAP); + get_midx_filename_ext(midx->repo->hash_algo, &buf, midx->object_dir, + get_midx_checksum(midx), MIDX_EXT_BITMAP); return strbuf_detach(&buf, NULL); } @@ -415,7 +415,7 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git, if (bitmap_git->pack || bitmap_git->midx) { struct strbuf buf = STRBUF_INIT; - get_midx_filename(&buf, midx->object_dir); + get_midx_filename(midx->repo->hash_algo, &buf, midx->object_dir); trace2_data_string("bitmap", bitmap_repo(bitmap_git), "ignoring extra midx bitmap file", buf.buf); close(fd); diff --git a/pack-revindex.c b/pack-revindex.c index 22d3c2346488de6279b6f26a69fe611106c1365a..d3832478d99edffae17db0bbe85aa981c1a3ad30 100644 --- a/pack-revindex.c +++ b/pack-revindex.c @@ -383,7 +383,7 @@ int load_midx_revindex(struct multi_pack_index *m) trace2_data_string("load_midx_revindex", the_repository, "source", "rev"); - get_midx_filename_ext(&revindex_name, m->object_dir, + get_midx_filename_ext(m->repo->hash_algo, &revindex_name, m->object_dir, get_midx_checksum(m), MIDX_EXT_REV); ret = load_revindex_from_disk(revindex_name.buf, From patchwork Wed Nov 27 16:28:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak X-Patchwork-Id: 13887204 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10F8D200BB2 for ; Wed, 27 Nov 2024 16:28:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732724938; cv=none; b=PQNfK7khUZ/ljL9Ltfy2lOqH+2qLLANFZHZnQguMq9gP79npVOAjeGrvxbd7014dJibo0z4ZSMgLSF4qm7rdFL5qcs8UAHnEfTNkpuaTWxtZ5Waw+a6VAashGdIHGAEzaQ7bmAgvut3yiVNUeWeeYlxPUhHzUG++G3CxCwScg2E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732724938; c=relaxed/simple; bh=ALtIPsVKuN24FpmdBtyyIxZBuI8AmmwfyzoSJDxXdZM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=o6iPpVjFKRtFYToSVRas6D9mbz4xFnMeGPo3r3elHx8nWfsCHerJMAfS3t5f/zcC71J6OUofzkwL/IUZn8omZR0zDgNNMkokkP3UXajF3axeRMIUiU0gAJA83kMCSLVajSMnafgog7r0ZZgM33xHZaPlDYeM2e0wVPIkr8GqaC0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cztQmisG; arc=none smtp.client-ip=209.85.208.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cztQmisG" Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2ffa3e8e917so71939891fa.3 for ; Wed, 27 Nov 2024 08:28:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732724935; x=1733329735; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=E+o8hu8d5M0kbQgCi7Axhk0NHXksch1V1MaEESJHbew=; b=cztQmisGPx8JNEW4Ijc3v+f2uAGT8VUsqJpK1R7t6HtuUCMb8C1fzuwqHLqnmo4JFJ O05oX8dNhv+GXRqoy83aufKjByJYoR+e7O+HwJVgDZxWppQK3ubZhmPrkfrHKShCc9GJ 4uY/1UhtG1mI5uaBgWPe2FPiTDQQYP7lMW+Oyk86zcqg5fFnOMIpY4nrryORPQN4T8vP +PqKoHrq+IwmabaXAnUQKZeUfx1SGUHeQLnOnz3eV+vuT/fyk6ZqRchjbjdWnM/AXn86 Ir8o2gILr9+cGLyBItnPmKeKLSVB2BAJpRe9vdzwJSjL1TDQkT8MEpG1pij5zk5EWeV7 1qJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732724935; x=1733329735; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E+o8hu8d5M0kbQgCi7Axhk0NHXksch1V1MaEESJHbew=; b=sqqLC+MvS84bC81zz4CvvLlIaDO9ECr8veRAlO5d3cwlnShvi1AyOsQ/9ZTUZCrmfN HqeLCMl2TFTQkcFmenX8JoXRA49mSiwJgYjVlZYvsutviKlfdxfEdZO7kVcusjdYiEqz 1NzOBFh4EZ6R6lnRbOc31QTk9tdKdi12rJ9Rkqw+5dLxICAgmCKuWHD4d97zvTjOmVj+ xmboCVnWxHXGopCNml3/xlML4kdDxJatVeiRtxZawq9qLQ8Kpk2E3+ohkzNhe98EZgKJ 0fME7R1Jp4s/kFMvVZuxzNlbVJN30aRRdJUhl5Y/uneaDXQA5pg49Ge2BlmbeUFCC0DA HZOQ== X-Gm-Message-State: AOJu0Yxj7ujXrex7SjHgu+61Qnl5v10pjx8t5fn3tsuwR3A9RM6CgWBW +8PHdMXHbdb3E+14LqQEkLgSGZ6Wg/O9hxAHM5+zUdLoh2oTzJg2 X-Gm-Gg: ASbGncuSxfvyXpvizKy9XT6mCh8NvcQyAqmrukY9gEghzfkjO1gqVdY8FYEcGUD79Ek yRarhG8HPZ32LWPDI60PXp63Dvn2fzeBLPSvtSTIJRRHHyIhFZp0PGpDfyFH1iZ2zhoc3m3TjBe ZwhUfwBxMJShxsFyS/BqwdXTP972cQ2ENJACpT+qaz/k7DKho6dyLnoQEIt34TOuauC4TWbzP1g CWcD5BsWHWmgpMYyr2Bl01H8yGtgV2ncTuU+kBUB2dIjzFwf4mE/+lHXFX2vw== X-Google-Smtp-Source: AGHT+IErZ9mMnAq0suNqYPgtT2Ol1Vp7jC4DqduFY9b/K5vGYFd14KKwqhHP5f9hf8B3LZFdIU3B9A== X-Received: by 2002:a05:6512:3a8e:b0:53d:ed21:eeaf with SMTP id 2adb3069b0e04-53df00ff1a7mr2476368e87.44.1732724934878; Wed, 27 Nov 2024 08:28:54 -0800 (PST) Received: from [192.168.178.20] ([2a02:2455:825d:6a00:5640:4a6:5555:68ae]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa54e15c169sm420042366b.67.2024.11.27.08.28.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 08:28:54 -0800 (PST) From: Karthik Nayak Date: Wed, 27 Nov 2024 17:28:33 +0100 Subject: [PATCH v3 8/8] midx: inline the `MIDX_MIN_SIZE` definition Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-8-c5a99f85009b@gmail.com> References: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com> In-Reply-To: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , me@ttaylorr.com, shejialuo@gmail.com, gitster@pobox.com, Christian Couder X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1381; i=karthik.188@gmail.com; h=from:subject:message-id; bh=ALtIPsVKuN24FpmdBtyyIxZBuI8AmmwfyzoSJDxXdZM=; b=owEB7QES/pANAwAIAT7VnySORox/AcsmYgBnR0i9ZircOyhzPNu6sztIy4NrzVu3h3h8oUyli NmZZ6D/hM6JAbMEAAEIAB0WIQRXzkx/Y3VxD8tlxgY+1Z8kjkaMfwUCZ0dIvQAKCRA+1Z8kjkaM f9AzC/90LE8kX/NLbA0YYXCXqZiMR0iXJVH0Q1If2miIKh0ZdSZoGsExFb0XXfb+UTxOK0iI4uZ YktHQqOTRyhTDS0emTWaB1senFehoy9lB7yaI4Oa4Bkdtp9Hz+XWO3VmUO1GcQNYr1IyBD6dMph PQVLFpx8jxj/qx4NBeJbYXfrT+5xi52BrZMK5mRR4Q03SG62ESGs00UNb95wayA3ibOoozKpX0i /EhrKQJe9U/FTCBeQU6rbdiDumVG9vzEWgqtwg99tscsQy+pEqPE6t9q9rRwpRiaWl8bQcGQoJH ofitVH/bqAS6Ho+DG4CYM/RQVoU7d6VmY4X160CeY1gvValJ0Su0Ba2xXPZ/nbljPt317KwonbQ oWM5O3+KiCWkFutl7fBUgywuem74DvZV+2jHaTVSIRsqg819+LVi7RvkEd+vZ6dqR7gzQNOWWks /bL870S5dyuO3iUhWH9b4Vd3GaOTCbbaCEBEEssTzNaMsePe/tMvJQVdCPUiL+EzkkB/g= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F The `MIDX_MIN_SIZE` definition is used to check the midx_size in `local_multi_pack_index_one`. This definition relies on the `the_hash_algo` global variable. Inline this and remove the global variable usage. With this, remove `USE_THE_REPOSITORY_VARIABLE` usage from `midx.c`. Signed-off-by: Karthik Nayak --- midx.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/midx.c b/midx.c index f45ea842cd6eda23d2eadc9deaae43839aef24c1..e0eae1c25ec91f7db5670ff9bacdf0e195c35795 100644 --- a/midx.c +++ b/midx.c @@ -1,5 +1,3 @@ -#define USE_THE_REPOSITORY_VARIABLE - #include "git-compat-util.h" #include "config.h" #include "dir.h" @@ -94,8 +92,6 @@ static int midx_read_object_offsets(const unsigned char *chunk_start, return 0; } -#define MIDX_MIN_SIZE (MIDX_HEADER_SIZE + the_hash_algo->rawsz) - static struct multi_pack_index *load_multi_pack_index_one(struct repository *r, const char *object_dir, const char *midx_name, @@ -122,7 +118,7 @@ static struct multi_pack_index *load_multi_pack_index_one(struct repository *r, midx_size = xsize_t(st.st_size); - if (midx_size < MIDX_MIN_SIZE) { + if (midx_size < (MIDX_HEADER_SIZE + r->hash_algo->rawsz)) { error(_("multi-pack-index file %s is too small"), midx_name); goto cleanup_fail; }