Re: [PATCH v2 12/12] hash: stop depending on `the_repository` in `null_oid()`
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 6, 2025, 19:14 UTC
- Message-ID
- <xmqqr03ageej.fsf@gitster.g>
- In-Reply-To
- <20250306-b4-pks-objects-without-the-repository-v2-12-f3465327be69@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 13 quoted lines
> diff --git a/builtin/ls-files.c b/builtin/ls-files.c
> index a4431429b7d..2d2e90bc23a 100644
> --- a/builtin/ls-files.c
> +++ b/builtin/ls-files.c
> @@ -234,7 +234,7 @@ static void show_submodule(struct repository *superproject,
> {
> struct repository subrepo;
>
> - if (repo_submodule_init(&subrepo, superproject, path, null_oid()))
> + if (repo_submodule_init(&subrepo, superproject, path, null_oid(the_hash_algo)))
> return;
>
> if (repo_read_index(&subrepo) < 0)This has an obvious semantic interaction with what is done in Usman's series <20250306143629.1267358-7-usmanakinyemi202@gmail.com> where builtin/ls-files.c claims that it got rid of its dependence on the_repository.
The resulting ls-files still calls null_oid() here, hence it depends on the_hash_algo hence indirectly on the_repository. When these topics are merged together, builtin/ls-files.c again needs to be marked that it still needs the_repository variable in order to see the_hash_algo.
I _think_ the subrepo is not allowed to use different hash from the superproject, so we can pass superproject->hash_algo instead in this series to make it easier on the other topic?
What do you think?
Perhaps we should have hidden null_oid() as requiring the_repository just like the_hash_algo is guarded like so
#ifdef USE_THE_REPOSITORY_VARIABLE
# include "repository.h"
# define the_hash_algo the_repository->hash_algo
#endifin <hash.h>.
In other words, I wish we had the following patch already applied, before Usman started working on the other topic.
But with this topic getting solidified, it would become a moot point to do that in the longer term. This series removes null_oid() that had the implicit dependency anyway.
diff --git c/hash.h w/hash.h index 4367acfec5..3c9ccb550d 100644 --- c/hash.h +++ w/hash.h @@ -340,7 +340,9 @@ static inline int hash_algo_by_ptr(const struct git_hash_algo *p) const struct git_hash_algo *unsafe_hash_algo(const struct git_hash_algo *algop); +#ifdef USE_THE_REPOSITORY_VARIABLE const struct object_id *null_oid(void); +#endif static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop) {