Subject: Re: [PATCH 05/16] refs: pass repo when retrieving submodule ref store

From: Junio C Hamano <[email-masked]>
Date: Thu, 16 May 2024 11:44:17 -0700

Patrick Steinhardt <[email-masked]> writes:

> Modify the function to accept the parent repository as parameter and
> move the global map into `struct repository`. Like this it becomes
> possible to look up submodule ref stores for arbitrary repositories.

Hmph.

> diff --git a/refs.c b/refs.c
> index 542acb25ff..86008ce7b4 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -1949,8 +1949,7 @@ int resolve_gitlink_ref(const char *submodule, const char *refname,
>  	struct ref_store *refs;
>  	int flags;
>  
> -	refs = get_submodule_ref_store(submodule);
> -
> +	refs = repo_get_submodule_ref_store(the_repository, submodule);
>  	if (!refs)
>  		return -1;

This still wants to work on the_repository, which means at this 5th
step of 16-patch series, we cannot do a submodule of a submodule
that hangs below the top-level superproject yet?

> @@ -2069,20 +2066,15 @@ struct ref_store *get_submodule_ref_store(const char *submodule)
>  		goto done;
>  
>  	subrepo = xmalloc(sizeof(*subrepo));
> -	/*
> -	 * NEEDSWORK: Make get_submodule_ref_store() work with arbitrary
> -	 * superprojects other than the_repository. This probably should be
> -	 * done by making it take a struct repository * parameter instead of a
> -	 * submodule path.
> -	 */
> -	if (repo_submodule_init(subrepo, the_repository, submodule,
> +
> +	if (repo_submodule_init(subrepo, repo, submodule,
>  				null_oid())) {
>  		free(subrepo);
>  		goto done;
>  	}
>  	refs = ref_store_init(subrepo, submodule_sb.buf,
>  			      REF_STORE_READ | REF_STORE_ODB);
> -	register_ref_store_map(&submodule_ref_stores, "submodule",
> +	register_ref_store_map(&repo->submodule_ref_stores, "submodule",
>  			       refs, submodule);
>  
>  done:

Nice.