You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 is also a single non-trivial exception with "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.
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
0 commit comments