summaryrefslogtreecommitdiff
path: root/notes-merge.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-03-10 08:13:31 +0100
committerJunio C Hamano <gitster@pobox.com>2025-03-10 13:16:20 -0700
commit7d70b29c4f0b2fd3c6698956d9fb4026632d9c6e (patch)
treee089b1c2654d7dcb48ad39c93ef849efc811b45a /notes-merge.c
parent8ca9fa60a63c97bb9397f5de294aef53df90e7a0 (diff)
hash: stop depending on `the_repository` in `null_oid()`
The `null_oid()` function returns the object ID that only consists of zeroes. Naturally, this ID also depends on the hash algorithm used, as the number of zeroes is different between SHA1 and SHA256. Consequently, the function returns the hash-algorithm-specific null object ID. This is currently done by depending on `the_hash_algo`, which implicitly makes us depend on `the_repository`. Refactor the function to instead pass in the hash algorithm for which we want to retrieve the null object ID. Adapt callsites accordingly by passing in `the_repository`, thus bubbling up the dependency on that global variable by one layer. There are a couple of trivial exceptions for subsystems that already got rid of `the_repository`. These subsystems instead use the repository that is available via the calling context: - "builtin/grep.c" - "grep.c" - "refs/debug.c" There are also two non-trivial exceptions: - "diff-no-index.c": Here we know that we may not have a repository initialized at all, so we cannot rely on `the_repository`. Instead, we adapt `diff_no_index()` to get a `struct git_hash_algo` as parameter. The only caller is located in "builtin/diff.c", where we know to call `repo_set_hash_algo()` in case we're running outside of a Git repository. Consequently, it is fine to continue passing `the_repository->hash_algo` even in this case. - "builtin/ls-files.c": There is an in-flight patch series that drops `USE_THE_REPOSITORY_VARIABLE` in this file, which causes a semantic conflict because we use `null_oid()` in `show_submodule()`. The value is passed to `repo_submodule_init()`, which may use the object ID to resolve a tree-ish in the superproject from which we want to read the submodule config. As such, the object ID should refer to an object in the superproject, and consequently we need to use its hash algorithm. This means that we could in theory just not bother about this edge case at all and just use `the_repository` in "diff-no-index.c". But doing so would feel misdesigned. Remove the `USE_THE_REPOSITORY_VARIABLE` preprocessor define in "hash.c". Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'notes-merge.c')
-rw-r--r--notes-merge.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/notes-merge.c b/notes-merge.c
index 67a472020d..5008faef45 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -617,7 +617,7 @@ int notes_merge(struct notes_merge_options *o,
if (repo_get_merge_bases(the_repository, local, remote, &bases) < 0)
exit(128);
if (!bases) {
- base_oid = null_oid();
+ base_oid = null_oid(the_hash_algo);
base_tree_oid = the_hash_algo->empty_tree;
if (o->verbosity >= 4)
printf("No merge base found; doing history-less merge\n");