From patchwork Fri Jan 17 09:20:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak X-Patchwork-Id: 13943047 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 398391F91C3 for ; Fri, 17 Jan 2025 09:21:19 +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=1737105680; cv=none; b=myY6vfh7lsnVDT0napoQ7dX/rF8w/UHhyDpYGGXWWtbwOk9Kp1U9RuK8zW/ZngTt7o2PtC+i/31TzFitFUdAR1NUQv4yvcBHpNL5FXw0CHDcmfm0+TvjWCvS0C4FDuhvDIRjZ/ObTRtgYZbOGKOz1Y5gh7cPP7MF6MiT1dDMXSE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737105680; c=relaxed/simple; bh=Q3YTpVPctjeWQ1SI5ZHfabnjeICNZIAxFUmfeObUWxA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=k2zoMVQ9r4o9NBZRMi8W0GlSKImOldJTPYbcvW7nUtd1mTSRF2XfIj+9DdOPIgXpWrcCGeMjz6+GfpjN8oKdG1dQdGeTYHqFuvlDWbrGCAH2L8qFBqk3oe9PMy6DFLZaTUX68rd6pvJimaHnPTGwXrJ5Nuyc+4DlGUykik3IKkk= 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=fvetGq2c; 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="fvetGq2c" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-216281bc30fso42990225ad.0 for ; Fri, 17 Jan 2025 01:21:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737105678; x=1737710478; 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=cG/8Kxa+G1FdV/BsesI0eK2yhTEIBu4vHbqMzWuN1eM=; b=fvetGq2cQktJA4b0y1SMSBIAkLLDlhFj2lDhn7QOFmSIKB1ivqqSVpkf4AN7YV2yF2 WkpsJkL23pVm7FYfUNaFN0krdgwQcp5A4WS70/XdgGMBNu8jCk/5mplyefx35OMgvpLF l04ZXTNOXYYdd91/SZLLyCoghlA3KramJPCxlNcWDy9Y0H4H87XiG8ArIb0mO2CfJjq3 Pkg2XDe6PFRaKtnvVvmLv2V/yJlrfm5c2mBDyfbVGFt6MUaZ4T++hpM8iWklQv95uv1Z KpeBgQLJmB7K4qGPyuk7bFbgbbznDSq/RgAteVB2kEhNOfxV8wVVC8EBPHHHNWfXE7d7 nakg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737105678; x=1737710478; 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=cG/8Kxa+G1FdV/BsesI0eK2yhTEIBu4vHbqMzWuN1eM=; b=BY/lKQvShfcT08jEma4rIzbWcEObpHl1lwhIXuUPHJ0fIPFC16YFuiJnTX1x5I9Hx5 ro8ct3hwFkLJtSeuNMD6AHSn2AIkme7bx9XRUlrUeR0K8WyC+Q+1FR4xKm2waZbgMVi1 aFscXP7u1EfxEcYEiaX7wkSigsEDJbWhkra5jmVwNL0giIfL5WrsDlaUI1QNuhDLOuxi wo26Gr0YlYFvH3uNfcO2+Qc99RR6QjnC7v/dajY+cwi0bS1N0IltmBdeLD+bQOXrBBIg GnvY8aGzQGkWqJ123jffHdC3LHBWZu39FPI1OHkE/6Tvop/D56uDsjkV5ibbGnEAKkou 5yjQ== X-Gm-Message-State: AOJu0Yz8Hg8Bd6ehEfpTw/D1bXFq33BcPAQwRTpJND8iStA7gs1iSDpp 9sCDdtEKpIDAXScmPZFYoNHlSuG9G0A8Xejn1WLcdA7oBcjDjXHmVoOflhYR X-Gm-Gg: ASbGncuM9qGyZgiSg3mYIUVBOY/bZ6DUkAyhNrr2MxJtlQfpRP//wPWBBh5XV25ATdO y4/7LjGCZTQY8eVR6NoMNmGyFP/cDj7IZRMKFBWgxu2wlPGsnoiJx9rGt4eyyFVe9FxHxVXzVs+ GrN681Ep4nekoys2W2MyPqICZwQ+P37g88XytN1aCiFtODg3t3XGUHD5EtQK2TZKxPGz9RA3/OM YFAhOL9KobO2xgwrQubI/4wtrsUvVzL+u2ojEktaGlKtOSvGtV+LZVS5g4= X-Google-Smtp-Source: AGHT+IHZgZHd3uUl6aSIl59o7yHVE1o6rTIOQCCF7CWbIuLgOxANrT2oKqcS6NGvcxfpC4IQ1+UGZA== X-Received: by 2002:a17:902:d4c8:b0:216:2e6d:babd with SMTP id d9443c01a7336-21c355beb90mr34200325ad.15.1737105677868; Fri, 17 Jan 2025 01:21:17 -0800 (PST) Received: from [127.0.0.2] ([103.39.127.160]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2d3e088bsm11714065ad.173.2025.01.17.01.21.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 01:21:17 -0800 (PST) From: Karthik Nayak Date: Fri, 17 Jan 2025 10:20:48 +0100 Subject: [PATCH v2 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: <20250117-kn-the-repo-cleanup-v2-1-a7fdc19688f5@gmail.com> References: <20250117-kn-the-repo-cleanup-v2-0-a7fdc19688f5@gmail.com> In-Reply-To: <20250117-kn-the-repo-cleanup-v2-0-a7fdc19688f5@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , ps@pks.im, gitster@pobox.com 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+kA0DAAoBPtWfJI5GjH8ByyZiAGeKIQcEscebP3IscXsjZkrWx0bSGuzhBR1K3 Mf2LM76R0Y2lYkBswQAAQoAHRYhBFfOTH9jdXEPy2XGBj7VnySORox/BQJniiEHAAoJED7VnySO Rox/owML/RVQ+/xyU0tqN86RVmzziwffggh885EoQ1GEcubgxcYlal8cAaO6xXUsS1HhMJIfjA+ 6CHuUW+3mp0EEIdk8f1Ip0yTz+YpCwBLIa3xDrO4ZNUTMMjKaEMAttrjCT/dSGWSlRniuNl7wUv rxzP78dGiCpRHib2hVrlgf4WkPahgRQSjejbW6wk1bhV43TaGRsmbKZZnGeMcsaJeH1pwTEDQTY S+h1Gw1Ti1N/BLz4uX/EQU+3R5p95SCyqIn0CE8xQAvsZUYdRPDMjVxQEWMMWw8eZq7LaEwNMLX jM6shqoU3hfexGx0P4LJ8iVFV1dLoSHlWowb8lxs7IOY+2KBmQd37JLX5yPwNSYW91Y2co1Nlvo pjl8H27RUgm4entP2/QahGztHWkxN+TfKr6MP1e3WZLvAFvqfyhoZYOJW51Chp4igiQvQ6O3c0M 1BDdRGQ8iku90NA6pZscmadU2X+wW6ybgLR62ZV9hbx1mrkswblvE8NKM9YfjOXSK7aO+fwspx5 og= 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 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 Fri Jan 17 09:20:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak X-Patchwork-Id: 13943048 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 16FD61F9ED4 for ; Fri, 17 Jan 2025 09:21:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737105683; cv=none; b=ndErC9SKkrjue1FC+XWmzy7A7X6Xf5J54YBL6UvYjxxZMVXQRObnZpvVFnTcTqxuHPaYd8Uzvklhz+oaykjXkiYzWBCI730Yiar9JLWJAUVdmBUShOMPtp5JbDN3aOO/B2neS3q+YtTREYgibLvj/QCkluJCoU63FU0mk2gXe0o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737105683; c=relaxed/simple; bh=l/H1BXfgAsAT3JAZNzifnzOj2hY96z0VAYY5k4ZBJcI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WBlFGYlij7vPZAU8vuobLQCuXILXwyJzGEbdgNO8qiaeop1HlcDPjVhbyNRMUePhFplQnXjE2TZ5kUO1pjq52803T7BUxs1wgSP0T+G8EnzinPYzxeBObyv9gP76Wb9zNZGY9ByMHzn/uVOCb4FWjioFDedn3sfLFSZycnc+gyw= 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=C/eRKf63; arc=none smtp.client-ip=209.85.214.180 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="C/eRKf63" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2165cb60719so33784075ad.0 for ; Fri, 17 Jan 2025 01:21:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737105681; x=1737710481; 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=C/eRKf637cEBbbyJ4fjibpDrgdzsQXks5MtNyc9zA8XHkmuv4htmdvWivbMhkGB6fP Md6C67eyM/GTXaalnN1NMZBaGzpCRQk7lhLSGYU7pLeg6lKF+YXnUV9UWzSsa/SXmx8a yt7l/Dp+IzRaHqdGXe/YzRbj7GgDwCJtehAeVC+KZOtTSg9lgsvjIB0c65hn2zctpG1V RNR7WYhIYaieFQwjDT7D4CivDhN2gvWt8TnG4xoBm3IgFNfviyo1zm+hL9g/EIUgV0M5 j+foD4qnryPiSgdqRlg3fK/PWzOYx5/SyT1Y9AohzLDF46t1SFK3O+br9uBv8S0ulYfD eVwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737105681; x=1737710481; 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=g1NfDj4EOHEA9nL3sw/IRTbZ3ue/DNwRWufAp+vm9daHgnZa43XWE79qJOyYBP5POV jRVMLSVdBU0Mdkb1ubl51H3LbNO5fznxAlhIBVmtaSQcevPrD9JLzWyAc+gy/o96kEE+ E4SjHLWFJC+h1KSYfNph06UFPOEvDYgZ6pLa5soH27ON//cFnumXLeZhgHBk1MiAYvSc aZZP+arBgpoio8OA3f8CoN6WWh0ti/4OLep3wHCAwyY8YrUFS4iZHom5uPF//GG2l2OD XoMDj812ItnwwLBJ+HFHkarM8jylINaZxtBdRTBuTZJkIEOXTT7bTOjq7+ZTiJJFV2dl gkMA== X-Gm-Message-State: AOJu0Ywiyv4psYzOZRKn6R3yz3TMqDLD1/ch1KvLOP7iFa7EanMl4wqm Gb0uoj9nAS0FS4FRevoinOwZbi2p8y8tiuEuqc8z3D+gmV6veDysGuH7etd9 X-Gm-Gg: ASbGncsaepU7ahESfanEblK+SnCTtY1IsURfkL55kc061qwj4RH+ZDPN7C6ah08RnIT MdAjccpLqlVJYh3+AvGPIdVhvLyut/BZlFQuj+sCOrw/Ifsaag+9Dbg9gH9fx08KaSFFqpm9LuC lgkCwct9X7w7QdHQiV/PS5E+B+xu5Ko3AasmJ5tW6qgLNVbZ2cdnj2o2uCIaXebDl7TDCbXdxzZ uBDzy76GcYQNtgRimQnLMfhM5e59I5AyTStcUpnfWLbqcoEmFbx5/kazRw= X-Google-Smtp-Source: AGHT+IEsWhGNO9PWwN6yxPPJFPF38axgdUIe+kl06bFPlN3/RZDFeJ8DZLYMKXQfKWacKtfzK/t+hg== X-Received: by 2002:a17:902:db11:b0:216:6283:5a8c with SMTP id d9443c01a7336-21c355bac6amr29773455ad.39.1737105680784; Fri, 17 Jan 2025 01:21:20 -0800 (PST) Received: from [127.0.0.2] ([103.39.127.160]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2d3e088bsm11714065ad.173.2025.01.17.01.21.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 01:21:20 -0800 (PST) From: Karthik Nayak Date: Fri, 17 Jan 2025 10:20:49 +0100 Subject: [PATCH v2 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: <20250117-kn-the-repo-cleanup-v2-2-a7fdc19688f5@gmail.com> References: <20250117-kn-the-repo-cleanup-v2-0-a7fdc19688f5@gmail.com> In-Reply-To: <20250117-kn-the-repo-cleanup-v2-0-a7fdc19688f5@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , ps@pks.im, gitster@pobox.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+kA0DAAoBPtWfJI5GjH8ByyZiAGeKIQdYHluurQTKIL1YcaiUaKadvgNayzVIx GN2Jm8OHdrh6IkBswQAAQoAHRYhBFfOTH9jdXEPy2XGBj7VnySORox/BQJniiEHAAoJED7VnySO Rox/LQEL/RazomQtgtYP4tFoz62oAa/PfgKzpYBfqD7xFAPhs/bImWOUr0A7+IFNZbDfGV008Et XvyaxL6VJnkD5EfMiELCwSkW38gDGK0k/9ItnNU/BMN1tvLs6ozAXLg35UpKsnPy4D3x3IVe2Fs 0YHnXeydYPhykFbNozE+JI4Br7pf8C3AXAN2W3qrqCqJJLq2ZZ0YGh5KBFIVMp2VvuEvuhKmAL8 tELsj+gnPTmOyWlOZeQXvCP+42KJGVlZKWvMfILK4pW69WUJOtvUqlVDVEQmkKBziA0rkvNpyyG 8dtF1pSybXoBYwerwcfhqFxaX64KHH9l3ac+SQzMvFVl3kJGa6DGzNDIp9YgmoW1HCdklT8vZPK lu7rnqiKztoDYpEW16wlkmSxgK+OLH2KcIBhdBUrLBuh8SmdOHL1hPy6Y9UwdUzmbfhaUxMiPup 0L3hxK9Fd6el1Mabm+oPWteFgLX3Xml3GttPVmfxrnU2XkfvhSc9RsD8aQz90ZmX0+AfBaBLrz4 9U= 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 Fri Jan 17 09:20:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak X-Patchwork-Id: 13943049 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 EE1941F9F74 for ; Fri, 17 Jan 2025 09:21:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737105686; cv=none; b=Wfsyix7OImcFqJmhwS3KUq94Fc7UAMJJbobihyDO/PEuDD3LZkFizi8A1dt5uSXyQmxbMu5/Ngbq4+G4Ee7qlE7BGKXkVP76L58HIj+3PWRfqHzMqSJXCO03+lHFbQKyD7Xq9HEiYdfnYQytVCBM7dT9iQeAy4dnL2diWRh6/GA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737105686; c=relaxed/simple; bh=vn4955lD7ICrmMg8ThXo/IhTjkDfCKuJju+KaDnSbLE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=F/D9cR/lpGtgovoeKO0L5ku5GgwHPzjzM/rZKQKN9lPCvrNgVGqyXgGj5eVAuuTBK7AE+A8VVejRjeFX2J3kO9LPuKI4mIbaBSDBVkrT/4d+jnb8ZyV+eu72wruNrgH7njrF6U4UNRaMSXiYBoJlE5iUSARE03KLxfc+53AeNvY= 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=Di9zN9Ow; arc=none smtp.client-ip=209.85.214.175 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="Di9zN9Ow" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-215770613dbso24713045ad.2 for ; Fri, 17 Jan 2025 01:21:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737105684; x=1737710484; 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=zk1UQ6oJZqm7WwWyDwoUPFccIhqducZWiXvQn8m+LUk=; b=Di9zN9Ow1JmnvnSSmdHGncLLLBJRExl4CPyipiy9Igie8Otcg5vux0ZUA5nO/azHC6 +kN9+QEA0dByxnuLAwAgGhQhmt9L4hpzF7Qg/FTnGCWU76L4oberKCsvh6fVReclakwF nt3vmBl0rSAr2PYBWEVN3gn7SmW5NeHBQLjLeJt0KYBSPfNAXSCA7/QcTrYYpD+on2Jc jFAQ9BbBbDcEfD29fJFDfmMccR93T4J+9daPsdsBjwEGnElpqPxWF543j8jKJNTnjn7j KK3rGd9lpT1PctY+Dbctb+MpG8baOeknBkomIYG2/TyCuZGQPAfP1DO6RAWdtO8oleRK jZ9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737105684; x=1737710484; 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=zk1UQ6oJZqm7WwWyDwoUPFccIhqducZWiXvQn8m+LUk=; b=heyfJ3lGVmpReqNG8+gFMWijThj+poQoywYK4gZQGEQ1lITgJFyyg19jz5SjKgvcNe evK4QsVnanrzTNsJuyUhp98RBTqEp4grJHhorNrFeLzsOEJ+iBIIvVmjT53Tzd6RWyrg OEVxEuLKz2ct76MOqsQA46B+buKeWegY7rb8Q2HocjX50WFEhAz6OpIe45pQKXdwGgBb MCtdaA2GL709FhDCpUUcQG3nsX69viivfS+wcH9cRBBJs39wy4jkgGGft8PpMF4GYuuw GKQlGj/hSaPrgKTrsAGTrqTD8qTX5+F7slr6oSdmGju1D9SqmkZcw0DbKIGXOENKSwOj CNsg== X-Gm-Message-State: AOJu0YwDbWu2TwKatln0xSf2A/WIeF8CPYqsqkmKvdDZGHcFUkcF8nHH XzzueMpdvM9taA+ce5uybK8NekrBHPeKe0uV6vGeiOBR8lNL3INytvZfkIl/ X-Gm-Gg: ASbGncs9avsQhCWAfYfZDybkT1ZiKDaDRxAj1p4er68thlanVIhsavTzYeap+oWlJUl 2DvGtjjiV6opcH4+eg7sqiQloSIwATa9+ZyXvMU+eZSLZHVQZhgrSHEe5shYYlqGvTP8q6CUW6W fug0xfy5hzh2lRGaDLDf6FtVEVM1MQefagyjgxYwJT+21o88H5anLLrl4rAvTMDwZ8LX8Revlcf 6qexI9dmO7Up0D60lF2rCON25DtoUk+OiWMNv8GaXhhGgWwLeJGR4LzFZQ= X-Google-Smtp-Source: AGHT+IGNeTH6irJt6i7z3sRWHpDLCqI8aaHOsEEck1WsYwQbFnFwM+HjyIn8x/KGW2fVrMhB1hyeWg== X-Received: by 2002:a17:902:d4cf:b0:215:a97a:c6bb with SMTP id d9443c01a7336-21c35400a0dmr30824915ad.12.1737105683757; Fri, 17 Jan 2025 01:21:23 -0800 (PST) Received: from [127.0.0.2] ([103.39.127.160]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2d3e088bsm11714065ad.173.2025.01.17.01.21.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 01:21:22 -0800 (PST) From: Karthik Nayak Date: Fri, 17 Jan 2025 10:20:50 +0100 Subject: [PATCH v2 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: <20250117-kn-the-repo-cleanup-v2-3-a7fdc19688f5@gmail.com> References: <20250117-kn-the-repo-cleanup-v2-0-a7fdc19688f5@gmail.com> In-Reply-To: <20250117-kn-the-repo-cleanup-v2-0-a7fdc19688f5@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , ps@pks.im, gitster@pobox.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=7524; i=karthik.188@gmail.com; h=from:subject:message-id; bh=vn4955lD7ICrmMg8ThXo/IhTjkDfCKuJju+KaDnSbLE=; b=owJ4nAHtARL+kA0DAAoBPtWfJI5GjH8ByyZiAGeKIQeUVuWfcvgL4KR20mUtxMGY8RPOjTvJs Zdzit4k6Z9SO4kBswQAAQoAHRYhBFfOTH9jdXEPy2XGBj7VnySORox/BQJniiEHAAoJED7VnySO Rox/hxoMAJl86aomyrIBJV9R5GkLF9Qz8o+WzhBjrEyKO8FMk2rRObAIslfQgaxUXY+s/VPetbB ueUrgm5L6j5pQvjUTFk1dL8Uy49zzyBIJyBUPNU3VuJ6JBZgNSgde6CSomBMYlEe5o4beMmmBKX P63B9tbbMwOmP1vGpx7g6NgscjxrCfa09Cya3qPMPUTabfsWsaqzXUIt+IWaA5WsqTiCJZi7YRT nhtux7JS3m7rLGQrdZbuezeq5QonpNVGcnk0qp0+3252oXoomAIbHy/X/Mi0n0VT534BBljahWm b0VzbJKwDp1IyAH5UjSQs5mva2gx0fR309dYm730MWxa9IL3zdTAvBe0jxJH8lISUgYyjQxTqlU aBJ0+ianIY6aWH4nzvLppquTM/G1lbWq4aao2asPbYRrOuhCVqCUsRnTJT4PEGjzZdf20NqjAo4 Ct9Vq+R7ewsAeyb1QaPuksM0cbFjLWRvChK06DsIi/jGgTJCG9eGe3+k6ysm+ZaLtuWgdivhA46 fU= 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 function. To avoid global variable usage, pass the hash function from the layers above. Since `stage_tmp_packfiles()` also resides in 'pack-write.c' and calls `write_idx_file()`, update it to accept `the_hash_algo` as a parameter and pass it through to the callee. 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 Fri Jan 17 09:20:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak X-Patchwork-Id: 13943050 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 7A8B71F8AF2 for ; Fri, 17 Jan 2025 09:21:28 +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=1737105690; cv=none; b=oOr3C9YoUeRA4Y36zz8aRw2MFFokX7iTJ/IZRH0EV4UvvveBi4rhXhzdecmiVOPLNs+dH0x4JpjrkH+1fwyOUaEiVyDrLdq/qiaKH+23ciHe+PhMdr0oP+P/+dCZwOEBfFEqEfougKob/7eQcfMxQ+AYAhWWmvPRWrWEktdtnqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737105690; c=relaxed/simple; bh=9kFuITbRumnH74PKHjusgQ2qdn/hfbWNmYOxuSJK3rk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MjMaTO/zGr2c9lWejvMzyagrSjQxewqKyMQ5L2mnlUhPIBEQ91/aK0Xe0xbPvHVr1dt9+XQpFqr9YorRcec8JM6rPnm30Vwg08hmTK5hnaM1fbeE0i3YMvuuuWzDtoXK8lE2iHWOXi3HIvy36XMfNCYJS3dk51uP1bs8+OTjBik= 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=g7GS7hRg; 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="g7GS7hRg" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2166f1e589cso46007865ad.3 for ; Fri, 17 Jan 2025 01:21:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737105687; x=1737710487; 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=bR9d6T1dx5zEkdi028Rb0GF0JUAz7X1++LakO3DyP6U=; b=g7GS7hRgl8eBRHmST8y1hKb2MmV8Fp2OAEfzacz1YSkj5VtgedHOlM2RPgrXr5ICI0 ec3HhNi3tTyYWyNb7Tr489OIWyRgLuAtlMpf30NUDb8NsSB0eeLvUlpxw9eYrCU91gZ5 liwVQfDhRpitC/Fw3JSuTh7OAMBGwmw6TSiT7deF34byYnvXg75nNniJNVqmmTV6DQoi 4rmeQ/yZ8PGJYAHzcD7/qocu/9gIvgspljnEVQQt/Nl11sNVVZUku+ReyPH/dSy536rb 5DxbxNQyRVO77rn2Jq31d6rG1Y5B4T6dV7t9g/9zSOyeRZg3GCWunGXra/6McB7mhDH/ rqYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737105687; x=1737710487; 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=bR9d6T1dx5zEkdi028Rb0GF0JUAz7X1++LakO3DyP6U=; b=uH6rhzyJKL+pVYPBDfkfjltSI7xfkPFm08Kr+U8Um3xd6N5L2A0GI+bsrEqnJFdRFE aMeo1Wo7gvEpxZRXaMzctV41L/7heyZIe9TU92I0bkP7Oo0neUzIRRi7QLF8ejwErpMk v52Jz5yLOhbje0JScrLiT64YuZS1l+shups21skREZ0yZb8qGYfb4QkskwE4Qtz9o45R 1FG/NgB26kMHjPUCxv46hJfsg4V4vO4Ldz+m99vF9974V7K+Y+X/MeBIu0Kra5FAS6Cf xRci1AJL0leb2RCLHJkZKBkkG0LzqZoEiOXAeXnYMpGZ3sow7pbPCruEXKzv8/BAb5iv CYfw== X-Gm-Message-State: AOJu0YyGsqDB2Zb2uiGUTiq6mKbS59WGJ/2lciPz7WCuctW7JH7bc2mj VoscsFeZN+nyHrJ8w1ablctTeFYo/c1O34NfOKxAhjqKn6SUhVzKs/fK+IyE X-Gm-Gg: ASbGncv5QEgFFDI1CDnIcNPhRr3kYzi8dCgDiLPjverL5gt4L5PhYBwrnRKDBbZ3qi3 bV9WhZZX1BNrxyAGmRhZpM233KrgFbqjcIUZWcSXTR6CyQzE9BzEXepBLURzGSa+zdU7tDTHJsq a6UI/J+gWYVrGimKzXQa550s8ueMHxHsWQYyxYC6b5Q0lmps4pFYTRE0tXnCcA6aBvIGpXyCkCr Y4oZbiP2taGbcyzEL8CceXhYJnoqBBiX3M77UDmWzaORmXnXR0BuXu2tNI= X-Google-Smtp-Source: AGHT+IGOg4yPgkc1kqWDnhijnwohTIsnV16NY6BMWLJAgNUbb1jCbZfSAQXOoshPnu36D+BkDMeVcA== X-Received: by 2002:a17:902:e746:b0:215:97c5:52b4 with SMTP id d9443c01a7336-21c35631dd4mr28015285ad.39.1737105687386; Fri, 17 Jan 2025 01:21:27 -0800 (PST) Received: from [127.0.0.2] ([103.39.127.160]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2d3e088bsm11714065ad.173.2025.01.17.01.21.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 01:21:26 -0800 (PST) From: Karthik Nayak Date: Fri, 17 Jan 2025 10:20:51 +0100 Subject: [PATCH v2 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: <20250117-kn-the-repo-cleanup-v2-4-a7fdc19688f5@gmail.com> References: <20250117-kn-the-repo-cleanup-v2-0-a7fdc19688f5@gmail.com> In-Reply-To: <20250117-kn-the-repo-cleanup-v2-0-a7fdc19688f5@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , ps@pks.im, gitster@pobox.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5990; i=karthik.188@gmail.com; h=from:subject:message-id; bh=9kFuITbRumnH74PKHjusgQ2qdn/hfbWNmYOxuSJK3rk=; b=owJ4nAHtARL+kA0DAAoBPtWfJI5GjH8ByyZiAGeKIQedJyEX4XZdBK49kKXe7e12qImI/Vl5+ yvGvLsI23/HkokBswQAAQoAHRYhBFfOTH9jdXEPy2XGBj7VnySORox/BQJniiEHAAoJED7VnySO Rox/Mw0L/iS7FV1W9gijNbJz5Bin2tUCqRLHdB91driahVgaNUbGny8avWqj/hwMWCSoX3PmdUY zj7Q5WeyfZuEWvJHmHka8iFIkzZMMTgUi9SJM9RoOv+mwluHeBFdM4D4XxLY6Ch9g/k6s3KmIw9 83PogEcxUXiIPeDbuO8Q+snabyQFLEFivRF5OHsilsiQTUj1oGor5R3ohtGJigYbhFIwSYBBCJc BhXnBuEk5nd6PbWxTg5EciJvDylvm+n0uJE1VodUQ3JdoV38sk1kvJn8hkATRamnL7yUVDSrQaa 8XrutL+eXJg2DXaxJDa/8bXvmASyVwUnYJ0oGIxOLvd8xSqGDqoetHQxMK+4GGbjz0Nb2b8Bm9t GS90t7Kf9gMe1nm2j7nQz9hqNd8RVtJTgCCexO4RyeGhZ2unJxuzTgUmH53QC1dCGJjCbG2TTEi twLzva7/Cj3++eiHta/O9nu/aBX81Mv6ILjvTiMkD2WoW4OhfAElBOA6b6x7pbRmn7ev8NLzAR5 3s= 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 function. To avoid global variable usage, let's pass the hash function 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 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 Fri Jan 17 09:20:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak X-Patchwork-Id: 13943051 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 0434E1F9EA4 for ; Fri, 17 Jan 2025 09:21:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737105693; cv=none; b=JRjtn06ERjzggIjuSfRtOWNGzgcw737hYAK1Z7kAAnbVs+ZQgfSXtnFNWIXkuWD71GnqROy7IQqUGmc31FZ0TgUUSe9hISwWwuzrdBwSHt2zeR82agfuLufC93yjIapCvKp9GVVHToo7oJy3B9KDXh3SbsGceWnMK+NogySFqlc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737105693; c=relaxed/simple; bh=23JyOMoFwF4jiMtL4yVRFt0D3XC8k/jej3UC8iDqdWI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WESZ/dK/ZJdHYAHhsim37a7dQ/jQEF/ttWXD5sOeEO/UeDBzmQkNHkWUe3KEgNr7R72I2qMY7LSJSoMDyovhWibMQA/lxivUxNTZqlFq2t8vc3ftJMI2KSGMSmfrE1K3iD4L8cgneMmInLVF91bAmmfPhEuqKwIr7EB+jS0I70M= 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=mAnEcD0o; arc=none smtp.client-ip=209.85.214.180 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="mAnEcD0o" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-21bc1512a63so37169465ad.1 for ; Fri, 17 Jan 2025 01:21:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737105690; x=1737710490; 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=F86bRfZ0CRnEFPj1MwKkdvsCHGwQ3o0fpITygS2KPxc=; b=mAnEcD0ojlBFwu98hiY5cJamWADhYOV7pW2HGuq209/J2wBKPGWjY6yYJSu4q+j0Bn 5L899a5p9oFJoWMqqBwPxsIFEWGN9Gx21LKgR//wdQCNv1hOwK22Xdi1SQmaucNuPIVB WLaWbWQHXcVJuJj+GS6AiHiHUmFX68d+aqV17dd71eP+PhYlB2XjJUQuwMoU4BCHKVA0 kGjmihY9RK4EryygokyC7zGEEYzfHmWO51377xn9EsfMhk7ZHJ081V8NWBItlsgrGb44 tLrekx7XoKq1zg0TYRGChBDOnSBL7B3jkVz8/sh+48vppi/Mc9tJMgZ/r8rTAcaQrlIH reoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737105690; x=1737710490; 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=F86bRfZ0CRnEFPj1MwKkdvsCHGwQ3o0fpITygS2KPxc=; b=sky2swSPaKBR5trlpCajAm1/D/naR10ZVfXFUML102GTgQMPML3a2mNTVsvtJKKvZX Yl71VIxGhjdx28nyYBG/4WjNE7ni55PeB67NjZd4+Ons4kmZWPxNMxHoDJAmzGWXfNaa ApLH86FTL4b0tL4ysXmQYjG2K47EPE4+8qvyrxR3NYTJd/RKqLzbnXNgbffqYeupKOGk enE8O+mVFKiw6ocIKXZmQNAy1zEnUpXazdx62y8RgHFZV/7gdwYOK05qPaUPWLPhKelm 2BSRYFgbH2zxrFQBO6gm9iSADREkgmI2ZIdwmmW8Ab70/iEY1uRm0N67K1HJUTOWEggQ vrPw== X-Gm-Message-State: AOJu0YzidY8Oy00MkrJfUed7UavudcS2yI34WYGXXZ//rx9vbxf+2Y0C TaLGxiQNBH/9gXuuDuSqPTVAHvwxa5LoLw3oJKDdxHWP7SCndh3rBmf85igr X-Gm-Gg: ASbGnctX5NSYR6+we8DEz8QzsZo9FF2W6r1MxfAK0KXZe1o4aL9uhOlckhVJxBgnX/+ c/YBKNSWkYs6uGvZFRfV9eCDYiplmPtwz1sFBf6d4dwCTXVX3ff78tnFAAuoQsqbyXoKXx1Qn8C oMBmPL+nIjA3FwqvWqfnnym5r2jM0QRzjNLTtm6zh5iVmJbXvvyLY1W+gOEV+JD3QTAPTZzN3ij uvAs6xUEJPlnqFYPrkyjXizVKE+xFz6KVZQQM/EcOmgPUwaszyyfsfnXTI= X-Google-Smtp-Source: AGHT+IHBq5jBQTl2XkrBMXVNhVcNAVx89WYSsu85yjYT5t2UMSKfhqsJSqvWINjPMJk/gUybO0TvTA== X-Received: by 2002:a17:902:d492:b0:216:1543:195e with SMTP id d9443c01a7336-21c3553b227mr31320065ad.5.1737105690255; Fri, 17 Jan 2025 01:21:30 -0800 (PST) Received: from [127.0.0.2] ([103.39.127.160]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2d3e088bsm11714065ad.173.2025.01.17.01.21.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 01:21:29 -0800 (PST) From: Karthik Nayak Date: Fri, 17 Jan 2025 10:20:52 +0100 Subject: [PATCH v2 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: <20250117-kn-the-repo-cleanup-v2-5-a7fdc19688f5@gmail.com> References: <20250117-kn-the-repo-cleanup-v2-0-a7fdc19688f5@gmail.com> In-Reply-To: <20250117-kn-the-repo-cleanup-v2-0-a7fdc19688f5@gmail.com> To: git@vger.kernel.org Cc: Karthik Nayak , ps@pks.im, gitster@pobox.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=23JyOMoFwF4jiMtL4yVRFt0D3XC8k/jej3UC8iDqdWI=; b=owJ4nAHtARL+kA0DAAoBPtWfJI5GjH8ByyZiAGeKIQgQjCdjEP5Q9aZoXbQwrSqb+bG5CJtmL aghk66vonDotokBswQAAQoAHRYhBFfOTH9jdXEPy2XGBj7VnySORox/BQJniiEIAAoJED7VnySO Rox/cRYL/iC1vLVWiFGE69b6+SORJrpucJprZn07SQsB5K88YnkeXmUrEvXvuwVjS9B3fVl/npb FjutIUP+xrc7sSK1up/Y8A1HojLwINrfDM0POypdu3pZDM6ID8R5AxEfTERg+yiJVVoHznzmGWh Euk8W2dQoXDlgdYIpxJAz3cJBe1AlE/WroiSA6Y7bBYPXNdD5R+uwGFANce0oOgFk9BI2ByaYmF DxelSRIY7t7ft3lR9761gRID0yWnEUlONfHiW4q+LSdLrWfENXiQ5agjRNrVFpk9UzDShYm8Gfo 47SDlkD1/Vts48M2kRxcNv7KoAxFIC0MrDM5/pVBc+1tphbi2dAVmQ/bEzsrY95+4fRXFuZL38r mZa5at3kwEI96VmS7p/Ac1Iw2jClTqenttOi0n+viWZo52N5jF4dNub48NM34mdtiTMNVipixNT uwEFGhLv+v972LUhZzm+piBqNNK7vtaTItABhJoJB2gL5xqyh+MemrLd/pW4zV9Ai/vx1gcs2f5 S0= 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 from down as we've added made them available in the previous few commits. 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); }