From patchwork Thu Jan 16 11:35:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak via B4 Relay X-Patchwork-Id: 13941614 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 052B31DE88B for ; Thu, 16 Jan 2025 11:35:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737027320; cv=none; b=NtSK8rr7lyarSUe5hYThv/QpKkf8HG3hm8EUNqYv0Dlo4/W69IS5VWpU3zYkrK9PvabA7RgPD7edLm16jnBFCP2NvhHnopYV/lAS/NW3hT4ui5FJ+nKSyMnO09t/e63RtELEclF3sv+QjZZdvlE3cKAnyJT62AFLTk90VPzt3Go= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737027320; c=relaxed/simple; bh=e5QNhCCtivCRVUGSra1bkuTY7szUKnqwHCZi9KbKo+M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oRh4M6p8bqiSpBCDtluJBdxmt2ZZXzPUlPIRWiRTXkleU0DpYBSYcilB+8SOyvNZVXw6NPFTkykFtOOpNPIsK/5hv8dI5xiZZpK0l3Vh41ydwLfyHefmMknSM5kG2+AOqkGFg4SVlaHnGsI3C0eRZmu51oZoT8uhI+WhkwXtjQ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ekZeFesV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ekZeFesV" Received: by smtp.kernel.org (Postfix) with ESMTPS id A72B4C4CEE4; Thu, 16 Jan 2025 11:35:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737027319; bh=e5QNhCCtivCRVUGSra1bkuTY7szUKnqwHCZi9KbKo+M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=ekZeFesVXYRp/2YMdAicsefCywFDmeKV7f9m+296z+5/Zh9YRduYK28LnXTXsP+wd C9ib+xLysIOKauKfPZPHjxyFxggIntTN5qKaLq3OUfDnqPHtOAC6s2tUr0T62MTMMK hDHC/54W8LpyNu4lwA+vZs1mRRQQodZBPkOTfDtPUkktGSunCK8dkw/VGMzPuuoJ8b vgzLPQpy1PFFj3JOIBTkZ7qyAEBWiM7ce2N7hjICwmELhGoHUlsstfZdfiIJpH6o5t 5OK2mdNO0mSWMRu+PiImEyOan19Zza1AoSSPf03BW9GIUgWLX9V1y7YBWmwLPP5vFS e0q5jNqYeJ30Q== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99BC2C02183; Thu, 16 Jan 2025 11:35:19 +0000 (UTC) From: Karthik Nayak via B4 Relay Date: Thu, 16 Jan 2025 12:35:13 +0100 Subject: [PATCH 1/5] pack-write: pass hash_algo to `fixup_pack_header_footer()` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250116-kn-the-repo-cleanup-v1-1-a2f4c8e1c4c3@gmail.com> References: <20250116-kn-the-repo-cleanup-v1-0-a2f4c8e1c4c3@gmail.com> In-Reply-To: <20250116-kn-the-repo-cleanup-v1-0-a2f4c8e1c4c3@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=7847; i=karthik.188@gmail.com; h=from:subject:message-id; bh=Q3YTpVPctjeWQ1SI5ZHfabnjeICNZIAxFUmfeObUWxA=; b=owJ4nAHtARL+kA0DAAoBPtWfJI5GjH8ByyZiAGeI7vSMmsze+ZrRtdNaSaLr5Yi8zy0rZZGbv 3ZDeVLV1OaggYkBswQAAQoAHRYhBFfOTH9jdXEPy2XGBj7VnySORox/BQJniO70AAoJED7VnySO Rox/d8wL/jSKLJ8fiI5hd2W2G59G5HZILUNzEsmRLCRBRTF2n8HINOHA3cKMPw28xDuKEtZlDCE GWnvygUrjwhwKJ9uCkjAJ7XhvUbjcu1fE8DVk7UmufSmY2r+o02KcCJXJnEUpXkwdufcPg14KvA PIZGBmZZqVYYgPgdLnQcn43Yt/vsQOVfiEpVze38x8ovGbx0DraC8poQ7RCyEzvH9WUBBDbcrmZ iwMVyoJUyjRGXdWGDtD5GKMyVhyEWC/ndPhJryWPFaRB7NL1qPTqmHfsyoyeXXzZUFHUBwh/qwy K8oa1jhkJad5qflcgOFbRQgzJbe9gWZ4gHvxQmvIgvooD8jpTRgiOq/3i0WzC3u5wzJhz5WhRIa JZwvJIUmhq2Ss71UXZAD0vlQCvBCXyty0Q0wdYpZXJP7JWtnV5iUh2my3X/Md+UPB9yjmwRs3Pj sxXSluCW0vF49I94Bnvkummm4xFoAanEWtpZ4D8Ae9xTd8LV2L13GKkIKLwMHdMtGEGZHgi8UK5 rI= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F X-Endpoint-Received: by B4 Relay for karthik.188@gmail.com/default with auth_id=276 X-Original-From: Karthik Nayak Reply-To: karthik.188@gmail.com From: Karthik Nayak The `fixup_pack_header_footer()` function uses the global `the_hash_algo` variable to access the repository's hash function. To avoid global variable usage, pass the hash function from the layers above. Altough the layers above could have access to the hash function internally, simply pass in `the_hash_algo`. This avoids any compatibility issues and bubbles up global variable usage to upper layers which can be eventually resolved. Signed-off-by: Karthik Nayak --- builtin/fast-import.c | 7 ++++--- builtin/index-pack.c | 2 +- builtin/pack-objects.c | 5 +++-- bulk-checkin.c | 2 +- pack-write.c | 28 ++++++++++++++-------------- pack.h | 4 +++- 6 files changed, 26 insertions(+), 22 deletions(-) diff --git a/builtin/fast-import.c b/builtin/fast-import.c index 0f86392761abbe6acb217fef7f4fe7c3ff5ac1fa..6baf2b1b71e2443a7987a41e0cd246076682bf58 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -878,9 +878,10 @@ static void end_packfile(void) close_pack_windows(pack_data); finalize_hashfile(pack_file, cur_pack_oid.hash, FSYNC_COMPONENT_PACK, 0); - fixup_pack_header_footer(pack_data->pack_fd, pack_data->hash, - pack_data->pack_name, object_count, - cur_pack_oid.hash, pack_size); + fixup_pack_header_footer(the_hash_algo, pack_data->pack_fd, + pack_data->hash, pack_data->pack_name, + object_count, cur_pack_oid.hash, + pack_size); if (object_count <= unpack_limit) { if (!loosen_small_pack(pack_data)) { diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 0bef61c57232e198ba539cd44ec301d26dcb0eb8..6c5e3483f4fe67fb2e26132c55b1f8395d60c11f 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1390,7 +1390,7 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha strbuf_release(&msg); finalize_hashfile(f, tail_hash, FSYNC_COMPONENT_PACK, 0); hashcpy(read_hash, pack_hash, the_repository->hash_algo); - fixup_pack_header_footer(output_fd, pack_hash, + fixup_pack_header_footer(the_hash_algo, output_fd, pack_hash, curr_pack, nr_objects, read_hash, consumed_bytes-the_hash_algo->rawsz); if (!hasheq(read_hash, tail_hash, the_repository->hash_algo)) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index d51c021d99d9f470c04b7ec52565ab2f4c1c19ae..ffc62930b68c9b4152057572ede216381a4b0991 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1319,8 +1319,9 @@ static void write_pack_file(void) */ int fd = finalize_hashfile(f, hash, FSYNC_COMPONENT_PACK, 0); - fixup_pack_header_footer(fd, hash, pack_tmp_name, - nr_written, hash, offset); + fixup_pack_header_footer(the_hash_algo, fd, hash, + pack_tmp_name, nr_written, + hash, offset); close(fd); if (write_bitmap_index) { if (write_bitmap_index != WRITE_BITMAP_QUIET) diff --git a/bulk-checkin.c b/bulk-checkin.c index 5044cb7fa083d692a3797e2491c27b61ec44c69c..c4b085f57f74fb8b998576ac9d84fed9e01ed0ed 100644 --- a/bulk-checkin.c +++ b/bulk-checkin.c @@ -70,7 +70,7 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state) CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE); } else { int fd = finalize_hashfile(state->f, hash, FSYNC_COMPONENT_PACK, 0); - fixup_pack_header_footer(fd, hash, state->pack_tmp_name, + fixup_pack_header_footer(the_hash_algo, fd, hash, state->pack_tmp_name, state->nr_written, hash, state->offset); close(fd); diff --git a/pack-write.c b/pack-write.c index 98a8c0e7853d7b46b5ce9a9672e0249ff051b5f9..fc887850dfb9789132b8642733c6472944dbe32d 100644 --- a/pack-write.c +++ b/pack-write.c @@ -380,7 +380,8 @@ off_t write_pack_header(struct hashfile *f, uint32_t nr_entries) * partial_pack_sha1 can refer to the same buffer if the caller is not * interested in the resulting SHA1 of pack data above partial_pack_offset. */ -void fixup_pack_header_footer(int pack_fd, +void fixup_pack_header_footer(const struct git_hash_algo *hash_algo, + int pack_fd, unsigned char *new_pack_hash, const char *pack_name, uint32_t object_count, @@ -393,8 +394,8 @@ void fixup_pack_header_footer(int pack_fd, char *buf; ssize_t read_result; - the_hash_algo->init_fn(&old_hash_ctx); - the_hash_algo->init_fn(&new_hash_ctx); + hash_algo->init_fn(&old_hash_ctx); + hash_algo->init_fn(&new_hash_ctx); if (lseek(pack_fd, 0, SEEK_SET) != 0) die_errno("Failed seeking to start of '%s'", pack_name); @@ -406,9 +407,9 @@ void fixup_pack_header_footer(int pack_fd, pack_name); if (lseek(pack_fd, 0, SEEK_SET) != 0) die_errno("Failed seeking to start of '%s'", pack_name); - the_hash_algo->update_fn(&old_hash_ctx, &hdr, sizeof(hdr)); + hash_algo->update_fn(&old_hash_ctx, &hdr, sizeof(hdr)); hdr.hdr_entries = htonl(object_count); - the_hash_algo->update_fn(&new_hash_ctx, &hdr, sizeof(hdr)); + hash_algo->update_fn(&new_hash_ctx, &hdr, sizeof(hdr)); write_or_die(pack_fd, &hdr, sizeof(hdr)); partial_pack_offset -= sizeof(hdr); @@ -423,7 +424,7 @@ void fixup_pack_header_footer(int pack_fd, break; if (n < 0) die_errno("Failed to checksum '%s'", pack_name); - the_hash_algo->update_fn(&new_hash_ctx, buf, n); + hash_algo->update_fn(&new_hash_ctx, buf, n); aligned_sz -= n; if (!aligned_sz) @@ -432,13 +433,12 @@ void fixup_pack_header_footer(int pack_fd, if (!partial_pack_hash) continue; - the_hash_algo->update_fn(&old_hash_ctx, buf, n); + hash_algo->update_fn(&old_hash_ctx, buf, n); partial_pack_offset -= n; if (partial_pack_offset == 0) { unsigned char hash[GIT_MAX_RAWSZ]; - the_hash_algo->final_fn(hash, &old_hash_ctx); - if (!hasheq(hash, partial_pack_hash, - the_repository->hash_algo)) + hash_algo->final_fn(hash, &old_hash_ctx); + if (!hasheq(hash, partial_pack_hash, hash_algo)) die("Unexpected checksum for %s " "(disk corruption?)", pack_name); /* @@ -446,7 +446,7 @@ void fixup_pack_header_footer(int pack_fd, * pack, which also means making partial_pack_offset * big enough not to matter anymore. */ - the_hash_algo->init_fn(&old_hash_ctx); + hash_algo->init_fn(&old_hash_ctx); partial_pack_offset = ~partial_pack_offset; partial_pack_offset -= MSB(partial_pack_offset, 1); } @@ -454,9 +454,9 @@ void fixup_pack_header_footer(int pack_fd, free(buf); if (partial_pack_hash) - the_hash_algo->final_fn(partial_pack_hash, &old_hash_ctx); - the_hash_algo->final_fn(new_pack_hash, &new_hash_ctx); - write_or_die(pack_fd, new_pack_hash, the_hash_algo->rawsz); + hash_algo->final_fn(partial_pack_hash, &old_hash_ctx); + hash_algo->final_fn(new_pack_hash, &new_hash_ctx); + write_or_die(pack_fd, new_pack_hash, hash_algo->rawsz); fsync_component_or_die(FSYNC_COMPONENT_PACK, pack_fd, pack_name); } diff --git a/pack.h b/pack.h index a8da0406299bf267205256aaa8efb215f2ff73be..6d9d477adc83e83d9e9175ccf699c100b4c147c6 100644 --- a/pack.h +++ b/pack.h @@ -91,7 +91,9 @@ int check_pack_crc(struct packed_git *p, struct pack_window **w_curs, off_t offs int verify_pack_index(struct packed_git *); int verify_pack(struct repository *, struct packed_git *, verify_fn fn, struct progress *, uint32_t); off_t write_pack_header(struct hashfile *f, uint32_t); -void fixup_pack_header_footer(int, unsigned char *, const char *, uint32_t, unsigned char *, off_t); +void fixup_pack_header_footer(const struct git_hash_algo *, int, + unsigned char *, const char *, uint32_t, + unsigned char *, off_t); char *index_pack_lockfile(int fd, int *is_well_formed); struct ref; From patchwork Thu Jan 16 11:35:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak via B4 Relay X-Patchwork-Id: 13941615 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0530A1DE88C for ; Thu, 16 Jan 2025 11:35:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737027320; cv=none; b=fS0SyQrzoaLLrHf/psCRj5fbJPYNYPtRKDna+hkrUQIZ7ED8hXbtfhNx6AMdoobRfXCa25n7n4Om3DfNYx0cASoXOSUZYvm3m++KHMn9MoTS8apkVVcRThgv8M3IeAC6ZEoWL38Y0+/LCDTBaHDiwkBxNHjay9kUeF+qClOyJTM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737027320; c=relaxed/simple; bh=nfRLsLy/KZfnpWyvJ1W2OTuFJufJa/rRGAmfgo0Ysoo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rDqOXiNV9SQ6P/TA6oEstQpVBZeLVkWrDPFM6BE5BZq8stfAya9a/UI2HOmFsXIuiGKCtHNb5CKA6l9eG1TDmBWXU96C+NlpORcR+a5nuIt6+gV9IixwmbW8paOSss5PpWx3jg5ku3H6yV1ARuywfngjfTnKI3VMFtVG+eNssYY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GPO8O2xx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GPO8O2xx" Received: by smtp.kernel.org (Postfix) with ESMTPS id BA743C4CEE6; Thu, 16 Jan 2025 11:35:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737027319; bh=nfRLsLy/KZfnpWyvJ1W2OTuFJufJa/rRGAmfgo0Ysoo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=GPO8O2xxqN0sDLLXxxWNfc/noElhE6jMv7LlYhWA+vhIycR0Dkrj2ZtEbt2SPv/EK nLKwclvEDgX6v+tZSGcQNx4n9iDsv2/cTm8TXXtOQiO1S5RpoF3q2u8hczrP9RdzNx DIQ+m2M9aorn/JAdHY9ZCepRToOT656QVa9Sxm1qE3IwhnjAZl5dRprpKVotF1nxcL RrU6drupyejoa2YsF3Vneo7pd0/P9sarQGXIlGg/m66WEW/Y3PlxIZiR5RaoRZPMm3 pdmNxxF4t4oG/957hVvl3X7O0zLXFQ+RoAZ8KQjUiQe3SPVPsGqXRiZY4y7VjeUPPD 3rAG9nejNCNSg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9B85C02188; Thu, 16 Jan 2025 11:35:19 +0000 (UTC) From: Karthik Nayak via B4 Relay Date: Thu, 16 Jan 2025 12:35:14 +0100 Subject: [PATCH 2/5] pack-write: pass repository to `index_pack_lockfile()` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250116-kn-the-repo-cleanup-v1-2-a2f4c8e1c4c3@gmail.com> References: <20250116-kn-the-repo-cleanup-v1-0-a2f4c8e1c4c3@gmail.com> In-Reply-To: <20250116-kn-the-repo-cleanup-v1-0-a2f4c8e1c4c3@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3498; i=karthik.188@gmail.com; h=from:subject:message-id; bh=4+NcIvb9eGXZWFVkaGz25U3+N7Kc8XV6gLpT89ksQDA=; b=owJ4nAHtARL+kA0DAAoBPtWfJI5GjH8ByyZiAGeI7vXhuwr8JrGpb907ky1LbhEAU2s8a0Wn2 +E4ScLTlPXzmokBswQAAQoAHRYhBFfOTH9jdXEPy2XGBj7VnySORox/BQJniO71AAoJED7VnySO Rox/ZT4MAIfr+NVGqktnAehiZKd3Bhh30rRGf9Pjc8iO0DGdMFzzSVH6eKcSIJP3ysA9X2V5So6 FBvkaam15Bx1IMAYz2rM6ZyHJpeenupILx/ZFWTGbVEjvPNbIiizlKKZWn1ZMXL2u+kWCuSepXp fWnpP2GwtnSapNYD9aBTqSaX+NhP0C1SbGkGulsZDm1hLH1TOecGY0TJCm3VsneSVGS/0ivpAyo W8AmcnWzf7XiA+I3bcTR9sBbQuVtwn7TVQ42J0ciqCVwuIAG1nE4iFERqYLwk4d0opYzYC8Arjs JMKdoHEehrYe6f3EvZG8/6AqOfCAz/t/TcitUUjT4lkT+Ifi6NKQTUF4CsEgAaYW9HpOVetjcHF BFViuHMd2SRTiLZNa7z0u3UfC8Ep69WHl/bP+DTWQ9He8crFkSdBEdYVI1XAQGh6fclhUlAxeYx AlqgPvUXfVUAcIzC9Mp8YMNsE89Csz2hsBUzPDwI7LEx1n09w/0/JCVPf8N0xzstZGrZ9tcRfZ6 Fw= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F X-Endpoint-Received: by B4 Relay for karthik.188@gmail.com/default with auth_id=276 X-Original-From: Karthik Nayak Reply-To: karthik.188@gmail.com From: Karthik Nayak The `index_pack_lockfile()` function uses the global `the_repository` variable to access the repository. To avoid global variable usage, pass the repository from the layers above. Altough the layers above could have access to the hash function internally, simply pass in `the_hash_algo`. This avoids any compatibility issues and bubbles up global variable usage to upper layers which can be eventually resolved. Signed-off-by: Karthik Nayak --- builtin/receive-pack.c | 2 +- fetch-pack.c | 4 +++- pack-write.c | 6 +++--- pack.h | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 56347a79633505efe8dc05acf1583b4c9995eefe..b83abe5d220cefd3707b701409dc5e6b67566599 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -2304,7 +2304,7 @@ static const char *unpack(int err_fd, struct shallow_info *si) if (status) return "index-pack fork failed"; - lockfile = index_pack_lockfile(child.out, NULL); + lockfile = index_pack_lockfile(the_repository, child.out, NULL); if (lockfile) { pack_lockfile = register_tempfile(lockfile); free(lockfile); diff --git a/fetch-pack.c b/fetch-pack.c index 3a227721ed0935d1f9c40584c57f54043354c032..824f56ecbca11cd9e4da6a3e4c450c6b2e7078ab 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -1036,7 +1036,9 @@ static int get_pack(struct fetch_pack_args *args, die(_("fetch-pack: unable to fork off %s"), cmd_name); if (do_keep && (pack_lockfiles || fsck_objects)) { int is_well_formed; - char *pack_lockfile = index_pack_lockfile(cmd.out, &is_well_formed); + char *pack_lockfile = index_pack_lockfile(the_repository, + cmd.out, + &is_well_formed); if (!is_well_formed) die(_("fetch-pack: invalid index-pack output")); diff --git a/pack-write.c b/pack-write.c index fc887850dfb9789132b8642733c6472944dbe32d..0cd75d2e55419362a61cf981fc11117ea7a1d88a 100644 --- a/pack-write.c +++ b/pack-write.c @@ -460,10 +460,10 @@ void fixup_pack_header_footer(const struct git_hash_algo *hash_algo, fsync_component_or_die(FSYNC_COMPONENT_PACK, pack_fd, pack_name); } -char *index_pack_lockfile(int ip_out, int *is_well_formed) +char *index_pack_lockfile(struct repository *r, int ip_out, int *is_well_formed) { char packname[GIT_MAX_HEXSZ + 6]; - const int len = the_hash_algo->hexsz + 6; + const int len = r->hash_algo->hexsz + 6; /* * The first thing we expect from index-pack's output @@ -480,7 +480,7 @@ char *index_pack_lockfile(int ip_out, int *is_well_formed) packname[len-1] = 0; if (skip_prefix(packname, "keep\t", &name)) return xstrfmt("%s/pack/pack-%s.keep", - repo_get_object_directory(the_repository), name); + repo_get_object_directory(r), name); return NULL; } if (is_well_formed) diff --git a/pack.h b/pack.h index 6d9d477adc83e83d9e9175ccf699c100b4c147c6..46d85e5bec787c90af69700fd4b328b1ebf1d606 100644 --- a/pack.h +++ b/pack.h @@ -94,7 +94,7 @@ off_t write_pack_header(struct hashfile *f, uint32_t); void fixup_pack_header_footer(const struct git_hash_algo *, int, unsigned char *, const char *, uint32_t, unsigned char *, off_t); -char *index_pack_lockfile(int fd, int *is_well_formed); +char *index_pack_lockfile(struct repository *r, int fd, int *is_well_formed); struct ref; From patchwork Thu Jan 16 11:35:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak via B4 Relay X-Patchwork-Id: 13941617 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46EE11DE4DA for ; Thu, 16 Jan 2025 11:35:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737027320; cv=none; b=bHwKTrgT9yDtBakDp8h1LXTkMUDicsBPaIxdWriuzXqtjT6woZMNglE/Rp87Pkg3MBNKaIB13pil40mgJ4l2ICVxshNx0dbhYIr2I96pPth2ANahhtgAZHi8eZH9VmjwEzYxxGXIy2JPqAVVPA9RNGmKk2VMrQPO4V/6fO0zQ74= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737027320; c=relaxed/simple; bh=DeZzuyhEBqLFgJ8gcVT2krzsuOjoDIWjL3ueR3oRDdg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kvoGUymOuDpw0z8nQM7TMEp+P8Fk597GeLI5LYDv7G1PuM3wEw3WuP5BY95BwmnFGZk7/7tWgxRfNOdvqFj5zNHCny5ei93SeToYm1iudshLcvWb5bNTfp4QrClb/2B5Ft/f7QsV6YCsmEncwaDAEEPB9oqITQXSnEyAtC/5o5Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OiwTASDK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OiwTASDK" Received: by smtp.kernel.org (Postfix) with ESMTPS id D957AC4CEE7; Thu, 16 Jan 2025 11:35:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737027319; bh=DeZzuyhEBqLFgJ8gcVT2krzsuOjoDIWjL3ueR3oRDdg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=OiwTASDKMxyk5anRL+GetFFfbbM99mAmBNPOcB6TWsoSF0C3Ft9QXQLIgaxSjmZaT BBmuNF8bZNKmP014OHEwct0Kj3+fMXrBGOW5bdTdfh7p/q1W8GyUZehMBwvmycdmT1 89wXRlryFflXVLNRuZ2+9vaS/4dWz2Nblpco7r5EPj33T7hR1R95//3qzLWXEaWHPU m+ipJQye7+7Q8xYHQqQJZlPRpWtvUseOOU5LlwFJ+TVtGEeQdtJynPrRmdICJ2cBhZ Z4uIjqXlVYGN9X4tsDJj8mef9Ia5nHtcBYzTI0iwtcbGR6hHFWHcsH9Hmg9m/BNMEU 6w1/wXs1c3erw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D18AFC02183; Thu, 16 Jan 2025 11:35:19 +0000 (UTC) From: Karthik Nayak via B4 Relay Date: Thu, 16 Jan 2025 12:35:15 +0100 Subject: [PATCH 3/5] pack-write: pass hash_algo to `write_idx_file()` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250116-kn-the-repo-cleanup-v1-3-a2f4c8e1c4c3@gmail.com> References: <20250116-kn-the-repo-cleanup-v1-0-a2f4c8e1c4c3@gmail.com> In-Reply-To: <20250116-kn-the-repo-cleanup-v1-0-a2f4c8e1c4c3@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=7342; i=karthik.188@gmail.com; h=from:subject:message-id; bh=lgH6WSk//9YmVZiDA9JT771GFfmm1Z/I3oTlK5JxM7M=; b=owJ4nAHtARL+kA0DAAoBPtWfJI5GjH8ByyZiAGeI7vWfKA0RDW6FFbQZbZFenubzf2jJdmem+ 81DuVNryjoZUokBswQAAQoAHRYhBFfOTH9jdXEPy2XGBj7VnySORox/BQJniO71AAoJED7VnySO Rox/+RML/39AJtLVnEACAS6DrDZ/InCd3MzRssFCmyWdIp+9m4P+kos1WU+5nll5k6+XsV/mmFN a5K2+2aalhtpbSE4SH6c+v/juiTN4wNF/36KF+CXA7g4KBzRPQd/GvsKFBLmnbk/JDABhRAxEom G9gkdVxy8QBGHWpmwkU7Mm6cKwE1QoQTf7/y7eeUtPLiU6zQ6lskm1s8QLqUg+4w0+sIP5dDQWf gBGTT8m6Rl50N5ZHhY94BdUTzLiXrO4ehHGIs7BuLBUO/QMUyWufBqJyjR7TMy2i14k8Tat9ZS7 AVJ1XIf10AmMCKBcTSpKzLkLM18aGwGER5hL7WNHUDNMeeBFjdyzdhBpH6XLJkIax/n5oH2pJ5w 8/ol/JqGfRw8lQOaiOy2NghZDOnGfpDbkz7Go2qSxMNe4CUnfvui8ECsnGrAbgzSf65z+caN/Lh BKxlglbn6cXOc0771+0RxBFxowARMFc9phKON/+8d3RPw92+BFlmBcachYHj2QmQcSoI30hg4L3 sU= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F X-Endpoint-Received: by B4 Relay for karthik.188@gmail.com/default with auth_id=276 X-Original-From: Karthik Nayak Reply-To: karthik.188@gmail.com From: Karthik Nayak The `write_idx_file()` function uses the global `the_hash_algo` variable to access the repository's hash function. To avoid global variable usage, pass the hash function from the layers above. Altough the layers above could have access to the hash function internally, simply pass in `the_hash_algo`. This avoids any compatibility issues and bubbles up global variable usage to upper layers which can be eventually resolved. Signed-off-by: Karthik Nayak --- builtin/fast-import.c | 4 ++-- builtin/index-pack.c | 3 ++- builtin/pack-objects.c | 7 ++++--- bulk-checkin.c | 5 +++-- pack-write.c | 14 ++++++++------ pack.h | 10 ++++++++-- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/builtin/fast-import.c b/builtin/fast-import.c index 6baf2b1b71e2443a7987a41e0cd246076682bf58..c4bc52f93c011f34bd7f98c8e9d74a33cf9783bd 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -798,8 +798,8 @@ static const char *create_index(void) if (c != last) die("internal consistency error creating the index"); - tmpfile = write_idx_file(NULL, idx, object_count, &pack_idx_opts, - pack_data->hash); + tmpfile = write_idx_file(the_hash_algo, NULL, idx, object_count, + &pack_idx_opts, pack_data->hash); free(idx); return tmpfile; } diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 6c5e3483f4fe67fb2e26132c55b1f8395d60c11f..d73699653a2227f8ecfee2c0f51cd680093ac764 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -2096,7 +2096,8 @@ int cmd_index_pack(int argc, ALLOC_ARRAY(idx_objects, nr_objects); for (i = 0; i < nr_objects; i++) idx_objects[i] = &objects[i].idx; - curr_index = write_idx_file(index_name, idx_objects, nr_objects, &opts, pack_hash); + curr_index = write_idx_file(the_hash_algo, index_name, idx_objects, + nr_objects, &opts, pack_hash); if (rev_index) curr_rev_index = write_rev_file(rev_index_name, idx_objects, nr_objects, pack_hash, diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index ffc62930b68c9b4152057572ede216381a4b0991..7b2dacda514c29f5393b604f15d379abb81546c0 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1369,9 +1369,10 @@ static void write_pack_file(void) if (cruft) pack_idx_opts.flags |= WRITE_MTIMES; - stage_tmp_packfiles(&tmpname, pack_tmp_name, - written_list, nr_written, - &to_pack, &pack_idx_opts, hash, + stage_tmp_packfiles(the_hash_algo, &tmpname, + pack_tmp_name, written_list, + nr_written, &to_pack, + &pack_idx_opts, hash, &idx_tmp_name); if (write_bitmap_index) { diff --git a/bulk-checkin.c b/bulk-checkin.c index c4b085f57f74fb8b998576ac9d84fed9e01ed0ed..0d49889bfbb233d58fc094f5e2c2d2433dad9851 100644 --- a/bulk-checkin.c +++ b/bulk-checkin.c @@ -44,8 +44,9 @@ static void finish_tmp_packfile(struct strbuf *basename, { char *idx_tmp_name = NULL; - stage_tmp_packfiles(basename, pack_tmp_name, written_list, nr_written, - NULL, pack_idx_opts, hash, &idx_tmp_name); + stage_tmp_packfiles(the_hash_algo, basename, pack_tmp_name, + written_list, nr_written, NULL, pack_idx_opts, hash, + &idx_tmp_name); rename_tmp_packfile_idx(basename, &idx_tmp_name); free(idx_tmp_name); diff --git a/pack-write.c b/pack-write.c index 0cd75d2e55419362a61cf981fc11117ea7a1d88a..f344e78a9ec20cea9812a5eaffc72ae0b7e7424d 100644 --- a/pack-write.c +++ b/pack-write.c @@ -56,7 +56,8 @@ static int need_large_offset(off_t offset, const struct pack_idx_option *opts) * The *sha1 contains the pack content SHA1 hash. * The objects array passed in will be sorted by SHA1 on exit. */ -const char *write_idx_file(const char *index_name, struct pack_idx_entry **objects, +const char *write_idx_file(const struct git_hash_algo *hash_algo, + const char *index_name, struct pack_idx_entry **objects, int nr_objects, const struct pack_idx_option *opts, const unsigned char *sha1) { @@ -130,7 +131,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec struct pack_idx_entry *obj = *list++; if (index_version < 2) hashwrite_be32(f, obj->offset); - hashwrite(f, obj->oid.hash, the_hash_algo->rawsz); + hashwrite(f, obj->oid.hash, hash_algo->rawsz); if ((opts->flags & WRITE_IDX_STRICT) && (i && oideq(&list[-2]->oid, &obj->oid))) die("The same object %s appears twice in the pack", @@ -172,7 +173,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec } } - hashwrite(f, sha1, the_hash_algo->rawsz); + hashwrite(f, sha1, hash_algo->rawsz); finalize_hashfile(f, NULL, FSYNC_COMPONENT_PACK_METADATA, CSUM_HASH_IN_STREAM | CSUM_CLOSE | ((opts->flags & WRITE_IDX_VERIFY) ? 0 : CSUM_FSYNC)); @@ -546,7 +547,8 @@ void rename_tmp_packfile_idx(struct strbuf *name_buffer, rename_tmp_packfile(name_buffer, *idx_tmp_name, "idx"); } -void stage_tmp_packfiles(struct strbuf *name_buffer, +void stage_tmp_packfiles(const struct git_hash_algo *hash_algo, + struct strbuf *name_buffer, const char *pack_tmp_name, struct pack_idx_entry **written_list, uint32_t nr_written, @@ -561,8 +563,8 @@ void stage_tmp_packfiles(struct strbuf *name_buffer, if (adjust_shared_perm(pack_tmp_name)) die_errno("unable to make temporary pack file readable"); - *idx_tmp_name = (char *)write_idx_file(NULL, written_list, nr_written, - pack_idx_opts, hash); + *idx_tmp_name = (char *)write_idx_file(hash_algo, NULL, written_list, + nr_written, pack_idx_opts, hash); if (adjust_shared_perm(*idx_tmp_name)) die_errno("unable to make temporary index file readable"); diff --git a/pack.h b/pack.h index 46d85e5bec787c90af69700fd4b328b1ebf1d606..c650fdbe2dcde8055ad0efe55646338cd0f81df5 100644 --- a/pack.h +++ b/pack.h @@ -86,7 +86,12 @@ struct progress; /* Note, the data argument could be NULL if object type is blob */ typedef int (*verify_fn)(const struct object_id *, enum object_type, unsigned long, void*, int*); -const char *write_idx_file(const char *index_name, struct pack_idx_entry **objects, int nr_objects, const struct pack_idx_option *, const unsigned char *sha1); +const char *write_idx_file(const struct git_hash_algo *hash_algo, + const char *index_name, + struct pack_idx_entry **objects, + int nr_objects, + const struct pack_idx_option *, + const unsigned char *sha1); int check_pack_crc(struct packed_git *p, struct pack_window **w_curs, off_t offset, off_t len, unsigned int nr); int verify_pack_index(struct packed_git *); int verify_pack(struct repository *, struct packed_git *, verify_fn fn, struct progress *, uint32_t); @@ -119,7 +124,8 @@ int read_pack_header(int fd, struct pack_header *); struct packing_data; struct hashfile *create_tmp_packfile(char **pack_tmp_name); -void stage_tmp_packfiles(struct strbuf *name_buffer, +void stage_tmp_packfiles(const struct git_hash_algo *hash_algo, + struct strbuf *name_buffer, const char *pack_tmp_name, struct pack_idx_entry **written_list, uint32_t nr_written, From patchwork Thu Jan 16 11:35:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak via B4 Relay X-Patchwork-Id: 13941616 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46F3F1DE4FE for ; Thu, 16 Jan 2025 11:35:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737027320; cv=none; b=jhKfGr4EjLvrI5M0YKjjvfcsnph4NpJg5hukhHUtPaaiSDV5qvl6h6jw+tEjs0f7euZzQx7/R3V2BwSJdaXtxN6YWykyfnS/XhMZhc/9/dshHPDPSrBsolK/WPwHdX8I0S3xIZsQwuRiLkBdKc+fAs+LHN7UWQvfxX9FL+E4OOk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737027320; c=relaxed/simple; bh=fUJJh2sgaRySQkjAP4Eh1iR9uJVn/wSd/xkz9Rixvj8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sOAsz2dk9oTlGGWUSNzjshDgrYt2ly3kNUweq8hbzLWLrEIG7I7bPJ9HhA+9khIY0Q+qnulr2oMn7/8brG4FlGlbzbqrFksVLuPhOoBamhXk/DM+9ALMyFqK3Yxs+jcwczcI+pCObVZDcJh7CVc3feJP9lfefrjYQqCV2ai+c8Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EfgCre7t; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EfgCre7t" Received: by smtp.kernel.org (Postfix) with ESMTPS id EB59FC4CEDF; Thu, 16 Jan 2025 11:35:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737027320; bh=fUJJh2sgaRySQkjAP4Eh1iR9uJVn/wSd/xkz9Rixvj8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=EfgCre7tsg1arT2MXudoX9zustqdCdoHJvJ3aOHfqrhhiKdJlujRdAHEnbT7/jROj F1wK1L202Tg8uqdgU7iCvBYw8dHYGq0g7iOKt+l8TrSXvPye64qREYOqoSXueRi9ZP LQgI8wW2vw46GKu4STP1wPYXLnYqFesWTDqW94FrL2ykjLDKdPdQ+vRX9BGEaqbTPj AVhJJQoUY1gIVEJ0rZMIxKTCEklOYbYh7JslQJRVSiktvzpTmS5mmVxEm6sYgnGdhb c/13o/ZOj/MlE+WsZzLCB8m5J0d5mdEoMGRgDqnLOfG3wwBh6K63HIJkXhCMJCe9/z YFd9EbYvzt75A== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0FFEC02187; Thu, 16 Jan 2025 11:35:19 +0000 (UTC) From: Karthik Nayak via B4 Relay Date: Thu, 16 Jan 2025 12:35:16 +0100 Subject: [PATCH 4/5] pack-write: pass hash_algo to `write_rev_file()` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250116-kn-the-repo-cleanup-v1-4-a2f4c8e1c4c3@gmail.com> References: <20250116-kn-the-repo-cleanup-v1-0-a2f4c8e1c4c3@gmail.com> In-Reply-To: <20250116-kn-the-repo-cleanup-v1-0-a2f4c8e1c4c3@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5880; i=karthik.188@gmail.com; h=from:subject:message-id; bh=tgeOZNYzqhCrj1kyCoBVrPtA9tcVhEVzf9gEDPX9KKI=; b=owJ4nAHtARL+kA0DAAoBPtWfJI5GjH8ByyZiAGeI7vWaT6EwM4hufwx0JjDEsr2xIujjt8ATv vg7jEynvOt7IokBswQAAQoAHRYhBFfOTH9jdXEPy2XGBj7VnySORox/BQJniO71AAoJED7VnySO Rox/JGIMAJQOMnZhWPudB1/n0DHvgTNGsGIJPzxpb/Nnl+A24ljgp7nw4VU5PQnT9U5jpHv9cAK IRh93WxpH7DzU14nU/QQR7ydfZsUZw2jlRu9lZ9bxTkoZK+PBbZCqTUv17epfCT/6uGXq3P9ZE5 nkJG95f2i7w+AmRiaD7q9p1Zq/bggRP1jTID15CZPpFp5e4d8IMN9fe47gC5y9ySu6s2/FPk4eA 6Ah9A/NpuU7h6r1m0hThpacO7wg20kkvYe9zzJBW3XnLc2dtUrUqXEMIn7ayl18rg45N17nyMvg g//Xe2uG6nJA4kivfqNm5aKDIZiWZ7p8VdrTpu/t6U+zmX615ICcVUA4JMalca3VOrT/e6mkLDR neJYYWR9ORyO6CjJy3tOy6t2IrudHgLwPGaiSyvfzWGXJ9mPhJUhSRdS0JkrG42qnsNH4AVaFZQ LNXUSiF7JUPodrGV2/IpiOF8CVtgRkv9/y8aFqvEJg0LsA3cKgvLsSFqEwlidTNu5SVQrwA4nT8 AQ= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F X-Endpoint-Received: by B4 Relay for karthik.188@gmail.com/default with auth_id=276 X-Original-From: Karthik Nayak Reply-To: karthik.188@gmail.com From: Karthik Nayak The `write_rev_file()` function uses the global `the_hash_algo` variable to access the repository's hash function. To avoid global variable usage, let's pass the hash function from the layers above. Altough the layers above could have access to the hash function internally, simply pass in `the_hash_algo`. This avoids any compatibility issues and bubbles up global variable usage to upper layers which can be eventually resolved. However, in `midx-write.c`, since all usage of global variables is removed, don't reintroduce them and instead use the `repo` available in the context. Signed-off-by: Karthik Nayak --- builtin/index-pack.c | 6 +++--- midx-write.c | 4 ++-- pack-write.c | 21 ++++++++++++--------- pack.h | 14 ++++++++++++-- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/builtin/index-pack.c b/builtin/index-pack.c index d73699653a2227f8ecfee2c0f51cd680093ac764..e803cb2444633f937fafc841848dae85341475f1 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -2099,9 +2099,9 @@ int cmd_index_pack(int argc, curr_index = write_idx_file(the_hash_algo, index_name, idx_objects, nr_objects, &opts, pack_hash); if (rev_index) - curr_rev_index = write_rev_file(rev_index_name, idx_objects, - nr_objects, pack_hash, - opts.flags); + curr_rev_index = write_rev_file(the_hash_algo, rev_index_name, + idx_objects, nr_objects, + pack_hash, opts.flags); free(idx_objects); if (!verify) diff --git a/midx-write.c b/midx-write.c index b3827b936bdb1df12c73fb7d9b98ff65fc875cc3..61b59d557d3ba46a39db74c62393545cabf50f2c 100644 --- a/midx-write.c +++ b/midx-write.c @@ -658,8 +658,8 @@ static void write_midx_reverse_index(char *midx_name, unsigned char *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); + tmp_file = write_rev_file_order(ctx->repo->hash_algo, NULL, ctx->pack_order, + ctx->entries_nr, midx_hash, WRITE_REV); if (finalize_object_file(tmp_file, buf.buf)) die(_("cannot store reverse index file")); diff --git a/pack-write.c b/pack-write.c index f344e78a9ec20cea9812a5eaffc72ae0b7e7424d..09ecbcdb069cc9b0383295798ceb49cbdc632b64 100644 --- a/pack-write.c +++ b/pack-write.c @@ -194,11 +194,12 @@ static int pack_order_cmp(const void *va, const void *vb, void *ctx) return 0; } -static void write_rev_header(struct hashfile *f) +static void write_rev_header(const struct git_hash_algo *hash_algo, + struct hashfile *f) { hashwrite_be32(f, RIDX_SIGNATURE); hashwrite_be32(f, RIDX_VERSION); - hashwrite_be32(f, oid_version(the_hash_algo)); + hashwrite_be32(f, oid_version(hash_algo)); } static void write_rev_index_positions(struct hashfile *f, @@ -215,7 +216,8 @@ static void write_rev_trailer(struct hashfile *f, const unsigned char *hash) hashwrite(f, hash, the_hash_algo->rawsz); } -char *write_rev_file(const char *rev_name, +char *write_rev_file(const struct git_hash_algo *hash_algo, + const char *rev_name, struct pack_idx_entry **objects, uint32_t nr_objects, const unsigned char *hash, @@ -233,15 +235,16 @@ char *write_rev_file(const char *rev_name, pack_order[i] = i; QSORT_S(pack_order, nr_objects, pack_order_cmp, objects); - ret = write_rev_file_order(rev_name, pack_order, nr_objects, hash, - flags); + ret = write_rev_file_order(hash_algo, rev_name, pack_order, nr_objects, + hash, flags); free(pack_order); return ret; } -char *write_rev_file_order(const char *rev_name, +char *write_rev_file_order(const struct git_hash_algo *hash_algo, + const char *rev_name, uint32_t *pack_order, uint32_t nr_objects, const unsigned char *hash, @@ -280,7 +283,7 @@ char *write_rev_file_order(const char *rev_name, return NULL; } - write_rev_header(f); + write_rev_header(hash_algo, f); write_rev_index_positions(f, pack_order, nr_objects); write_rev_trailer(f, hash); @@ -568,8 +571,8 @@ void stage_tmp_packfiles(const struct git_hash_algo *hash_algo, if (adjust_shared_perm(*idx_tmp_name)) die_errno("unable to make temporary index file readable"); - rev_tmp_name = write_rev_file(NULL, written_list, nr_written, hash, - pack_idx_opts->flags); + rev_tmp_name = write_rev_file(hash_algo, NULL, written_list, nr_written, + hash, pack_idx_opts->flags); if (pack_idx_opts->flags & WRITE_MTIMES) { mtimes_tmp_name = write_mtimes_file(to_pack, written_list, diff --git a/pack.h b/pack.h index c650fdbe2dcde8055ad0efe55646338cd0f81df5..8a84ea475cda902936ee0b6091c5b4d462606be8 100644 --- a/pack.h +++ b/pack.h @@ -105,8 +105,18 @@ struct ref; void write_promisor_file(const char *promisor_name, struct ref **sought, int nr_sought); -char *write_rev_file(const char *rev_name, struct pack_idx_entry **objects, uint32_t nr_objects, const unsigned char *hash, unsigned flags); -char *write_rev_file_order(const char *rev_name, uint32_t *pack_order, uint32_t nr_objects, const unsigned char *hash, unsigned flags); +char *write_rev_file(const struct git_hash_algo *hash_algo, + const char *rev_name, + struct pack_idx_entry **objects, + uint32_t nr_objects, + const unsigned char *hash, + unsigned flags); +char *write_rev_file_order(const struct git_hash_algo *hash_algo, + const char *rev_name, + uint32_t *pack_order, + uint32_t nr_objects, + const unsigned char *hash, + unsigned flags); /* * The "hdr" output buffer should be at least this big, which will handle sizes From patchwork Thu Jan 16 11:35:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak via B4 Relay X-Patchwork-Id: 13941618 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E84E1DE894 for ; Thu, 16 Jan 2025 11:35:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737027320; cv=none; b=q/4wQkXUR5a/bHxIVRwUeWAg+A+1IhmbcRU9LLdtpGwAUJpwrQNTqhyb9ew6mnVU8XGyIAAPhmuPHouzJiMiw3AaDPUiLw3Yhb6XRQVKcWOaKUxc0taJBesif4geXDtAP9Ub9XR9IE8yMjMSGmzhKNinVTIS5FITSCkUjpDqk4Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737027320; c=relaxed/simple; bh=08xOZ4nX4Wpqds9TqEXj6xlVC4MVtJYbFfwe+V2yQOQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SO2Ekjk5+1Ic4q7yjBhZFcSP8c5Yy8fmMl4g/xKhyHW7YaogkWS+yKstzpxKDXdh6Nhyo/SoQrXJX7N13XowuoeqKR4y/etQCE4hylx5Y3IoX7sZbMr70NkwqSM347GTcFHvPktv02d1STj+6ci+LZ1HDYloAb1QrJszyi3R+GY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CZvTfJQL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CZvTfJQL" Received: by smtp.kernel.org (Postfix) with ESMTPS id 058D8C4CEE2; Thu, 16 Jan 2025 11:35:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737027320; bh=08xOZ4nX4Wpqds9TqEXj6xlVC4MVtJYbFfwe+V2yQOQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=CZvTfJQLDZgOmgpn74oKJsLFdm4LGwtZJ+yHJBpqmL2UGv6pcORIMfx5LxSFbhQ43 bftbfPUFQiRku/ZbB1NAq3OfmayGiLpa5SmSYYebQ3HyvPcp1KV6asHQP5Rk4KBNmI OrMQIPuipTbGFbjHnjzf2X09hssj0ZHMmPhg+g0qBamaYDNqN1wW3OI1mnHWP3e343 VuDVqFGo2m9RbTrw8ffuEkUpbHSq6dksTLtdKAt/qj9vdRcY7Vs64qbUUmIbTwqwkc 58YqyBcMHxUjjJthinDx/+HJCP4ehcET3N7XqilgBTamMGz9bh+S39vczel6tN43Xo C57kbnN3LdAVg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id F26C4C02180; Thu, 16 Jan 2025 11:35:19 +0000 (UTC) From: Karthik Nayak via B4 Relay Date: Thu, 16 Jan 2025 12:35:17 +0100 Subject: [PATCH 5/5] pack-write: pass hash_algo to `write_rev_*()` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250116-kn-the-repo-cleanup-v1-5-a2f4c8e1c4c3@gmail.com> References: <20250116-kn-the-repo-cleanup-v1-0-a2f4c8e1c4c3@gmail.com> In-Reply-To: <20250116-kn-the-repo-cleanup-v1-0-a2f4c8e1c4c3@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3538; i=karthik.188@gmail.com; h=from:subject:message-id; bh=9apsR1GBlegQZhItb+8Q0LgeChaYi1HyTHkcGvoZGi8=; b=owJ4nAHtARL+kA0DAAoBPtWfJI5GjH8ByyZiAGeI7vUQov1ESSA2Ouu5Qn6GmWVnU1BTp16lf nN9cCE5ZZWX9YkBswQAAQoAHRYhBFfOTH9jdXEPy2XGBj7VnySORox/BQJniO71AAoJED7VnySO Rox/8bcL/jliaQT0LoddbUaadjRZMYklcT9H9GiZzGrsnoPblf9l0Y4ompHH2qY6FUuqPiNr4p5 r8iHxsAPRsg3fsQoT3cwokR52jcCZ/qfmiYIv9vFNVfuofXuzkpHQ0H0O2G8TVA7XU2gtHBZUpb njLo4v3kniTP75iqJ4R7ZwFvDssFatq9OfXHtb6ug75WOlck/DjzEFj4E0tZscoaPo+o9SmAO5b LvYSKJaGcMuoeEI7/+rk3zoiw8PWO3/3ELVFVaO7p9d0wmFDewiuzTi/U7hZhF830NM7CcAdqoD NCwE71dVo/PnRglkGhe+bnN++pY6sxqgn6iTatKdK9lsGSWJvZj+xBsKudnGoVHP841g+PtEubJ wesJ4BQ1HP+F6tJqu+8oM93GeKa2JChdUvFF0i0/ggf8/NAUNa4tGWfV7/vLr49qVepIwsckS/H NFMeCN2F4VzqgrPckGbRvHsPFhFO6bC9zBvI1aDcGVNiC+KKGgY3cNF/hQAvVfHnnjwIwG3kH38 Ak= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F X-Endpoint-Received: by B4 Relay for karthik.188@gmail.com/default with auth_id=276 X-Original-From: Karthik Nayak Reply-To: karthik.188@gmail.com From: Karthik Nayak The `write_rev_*()` functions use the global `the_hash_algo` variable to access the repository's hash function. Pass the hash from down as we've added made them available in the previous few commits. Signed-off-by: Karthik Nayak --- pack-write.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/pack-write.c b/pack-write.c index 09ecbcdb069cc9b0383295798ceb49cbdc632b64..a2faeb1895e41f4c17281380478f1f2cabcc6f24 100644 --- a/pack-write.c +++ b/pack-write.c @@ -1,5 +1,3 @@ -#define USE_THE_REPOSITORY_VARIABLE - #include "git-compat-util.h" #include "environment.h" #include "gettext.h" @@ -211,9 +209,10 @@ static void write_rev_index_positions(struct hashfile *f, hashwrite_be32(f, pack_order[i]); } -static void write_rev_trailer(struct hashfile *f, const unsigned char *hash) +static void write_rev_trailer(const struct git_hash_algo *hash_algo, + struct hashfile *f, const unsigned char *hash) { - hashwrite(f, hash, the_hash_algo->rawsz); + hashwrite(f, hash, hash_algo->rawsz); } char *write_rev_file(const struct git_hash_algo *hash_algo, @@ -286,7 +285,7 @@ char *write_rev_file_order(const struct git_hash_algo *hash_algo, write_rev_header(hash_algo, f); write_rev_index_positions(f, pack_order, nr_objects); - write_rev_trailer(f, hash); + write_rev_trailer(hash_algo, f, hash); if (adjust_shared_perm(path) < 0) die(_("failed to make %s readable"), path); @@ -298,11 +297,12 @@ char *write_rev_file_order(const struct git_hash_algo *hash_algo, return path; } -static void write_mtimes_header(struct hashfile *f) +static void write_mtimes_header(const struct git_hash_algo *hash_algo, + struct hashfile *f) { hashwrite_be32(f, MTIMES_SIGNATURE); hashwrite_be32(f, MTIMES_VERSION); - hashwrite_be32(f, oid_version(the_hash_algo)); + hashwrite_be32(f, oid_version(hash_algo)); } /* @@ -322,12 +322,14 @@ static void write_mtimes_objects(struct hashfile *f, } } -static void write_mtimes_trailer(struct hashfile *f, const unsigned char *hash) +static void write_mtimes_trailer(const struct git_hash_algo *hash_algo, + struct hashfile *f, const unsigned char *hash) { - hashwrite(f, hash, the_hash_algo->rawsz); + hashwrite(f, hash, hash_algo->rawsz); } -static char *write_mtimes_file(struct packing_data *to_pack, +static char *write_mtimes_file(const struct git_hash_algo *hash_algo, + struct packing_data *to_pack, struct pack_idx_entry **objects, uint32_t nr_objects, const unsigned char *hash) @@ -344,9 +346,9 @@ static char *write_mtimes_file(struct packing_data *to_pack, mtimes_name = strbuf_detach(&tmp_file, NULL); f = hashfd(fd, mtimes_name); - write_mtimes_header(f); + write_mtimes_header(hash_algo, f); write_mtimes_objects(f, to_pack, objects, nr_objects); - write_mtimes_trailer(f, hash); + write_mtimes_trailer(hash_algo, f, hash); if (adjust_shared_perm(mtimes_name) < 0) die(_("failed to make %s readable"), mtimes_name); @@ -575,8 +577,8 @@ void stage_tmp_packfiles(const struct git_hash_algo *hash_algo, hash, pack_idx_opts->flags); if (pack_idx_opts->flags & WRITE_MTIMES) { - mtimes_tmp_name = write_mtimes_file(to_pack, written_list, - nr_written, + mtimes_tmp_name = write_mtimes_file(hash_algo, to_pack, + written_list, nr_written, hash); }