Subject: Re: [PATCH 06/14] server-info: stop using `the_repository`

From: shejialuo <[email-masked]>
Date: Tue, 17 Dec 2024 20:31:04 +0800

On Tue, Dec 17, 2024 at 07:43:53AM +0100, Patrick Steinhardt wrote:
> Stop using `the_repository` in the "server-info" subsystem by passing in
> a repository when updating server info and storing the repository in the
> `update_info_ctx` structure to make it accessible to other functions.
> 
> Adjust callers accordingly by using `the_repository`. While there may be
> some callers that have a repository available in their context, this
> trivial conversion allows for easier verification and bubbles up the use
> of `the_repository` by one level.
> 
> Signed-off-by: Patrick Steinhardt <[email-masked]>
> ---
>  builtin/receive-pack.c       |  2 +-
>  builtin/repack.c             |  2 +-
>  builtin/update-server-info.c |  2 +-
>  server-info.c                | 40 ++++++++++++++++++++++------------------
>  server-info.h                |  4 +++-
>  5 files changed, 28 insertions(+), 22 deletions(-)
> 

> -int update_server_info(int force)
> +int update_server_info(struct repository *r, int force)
>  {
>  	/* We would add more dumb-server support files later,
>  	 * including index of available pack files and their
>  	 * intended audiences.
>  	 */
>  	int errs = 0;
> +	char *path;
>  
> -	errs = errs | update_info_refs(force);
> -	errs = errs | update_info_packs(force);
> +	errs = errs | update_info_refs(r, force);
> +	errs = errs | update_info_packs(r, force);
>  
>  	/* remove leftover rev-cache file if there is any */
> -	unlink_or_warn(git_path("info/rev-cache"));
> +	path = repo_git_path(r, "info/rev-cache");
> +	unlink_or_warn(path);
> +	free(path);
>  

The original "git_path" will be returned from the static string buffers,
so there is no need to free. But "repo_git_path" will return a allocated
string, the caller need to explicit free this. Make sense.

>  	return errs;
>  }