This is a small series to remove global variable usage from `pack-write.c`. Mostly it bubble's up the usage of global variables to upper layers. The only exception is in `write-midx.c`, which was cleaned of global variable usage, so there, we use the repo that is in available in the context. This series is based on fbe8d3079d (Git 2.48, 2025-01-10) with 'ps/more-sign-compare' and 'ps/the-repository' merged in. There are no conflicts with topics in 'next', however there is a conflict with 'tb/incremental-midx-part-2' in 'seen', the fix is simple but happy to merge that in too if necessary. Signed-off-by: Karthik Nayak <karthik.188@xxxxxxxxx> --- Changes in v3: - Fix the ambiguous commit message in the last commit. - Link to v2: https://lore.kernel.org/r/20250117-kn-the-repo-cleanup-v2-0-a7fdc19688f5@xxxxxxxxx Changes in v2: - Fixes to the commit messages to: - Fix copy-paste error s/the_hash_algo/the_repository - Mention why certain functions are modified - Small cleanups - Link to v1: https://lore.kernel.org/r/20250116-kn-the-repo-cleanup-v1-0-a2f4c8e1c4c3@xxxxxxxxx --- Karthik Nayak (5): pack-write: pass hash_algo to `fixup_pack_header_footer()` pack-write: pass repository to `index_pack_lockfile()` pack-write: pass hash_algo to `write_idx_file()` pack-write: pass hash_algo to `write_rev_file()` pack-write: pass hash_algo to internal functions builtin/fast-import.c | 11 +++--- builtin/index-pack.c | 11 +++--- builtin/pack-objects.c | 12 +++--- builtin/receive-pack.c | 2 +- bulk-checkin.c | 7 ++-- fetch-pack.c | 4 +- midx-write.c | 4 +- pack-write.c | 99 +++++++++++++++++++++++++++----------------------- pack.h | 30 ++++++++++++--- 9 files changed, 106 insertions(+), 74 deletions(-) --- Range-diff versus v2: 1: d3812f88e6 ! 1: 5f646111d0 pack-write: pass hash_algo to `fixup_pack_header_footer()` @@ Commit message 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. + avoid global variable usage, pass a hash_algo 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. + 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 <karthik.188@xxxxxxxxx> 2: 89255a4822 = 2: 696e991823 pack-write: pass repository to `index_pack_lockfile()` 3: 5ccf220732 ! 3: 21fefb8279 pack-write: pass hash_algo to `write_idx_file()` @@ Commit message pack-write: pass hash_algo to `write_idx_file()` 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. + 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 `the_hash_algo` as a parameter - and pass it through to the callee. + `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 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. + 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 <karthik.188@xxxxxxxxx> 4: 95b1f784e2 ! 4: 3f730b26d1 pack-write: pass hash_algo to `write_rev_file()` @@ Commit message pack-write: pass hash_algo to `write_rev_file()` 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'. + 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 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. + 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 5: 50da9bf405 ! 5: 7d1d42ca67 pack-write: pass hash_algo to internal functions @@ Commit message 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. + 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. --- base-commit: 8b2efc058aaa3d1437678616bccf7c5f7ce1f92b change-id: 20250110-kn-the-repo-cleanup-44144fa42dc3 Thanks - Karthik