From patchwork Sun Jan 19 11:19:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak X-Patchwork-Id: 13944416 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 A94A41B86EF for ; Sun, 19 Jan 2025 11:19:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737285581; cv=none; b=Ha0wXVTO3juVmLnzg6xHOA5uz8j5QThtOd7+ANb2QtN/VLW1rVm38PYcXlVf1T6jS4IUrSwQs+ZeqLBwRGi8dGZLBcK/uTy7i/dc0+DCHtILGFW/w9Wxxhk0HcE9B5K36udqmuRTek9vOzO8sq5miWMaJmj94aSpET3innFe3+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737285581; c=relaxed/simple; bh=eJh50frnAgEBcRahU/ovUpY2gTVwjSznGbZKKe7Spsw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oot/S94FzsifYZuR0Hmw9/+tqCHl/YMFV060MlIOK8M12/NHHEzal29/6+SdrYYIv9MnoEcG8WXy8lkXsSQNlD25OBKHxLjtGN9WGb43iht1vBf7shTF5KdDo39lDe1oxO+B0w33Lec5PU0WmIHXqGicmGNXVocTmlaWPv2fRXQ= 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=AIQSkLk4; arc=none smtp.client-ip=209.85.214.176 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="AIQSkLk4" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2166f1e589cso87843145ad.3 for ; Sun, 19 Jan 2025 03:19:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737285579; x=1737890379; 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=x69q624R53wnHN1Cq1R59YFdwCfle6YPlFG5K6yLxqU=; b=AIQSkLk4iZzRbX/Y0TrL9a/jT9FwzEagEYl/ZR07VMMdWAOkKbEybphwrS2mf5B6rG AwjqlIHHu8ofomFrmg+OWB+APlDWJ0Foda3M6pi/K6FTI2H0DF/2TNjxNj13ztQIsEX9 m8gb2mga5wijcXqe2SSwYTvAjR6nKlJPYggPpBzlVzcxyTGzo/l5rrs7+Z/DdNfXfV/M NjCZ2Nq6U5qypHsHBSZlpRSg8b1ZFQK1TRNLsTEV8Ko0odhkVP/x+YfoeseXIhZGnaDj qXwFnnzLrVNsp7KK3yojXQOVO5KIUB5wTjK4t0Zn7PKmUIJUCPX7pTQviYSW8+ihKYfz fBVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737285579; x=1737890379; 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=x69q624R53wnHN1Cq1R59YFdwCfle6YPlFG5K6yLxqU=; b=vBrjON+O5au07/1QY/l80hDlAujpU69tTXszAjglet7Bm4Y6PM6B28I709Y6uLFWvg Z0btrejXd2K1f3nnLJRd3BFsmQxm+JEFunIZ8MQdXl/Hs8s+z7N4puRVY7m6/v9U73HZ NgYDuz54bXhI0KUESeFXGo6MQVAIJpsr2Rk00mHuouWmb8xHPE4p7tAZLUqQYHEq3Q9S T7kF0sk5P9WuuLlIdIwk51arIq7QVn9p8gnpm8hX5I6cNrbbJKTZxEEuHd3mrB4FVw+r 2TkBmc2mcXXQgBw9RLRdylj1RPtRccjgFICM2f02jW5vZy7y0Nz8FFJQEV0lEfupXPIb jBnA== X-Gm-Message-State: AOJu0Ywv+NmbGp7bmKaTOYSWb7B0tHUKgmDM0HUX65yU4enZbmt/Ei33 CYArpMGGJT+2Fp1DGb/+5Hlmy8HA32meHZLCR2EIavByoUuGc7eFlwS94wKv X-Gm-Gg: ASbGnctzGlbcdEBPE2Mf63ipDs7r1oNSIdcQNfFvcV9A5ad3x650LgdMznmwtOcwhRj jRuMx7dwOqFC10swDGgInTa4gK3eU/Yy7Taa6iEn30WDaON0yTtRJWnh087tojiCNhCOiKdHvBG P3FEaD4XE0fNt21WjqDRcjk+roMT9qgDVr0tzfA+PpuCrOKtumMVV+H84H0H/XFxNAungrMaO08 W+bBT8K+ySFFwavPKSav4kTpxckfviDftrI37rjJjiRH+Cpxc7ImQZcU//E1lgADogcLQS1 X-Google-Smtp-Source: AGHT+IHuvqOgzk/7GHAiH4XrM5tIrxTcNV8xkizkWOIhaAxex8rU9trf7Ay2htHGGzYRrCCU06E7Hw== X-Received: by 2002:a17:902:ccc2:b0:216:3e86:1cb9 with SMTP id d9443c01a7336-21c357a608dmr131247215ad.50.1737285578790; Sun, 19 Jan 2025 03:19:38 -0800 (PST) Received: from [127.0.0.2] ([103.39.127.160]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2cfbd01fsm43031415ad.104.2025.01.19.03.19.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jan 2025 03:19:38 -0800 (PST) From: Karthik Nayak Date: Sun, 19 Jan 2025 12:19:26 +0100 Subject: [PATCH v3 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: <20250119-kn-the-repo-cleanup-v3-1-a495fce08d71@gmail.com> References: <20250119-kn-the-repo-cleanup-v3-0-a495fce08d71@gmail.com> In-Reply-To: <20250119-kn-the-repo-cleanup-v3-0-a495fce08d71@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , ps@pks.im, gitster@pobox.com, toon@iotcl.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=7836; i=karthik.188@gmail.com; h=from:subject:message-id; bh=eJh50frnAgEBcRahU/ovUpY2gTVwjSznGbZKKe7Spsw=; b=owJ4nAHtARL+kA0DAAoBPtWfJI5GjH8ByyZiAGeM38Rzvue7tAFAkxn7hlqc2bzR4j5qALFwO uxcG+0Augf2vYkBswQAAQoAHRYhBFfOTH9jdXEPy2XGBj7VnySORox/BQJnjN/EAAoJED7VnySO Rox/A3AL/Rm0YBbaY1xMxMeAQhaxmPPEkmHV6NvcBpgbTNYEph6GcxV8zqecxfxANdaw6DHzCsq /CcRQc4h4YbdFLpoAAaRMK8Ov1A3HPHg/7mqdsm/7ygwBQKZtCWZma+BTmUAEPzQNT7PPR5hYdR IwmRZBY1KmXmBJDX5D7t4naSp/7XsAYTgWMRWObvI+8VXnneo0lwfhp7PvKQeeNfgpgg0h5/ggD SWOR+M03c8CJHvHAQPWEoCn4MbPwDUO+IPjgitCMOybWpkRKNvRBwOZ7/T4o7d+LmpNryUIuC6s 1tNxrNvG7/qGazQbaP68vaAy+fx701wB+0+bOiQtj7mumdBSbHuTp6tedfK/xE92pu/tZziaX67 JV9ZfKIxq79/XXDxfDbDRCVhbiW/+OAy/JV9p1PDf9kkXPPub4WFBLNNgWyJR0vbkXsdlb8cYpi jOrZxPVyPXcWyyGzisTjv/Wv3ugU/uBOGSP/vyR/qgOs2QqV3eToxDdijFiIfFjlCIA3MWbTc76 qk= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F 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 a hash_algo from the layers above. Altough the layers above could have access to the hash_algo 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 Sun Jan 19 11:19:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak X-Patchwork-Id: 13944417 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.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 23FDE1D4335 for ; Sun, 19 Jan 2025 11:19:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737285583; cv=none; b=cBIyMsoibrzKGvVYDRasJCdbX4zj4sFRhyNe5T05QBTs3ZxHTzoz/bkda1C1KQzLjXKFRFZherRSRnlMcWks3jq8J8vGXoCata3jXb3X7Le5wnwhqTvJUxUs172E5xfDpspB0bAr/Fdqb2wrCTqy15pIR43RoNZRwDH39pyyNa4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737285583; c=relaxed/simple; bh=l/H1BXfgAsAT3JAZNzifnzOj2hY96z0VAYY5k4ZBJcI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lUU5Gx2s+zFTQh6V9M3cWgW6apN8BVcPAUOqU40qmIyi6TLjbTgjL4c7ZU2g7G0TAkLHBpbTzhzjUnUOXBgJ57OBfHq+U2mVHiXEbLHAFpZmwyMyFgXzWbred5FxRZYg82TXVgs48eBTNruCuOOttauk0gAcGl2pxH4LTnomRMo= 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=Z4KLjBe2; arc=none smtp.client-ip=209.85.214.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="Z4KLjBe2" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-21c2f1b610dso55589795ad.0 for ; Sun, 19 Jan 2025 03:19:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737285581; x=1737890381; 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=bpLuD5hTj+VGAyHqFcU6pyOaq44t+mr+iV+5XBO0Q/I=; b=Z4KLjBe25fxRusLLTX8DC64quxtml4FKiYWiBDxmWJJKOUehFCVfU9rOi+a0Vksjvs NsXfipzcVHrvNFNb2hAQaWK3WTvmqeP1Szy/fFkgC6tVzHK0txo1nA4lR2f/3wf3v4KA Se4PATD++GLDd1DJKmYOe7LQwYVE7yHZxNwrCaq3BQGoHifcGpr5RJyFCUBV6Bqr808D HlTJlW2liO3qbh6VOKYn5zuxwCGAVRZ85LDr2n7AXYQv4FZkBey1Lw07jQTpfl8ApSOZ dcexVBYIx+Sawm/QqQ9AbJOfO58MxisrMXMC+zpvLRRMx/2ktNWTzs94YFIN4eUywTcH IZDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737285581; x=1737890381; 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=bpLuD5hTj+VGAyHqFcU6pyOaq44t+mr+iV+5XBO0Q/I=; b=FwV+3vts7zwdgidm6F0n6A678sTcwVtgKS6bPPuqfMSOjQOGzytAdo4m3obAahWmwZ zS9EjDIMDNNqBl/nc+IgoFxUWODBUotTP6EI5Tk5sdNo0QVr5j6WnFJSLP8ZVPdjnw8T nN1/bo+lTNT5fmNqAD6JldanwoTTzypchGhJhBndiDUBM0pD5a2bNAdd3QQHzvRF/S5X kADH+7usaG5woM2eiwCtelwLEkdBp5q6nuOaQRcGj+oflO+vs5MKwuV1XP7wkj9BVjKG dYFR3KA9FIcXMcxporBliUACqYiIxd3a1As0MEvpanhccdTlJIerd+7wg1IJW73uXu4j V8vw== X-Gm-Message-State: AOJu0YykQP9euHB8MR05jXRSdbJkP61jB271/K5hqtosyisK5SRd31m+ pZtRfsdf10ixCAoP+BQzL7pryMkVySwa5tcmhmNJmme8nTm0X0Ci X-Gm-Gg: ASbGncsmK5Nr9RvsMnJj4LS52ezkHsp0r4Bu88mWq6yL3UVmDaTsZk5G5uegGrpCOcO 06fwUAkGuUE24MRRJo8sGna1PrjZvShVIoerq7npQub+4VGBicdGwjNwzmaiw5gV6jRHaAwQ0sj uBfuvWmeR9aVxbmJT3/GYZn1M0YXOoxfBmBVDzMdRDwXRn9CSaq+QtZmwz4iSrqv278iIVZIj4D ApY+0yRQ/N3lLbpBLmsvV9uPCcaQn4isbZVhuI3F5ia/3vutjKmihpNaxf3x8/iUPMGu+jl X-Google-Smtp-Source: AGHT+IEUQjRCb5wP0coQL0Ze+rVHd2LuogJmfEzs7X4VpKyruTctN2AzGR5lgleJo1TG8RaXVxtmIw== X-Received: by 2002:a17:902:e802:b0:212:615f:c1 with SMTP id d9443c01a7336-21c3540a0admr155277545ad.14.1737285581307; Sun, 19 Jan 2025 03:19:41 -0800 (PST) Received: from [127.0.0.2] ([103.39.127.160]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2cfbd01fsm43031415ad.104.2025.01.19.03.19.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jan 2025 03:19:41 -0800 (PST) From: Karthik Nayak Date: Sun, 19 Jan 2025 12:19:27 +0100 Subject: [PATCH v3 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: <20250119-kn-the-repo-cleanup-v3-2-a495fce08d71@gmail.com> References: <20250119-kn-the-repo-cleanup-v3-0-a495fce08d71@gmail.com> In-Reply-To: <20250119-kn-the-repo-cleanup-v3-0-a495fce08d71@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , ps@pks.im, gitster@pobox.com, toon@iotcl.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3496; i=karthik.188@gmail.com; h=from:subject:message-id; bh=l/H1BXfgAsAT3JAZNzifnzOj2hY96z0VAYY5k4ZBJcI=; b=owJ4nAHtARL+kA0DAAoBPtWfJI5GjH8ByyZiAGeM38RPvK6AeZfgDGNsBAzsNu0zJXfMj5Ecw CimO3srrpWRIYkBswQAAQoAHRYhBFfOTH9jdXEPy2XGBj7VnySORox/BQJnjN/EAAoJED7VnySO Rox/+q0L/R8CsPk79SR39HMNblqNym/DTLN/+mbDKrmy1z+HLNDtJZauxfsif+lsM0OqPBSaIvK mJaX/hAyFU7P/crYKT5LPTO1FyoMMJy8rCpbVMlYmANy7VP19X/nJvec4Ik9VuxRl1/U04fGVop 4I+zZ7gB3OzVTVes3FvzDOYQiwy7gVCMRKSW6Wt2PWWYdT1fxqGA+G12yGQdaWy9+de3BShbUbo +1dIJVKgN9xZWRbUTO8UMl1grYRsKfmWrMbqydJKQsrQMarAJ0N/UGuE6fOFoS6lcJQSlVWyy3B BKFgH0QbQs9kS3iuUui2768ILwi8q3h6AF10PM6poI6mJUSzczBP4FI9Q2ZSHmQm4CuOGO5IMYm VJTxQrBMQTvo5V1zuUMQC47rfNMJlnwUq8/O2IxsWY/c/Su7t+gD6R+yhU+Hg7wou00FgE+0YCz s+sc/6x7vbeHeDVf6lsCE6qQxLQtBHrOICHyjm3yjIjlu2Pcg5dfbe+DmnthTiui+UW3/KpSK65 zw= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F 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 repository internally, simply pass in `the_repository`. 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 Sun Jan 19 11:19:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak X-Patchwork-Id: 13944418 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 26EC82905 for ; Sun, 19 Jan 2025 11:19:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737285586; cv=none; b=hkBRVTEI3A9aeo2mv47ifB85ouRT00AXv4TEShmaEXa9199PZFuCKmmTAUaxAmRWekuPGQH/TiyzBFQXmLntFYjR5yX7EMk9a95EzJVwuoojzh7exMP79btgkhrvFn5WkNC5RKFpZApGeuisg1UYOs/GzgujxRsn+SxrFwgab14= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737285586; c=relaxed/simple; bh=z/hvDkk2DJ15vSRotsVQFINNIZHtpQSKKB/IRckKOa8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pwFFBjVWjTJOBbk1CGCq2gvQ73Wduno0YQoJfDWNSgId3vXQSTjtH9tSOx1CJyO+dPXL6tI94zUy6qvpkh9UfVAJUu/O9ePHGf6V/iuuRszuwBX2jX0L4pacyv1behMhcRNq/762nL6CR3GKDfVcPUOMUFyTC4+LfeO1o8I/zh8= 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=VUnKTS0/; arc=none smtp.client-ip=209.85.214.173 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="VUnKTS0/" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-216281bc30fso82689825ad.0 for ; Sun, 19 Jan 2025 03:19:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737285584; x=1737890384; 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=Ordz7YpAXEG5TId6d9ADjSwqJ0gwgziIasGjel0WM3M=; b=VUnKTS0/2OKJGcrTqhMwLF7XKqqiNE2kSuSAq9UX4lhFd0HTxyyNwakdtg+sBcybFt RuDXgxE6c9Z920J+Gt1FlKQ2ZDKnPvESfIRdDj2e99eeGurrf7mVejbP/r8pfngOHsXB INSmcZGiLnG2z0Zvcv+cpG1/0bmo2tU4kRnLGAklCDVQdBYdN1k1e7tBfgb4kdED1V2m VmcDrLVycy934izC+nbgJicchTOj3AS0L8jHiiplX9oUZFQcxQ65loI8L6TIhe4o7Obt tIC198WFxQbxkSUYL0z+64VqOS8w0XBclMPLmyA2gpHcDDYCnNVEayrrqt7Lo7LlPktP 5uBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737285584; x=1737890384; 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=Ordz7YpAXEG5TId6d9ADjSwqJ0gwgziIasGjel0WM3M=; b=d6/p82z+xxf+80za51K/60zrnWVpnUHsh0Mnpin/EOGpkNi2od93eYg/WFkszZZOtT t5aWGVZuInzz3jEIe23lDuKPfNximrqAsjeBgG1a5EvJi51vH/YQSeAPchkRptbBYYpl Hw8ajZuGnMVQKO7gmmOWEJAAg2EDn6fnQTrjI1glz0oVfeuN44pWSy3+ISP8E7B89uFE wYS+jgPr8croQUuuOv2gnSkvXICwcnmi3LN5MQFv2TZsqZSsFhQK29ZAHriapqJH8XWN 10IWExxitvG4XVyKjPXSwv41ZI+Zc4zcaZDcMoWmxr2hTv5Xf8ysCL+WFySqzCL4s6hd BB2Q== X-Gm-Message-State: AOJu0Yyem1VfL/VhLvlBXN1YYwPKjz9h87j1fBNku8b950shE220eq24 cHDoay070cujbUiVTw3hF9FNLNa6+Nc14+S3oviF3V7qBKE+33X/ X-Gm-Gg: ASbGncthwzmpDpYD+1dcY4oo1PPURe01WKeZEkOTi52OWLcPViojxupmoVVR6XigWSN YXxGYXh6PUeJQHqvbW6+hODHD2PynohQRXd0mJ379n//cVAiBUgCpQKI3rC0AsLKVYM1qXPh/5g pbpW9IIh97A1AaFMq7GJl7buhA9DdGPCozySHLBLQQBasSlMXSoIJkJdToqXWFWC1khHbmcbsbU h7B96Ov3zkcejgeDmhnljf6iAlSQcjAjdSMr8OUhW7sXPPPx0X33sFcDihdVeuDjyfEhqis X-Google-Smtp-Source: AGHT+IHBDr+tvds5u8Lr+6j6ZXvywbG+7zy07/2crYXMe+dSjmMweWj7OsjqGUdbbBgs+MjbArWdbw== X-Received: by 2002:a17:902:e544:b0:21a:87d1:168a with SMTP id d9443c01a7336-21c3563c6e6mr143798515ad.41.1737285584341; Sun, 19 Jan 2025 03:19:44 -0800 (PST) Received: from [127.0.0.2] ([103.39.127.160]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2cfbd01fsm43031415ad.104.2025.01.19.03.19.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jan 2025 03:19:44 -0800 (PST) From: Karthik Nayak Date: Sun, 19 Jan 2025 12:19:28 +0100 Subject: [PATCH v3 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: <20250119-kn-the-repo-cleanup-v3-3-a495fce08d71@gmail.com> References: <20250119-kn-the-repo-cleanup-v3-0-a495fce08d71@gmail.com> In-Reply-To: <20250119-kn-the-repo-cleanup-v3-0-a495fce08d71@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , ps@pks.im, gitster@pobox.com, toon@iotcl.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=7519; i=karthik.188@gmail.com; h=from:subject:message-id; bh=z/hvDkk2DJ15vSRotsVQFINNIZHtpQSKKB/IRckKOa8=; b=owJ4nAHtARL+kA0DAAoBPtWfJI5GjH8ByyZiAGeM38Xa30gtdQYv21Ke/RSnk27f3qgLikbI5 YR0Vo16QoQnqIkBswQAAQoAHRYhBFfOTH9jdXEPy2XGBj7VnySORox/BQJnjN/FAAoJED7VnySO Rox/CUYL/1eTJ4fjHMuUlM89RBeb4ni2MJMhF7rLln7/vZaZLbEvgVvOyS/zmH3T7YiKFEoZ/IH ngll68mZQ94tX7B8Ru1/dJ+jDTJbUbH9v4HBkhfsX0pC66qgKdXjkvew25KqlW9VWziCeVoG1r/ eZbSmN3DNj91ngFvipZbwInAnA7NTYpKFRJ6L3iJ8fBjiJTvOLqTeU0nJ/bAmVwpZUPGMOrF9WW XMe2BQNa3/1m43pBQjXtFJJNe+lKyC5iBZSTdod7R95NL8nm+w57nq/P1ninZ37X+CIcwno8xCX OFkVALPQ0boFR7Psra+/txa0QXfmYx8v8GNPeeEWrS5AzCz3Az5di9vOCeoG9YFPMF0Ie++HBQ5 LHXVioxmKjqmGp6kuJE7x4Y87kFh/TkPWdrQvT2iwZPzR9aknIL9nbeYOEmcJklKslofGqe821r hPL8NjINl6+hEkpUFm+3soRXa2vKoVEAmPsdXCqlXsNnfd/Gw9BRPr/M4yfTgN1kbMwXK4O9U27 NM= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F The `write_idx_file()` function uses the global `the_hash_algo` variable to access the repository's hash_algo. To avoid global variable usage, pass a hash_algo from the layers above. Since `stage_tmp_packfiles()` also resides in 'pack-write.c' and calls `write_idx_file()`, update it to accept a `struct git_hash_algo` as a parameter and pass it through to the callee. Altough the layers above could have access to the hash_algo 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 Sun Jan 19 11:19:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak X-Patchwork-Id: 13944419 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 C84401DE2BC for ; Sun, 19 Jan 2025 11:19:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737285589; cv=none; b=erkGENRMoJuSdD8Zw8Ws3CarmIM8fot8Js1nd/0dTkeK+4CEOAMiOV3TduPe6fhlfzQpGHxuPJumksyo5iBpxobiuL0a8kTjHV4Y8PuO1VyVGKrOPq1bLLbPF8pZC5rCFXW460b8SseBKeC5oRSuFtIKqEAyRg3w2Um/ew5/uWo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737285589; c=relaxed/simple; bh=v5ZUwpdDJTd+G1HB8XKbc/aglyDr+icMlkaRjQZ/uYM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Eh1+7Svx+2zlQHZnYRhhAqpmm+MW+keilInYRMN2vx70PV1n2GRV26SgEE6SOwUJoaiZjM+s+brOuk8hZ24C2DzpjrHKg1qyyBcoiilFVxKsE215xYQ4SBKFNX1IeWZyLDsGyTVx/yjLHHHKQnFNk1tERz/d1JUG++pj75C3Iqs= 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=inlq/QLi; arc=none smtp.client-ip=209.85.214.177 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="inlq/QLi" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-216401de828so61439035ad.3 for ; Sun, 19 Jan 2025 03:19:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737285587; x=1737890387; 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=gHr0b/L9kX+cQqJbGdo8PiMkNCQ67VIUO6zbVBkRdv8=; b=inlq/QLidDZZzvyg4klkkYYBYig2FdFi/gUly3/6ROJTXiTkLqhyZMaOfaFB7medLB 7trPwQTcUsWUCQ9yNLY8M/31IMlsZ9QIsU4UnFdZucS20wMYzp5/ag46X2XQZjrnU+e5 5S6hkRV0YZcPHi6uV60q7zOIhinl9AQDd6vFI7Pky7ZfAfT2A3cgCz3/bR/cR/DtD9FE 3ZusW2Gq6BTWSmEoybn70tSZZclm43MMEthMgqyw/DqbJtRCUIQgSXaesJzT/06heMId utwQt5xAfMD+TokSMgvYSgeVlAe8YCGjmQSedgq82uqHuJIxmWnwTENN6jQgAyV5Jkrp WYPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737285587; x=1737890387; 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=gHr0b/L9kX+cQqJbGdo8PiMkNCQ67VIUO6zbVBkRdv8=; b=mgm9AxLdj7J1EhuZfLmo8x4EOeZ5fvx5pzlXwOJmZA15nqUGuYjl/tlEuI70N1V9Ps dZGxw9tD7TS8SShAV6WcCINIAo+X2+qTWQeGIN1lvnBoAOTzEWtXDn/LAV7oW76aoFW/ g+q33Lj27b/VcMxSHb236Hzp+0dK3txv0WRBr48WyUheDZ6OoZiiVyedkgjRqy4fKOHc 7ArmUTljfKxx3DeA0sckdhoiSw32hVQzH3M1ZU8ud3Z4WuMaKABrXPrVnQcCGJhQZB5F Z9Fb/0IP5mHO0ZJpLM3XFt1xKAJk/sFCWAJ65NWwRqMWzLMM30WYk6l6WcPhDrfSiYJW lHCA== X-Gm-Message-State: AOJu0YySD5hB+H7YJc7u7WUi49yayUX3C1FGLsFGgesEsMnlvqr8CqUo INs9nrakby5lCpGFDcvB28XlWx3/dwzwd7U724ndei7iXsHCFC0T X-Gm-Gg: ASbGnct2ub7Ca9GA+oAF+rYdXReAFt2fi3NLIpDKeVj1mp2VoVQBJvOhRBqzI53pY29 oBiZkYRs4b9aXRpLTYCpVHbd/2q0jHxNhknJSnmnuoxEQsP6Rb2mkfWj2bosUi6FmdqnoMXJhuM AzQSah0l0zxfBd54FT8EAdT6x9H6x0lKRf/8ZFHGgYsXvuafNSg+qOMUb231zoDHzQ5ciUTluur hx69JYVTVyEU4Ct5p9I85lnSz5eMp3yu0YjqeprE1p9fzXV5m5kcXUTMGoJhziyD3PPzJMh X-Google-Smtp-Source: AGHT+IGhHQteYK11nAGQPCJVCHg14AHz/uAoUKOOvVyg97D8jieNxnBYKtWo36HEY0ei1gQuee75Wg== X-Received: by 2002:a17:903:41c4:b0:215:7faa:ece2 with SMTP id d9443c01a7336-21c355813f0mr145211405ad.35.1737285586913; Sun, 19 Jan 2025 03:19:46 -0800 (PST) Received: from [127.0.0.2] ([103.39.127.160]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2cfbd01fsm43031415ad.104.2025.01.19.03.19.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jan 2025 03:19:46 -0800 (PST) From: Karthik Nayak Date: Sun, 19 Jan 2025 12:19:29 +0100 Subject: [PATCH v3 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: <20250119-kn-the-repo-cleanup-v3-4-a495fce08d71@gmail.com> References: <20250119-kn-the-repo-cleanup-v3-0-a495fce08d71@gmail.com> In-Reply-To: <20250119-kn-the-repo-cleanup-v3-0-a495fce08d71@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , ps@pks.im, gitster@pobox.com, toon@iotcl.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5970; i=karthik.188@gmail.com; h=from:subject:message-id; bh=v5ZUwpdDJTd+G1HB8XKbc/aglyDr+icMlkaRjQZ/uYM=; b=owJ4nAHtARL+kA0DAAoBPtWfJI5GjH8ByyZiAGeM38XxHM5ENcZEvdCbJAeABlLEEFVGXZbhX 3VuFrdgsRTULYkBswQAAQoAHRYhBFfOTH9jdXEPy2XGBj7VnySORox/BQJnjN/FAAoJED7VnySO Rox/Vl0L/1YYunSfL5VIn4Po1FVGOQ8thgg3U9IQ11c9plIyMnrZAoVNWJwPbsi6ItBa4CFTu0/ +92yTQhNGTu805Rtq3EZQAmn0ZAV366Kd0IEShzoK7iexecVMHTvYJYfIEwSK8vG7y+m3xHrrfc eE0u3k6n5ZciXNcvky8Fx325B1oSsGiP4gUq6yFljJwKd9DVEuzDrD3EJmoHLb3QJsRU0RVW1+S RW/MDH6J8p5p5zVTCnqKduESkSTobxJzWuPj+BtwxJjjQta7gFpkPz4v++JdikbQeRNABNmE5cl ckJmLPBnROqtqTYv07w/33tMY4VCGhBvjpIxjBhPXqoGU8X6OQFKyta7JJQmdYVMWVabByvkhqv iILW6SFDNF1k8lLs2UCfwRyp2aw7qnaMFiJwqWPuRUXCD5Q7mU0YkRvzJEWUOHJDu9HUcKOz5e/ LQeefAi11GgXDR4guQ24tAY9ce2K5u2CMoGesjWsibwF/VI2hINsHl7fn8knMz3WrUZ9sdh/su4 xA= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F The `write_rev_file()` function uses the global `the_hash_algo` variable to access the repository's hash_algo. To avoid global variable usage, pass a hash_algo from the layers above. Also modify children functions `write_rev_file_order()` and `write_rev_header()` to accept 'the_hash_algo'. Altough the layers above could have access to the hash_algo 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 Sun Jan 19 11:19:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak X-Patchwork-Id: 13944420 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 D62351DE4ED for ; Sun, 19 Jan 2025 11:19:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737285592; cv=none; b=JMwYIXXReYAn8OSiZqMuPDtIcX+Fdg2KOLo1dbQDJa2mhUiJ++0pDvzlaLAvAXIzmjChVkw5HAle8av+hTXsBpOe6X0FCOOgetzoQp4+j9U1h41gUrvgitZaBV95JA9eVJRV+YQgNtXzhk2M7yz5X/BW4VYPwz4MTwqIZrWWpZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737285592; c=relaxed/simple; bh=NYYOB8qr23T72v97GPr2AHX8A7pEBBq+40d8X95pjoY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CsucX41Npr90UXwowaDTemJRxYuQ2IPcAWb8w/I17Qw3qdcmLH6qpytohJY6KMem42KER5Qahu7udGOWkGorCbC7oSmE6BantNn568KElxdrenbUOIfi5mJpO10W7DC3A97NQofBYmkob16OLoACxEBqGM/a2bMPHTd0BwnwNjc= 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=k2RlaDSh; arc=none smtp.client-ip=209.85.214.177 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="k2RlaDSh" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2161eb94cceso42840695ad.2 for ; Sun, 19 Jan 2025 03:19:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737285590; x=1737890390; 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=YBEM8VBBa8OuBSrBzihOeR/FBs4k7AiHsVpv9+fBfC8=; b=k2RlaDShLiSaVKty+aX/vxiYDZfIsqk/ENDMUR0Z0D7TqY5kdnJ3xuEHUKDvPFnlgt +5d02xIOam0vV0FHNfB+Ej4VcdZ3gpaIA3toejfd/mTKeM5KMaceG+UdzPK9pQzWurUc Tx07NxUtPNGDh67dqtYlnFw19uHzmlwjwXRyhZViBMKm84YzSDePwJxobYzF9qozzWaY 9sUm/3rwXMCRJXP37DXtvwarFy/kL6lZhq5AZJoH6mnhO9QJOkzGyteLe/5+6SB9jmWV q8ap0/WZihD+GDZYIRbt72qpX+FzV/ZClCn3YnP+cru6I5LzV+rN8VA7Am/tqFD6TzdT s2lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737285590; x=1737890390; 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=YBEM8VBBa8OuBSrBzihOeR/FBs4k7AiHsVpv9+fBfC8=; b=XAyQU3nkhrGZ4JUmqSal0C9CKwOUI3ZiU4kw+6vKMHCqSBXPenM8cg8PcWpRnsrL6h W5T+n3KOvvgMYjmg7Wey26rXMcq2MXikGjKfwTbFYUBRFjr9N9sQugfZ/x0LZ5SsCWWD pvnMju9ZJ1cHmy4yO7vLvVED8qGCHZ5k/Ov65UH48PgJ6fmq3E8lDWiT2S2XloejCocH z3CUnu7qRuCZjY/bzGMy//eDyRAR8N2+4Pqaryb7jJV4pToBOnckRYQKuIRxfht0BB8K 8vEhhZ2rvBPOiO6KGIQKMtnC8GJDU2axQecCMmSzR9fMjLqZHjnW5JW+T4siFWbkfc2E jIeQ== X-Gm-Message-State: AOJu0YyfytUI2Gq2eVPvzfiVpKfHGYZ/PLGhyk4ezKA718SzZnhv8SYI PfCcDeVINFRbFlchKQ0PFtuQVj+SpGiO/4IqJDmGqgerQnZXQwc9 X-Gm-Gg: ASbGncuAc/bJi9EREUeH1EJaC4+4YpN68x0nMSJC1kJB1HeTZBRHrphwXhOxiskYBqu s+5xyryTMJ9gYCsX/qGdd4APRxjzB5OHA0IpXXlSKjodqa61JAxrq8nYRT8x/WnR+qsNl9N82GK XN4MmIB22Y3qR3ZWW7XU6HKLtdOHHx1rxwQJjXultTFmuoY7oZyZ3lfQZMSx9pug9qB01J2HpIi hrFXBqn7D9QaqFMpyzlr/KPZgx66cl8X0QP5dC19qnWoIwxdWhpmVxHjQUuWDHJaKC794fK X-Google-Smtp-Source: AGHT+IEs8IzXj4rw5uktNCUkrEoZ1Tk30TrqlIIq4Ndf87jbQCaEMB/hOwSek0qDb4oR3wV+LZcNbA== X-Received: by 2002:a17:902:f78e:b0:215:a05d:fb05 with SMTP id d9443c01a7336-21c355dcf9emr152731775ad.32.1737285590093; Sun, 19 Jan 2025 03:19:50 -0800 (PST) Received: from [127.0.0.2] ([103.39.127.160]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2cfbd01fsm43031415ad.104.2025.01.19.03.19.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jan 2025 03:19:49 -0800 (PST) From: Karthik Nayak Date: Sun, 19 Jan 2025 12:19:30 +0100 Subject: [PATCH v3 5/5] pack-write: pass hash_algo to internal functions Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250119-kn-the-repo-cleanup-v3-5-a495fce08d71@gmail.com> References: <20250119-kn-the-repo-cleanup-v3-0-a495fce08d71@gmail.com> In-Reply-To: <20250119-kn-the-repo-cleanup-v3-0-a495fce08d71@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , ps@pks.im, gitster@pobox.com, toon@iotcl.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3750; i=karthik.188@gmail.com; h=from:subject:message-id; bh=NYYOB8qr23T72v97GPr2AHX8A7pEBBq+40d8X95pjoY=; b=owJ4nAHtARL+kA0DAAoBPtWfJI5GjH8ByyZiAGeM38VKI8X7V8GqMIDi8nWpIalyxt5D6VhWS qzAnD9zMFz3DokBswQAAQoAHRYhBFfOTH9jdXEPy2XGBj7VnySORox/BQJnjN/FAAoJED7VnySO Rox/k+8MAI3URjMt6MDWkku2tq8ppEl//bkHneptjMTc/PUgDQ7OMT22nD/kHz6TDO/jz3k7ZRm h7FT2LcgVO3Vz4mGfp+D5O6GG/NE4uTNSrVzRl2wedqi/5lw8OGm6jS6LUjTkSNwpl1enI/EITf OQtdJbrNLTlt0k1eNG6x0f8rhb9TqM30OJI0CZN4IbcVUxgVdaUBrP2CbGyJuP4KEvyDhhqUmxi JgTe0G1EJNxZhzxz0SGp3v35uevuV+vSgA8wfVBmDyBzx1pAXYB+ArNMdiXbY/rjNE6CjEbd8aY F7iMY5+zlSmPvutuDmOcStPoVszQBWnxppmeBzRnJKPK+prDuBf37Z81XsGYN03R8X6LE0TnkUB EfHzYaQuIF6Gi4ROm9hS+78GVleVZR5mSg2eHEvLKCmgTrBLXxnMXag45EkXFLrasMpD/b/GJC3 uQlanVmTGFWqATWGSu9eAJtdLgGvZ17iy27+MzZXcgyZIUtLWZHS4u9sOqbeylIfDkruUm8KpD8 sI= X-Developer-Key: i=karthik.188@gmail.com; a=openpgp; fpr=57CE4C7F6375710FCB65C6063ED59F248E468C7F The internal functions `write_rev_trailer()`, `write_rev_trailer()`, `write_mtimes_header()` and write_mtimes_trailer()` use the global `the_hash_algo` variable to access the repository's hash function. Pass the hash_algo down from callers, all of which already have access to the variable. This removes all global variables from the 'pack-write.c' file, so remove the 'USE_THE_REPOSITORY_VARIABLE' macro. 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); }