git/list[1] front-page[2] threads[3] people[4] search[5] about
wed 2026-10-07 18:03 UTC

Re: [PATCH v2] repository: move fetch_if_missing into struct repository

From
Patrick Steinhardt <ps@pks.im>
Date
Aug 4, 2026, 08:24 UTC
Message-ID
<anGhtfPaGK7v3NNR@pks.im>
In-Reply-To
<20260716072954.582235-1-cat@malon.dev>
On Thu, Jul 16, 2026 at 03:29:54PM +0800, Tian Yuchen wrote:
Show 24 quoted lines
> The global variable 'fetch_if_missing' controls whether a missing
> object check should prompt a lazy fetch from a promisor remote.
> In order to continue the libification effort, move it into
> 'struct repository' and initialize it to 1 by default to keep the
> previous behavior.
> 
> Note that in builtin/fsck.c and builtin/index-pack.c, when running
> related commands with the '-h' parameter, the 'repo' pointer is not
> passed in. To prevent null pointer dereferences, we defer
> operations on the repo until after parameter parsing is complete.
> 
> Additionally, update the partial clone documentation to reflect
> that this is now a per-repository flag.
> 
> Mentored-by: Christian Couder <christian.couder@gmail.com>
> Mentored-by: Ayush Chandekar <ayu.chandekar@gmail.com>
> Mentored-by: Olamide Caleb Bello <belkid98@gmail.com>
> Signed-off-by: Tian Yuchen <cat@malon.dev>
> ---
> 
> Change since V1:
> 
> - Following Patrick's advice, use the_repository whenever possible
>   without re-introducing #define USE_THE_REPOSITORY_VARIABLE.

It would be great to include the range-diff compared to the previous version so that it's easier for the reviewer to spot what's changed. Tools like b4 automate this for you :)

Show 24 quoted lines
> diff --git a/builtin/index-pack.c b/builtin/index-pack.c
> index 0793dc595c..74f9694662 100644
> --- a/builtin/index-pack.c
> +++ b/builtin/index-pack.c
> @@ -1898,15 +1898,16 @@ int cmd_index_pack(int argc,
>  	int report_end_of_input = 0;
>  	int hash_algo = 0;
>  
> +	show_usage_if_asked(argc, argv, index_pack_usage);
> +
>  	/*
>  	 * index-pack never needs to fetch missing objects except when
>  	 * REF_DELTA bases are missing (which are explicitly handled). It only
>  	 * accesses the repo to do hash collision checks and to check which
>  	 * REF_DELTA bases need to be fetched.
>  	 */
> -	fetch_if_missing = 0;
> -
> -	show_usage_if_asked(argc, argv, index_pack_usage);
> +	if (repo)
> +		the_repository->fetch_if_missing = 0;
>  
>  	disable_replace_refs();
>  

This one looks a bit weird -- we check for `repo`, but then set `the_repository->fetch_if_missing`. We can probably just loose the conditional completely, and furthermore we don't need to reorder any code here at all anymore.

Other than that this patch looks good to me, thanks!
Patrick
Previous: Tian YuchenNext: Junio C Hamano
Message 9 of 26 in “repository: move fetch_if_missing into struct repository”
  1. repository: move fetch_if_missing into struct repositoryTian Yuchen, Jul 15, 2026
  2. Junio C HamanoJul 15, 2026
  3. Tian YuchenJul 15, 2026
  4. Patrick SteinhardtJul 15, 2026
  5. Tian YuchenJul 16, 2026
  6. repository: move fetch_if_missing into struct repositoryTian Yuchen, Jul 16, 2026
  7. Junio C HamanoJul 16, 2026
  8. Tian YuchenAug 1, 2026
  9. Patrick SteinhardtAug 4, 2026
  10. Junio C HamanoAug 4, 2026
  11. Tian YuchenAug 5, 2026
  12. Tian YuchenAug 5, 2026
  13. repository: move fetch_if_missing into struct repositoryTian Yuchen, Aug 7, 2026
  14. Junio C HamanoAug 7, 2026
  15. Tian YuchenAug 9, 2026
  16. repository: move fetch_if_missing into struct repositoryTian Yuchen, Aug 13, 2026
  17. Junio C HamanoAug 13, 2026
  18. 0/2 repository: move fetch_if_missing into struct repositoryTian Yuchen, Aug 14, 2026
  19. 1/2 pack-objects: give fetch_if_missing call sites access to 'repo'Tian Yuchen, Aug 14, 2026
  20. 2/2 repository: move fetch_if_missing into struct repositoryTian Yuchen, Aug 14, 2026
  21. Junio C HamanoAug 14, 2026
  22. Junio C HamanoAug 14, 2026
  23. Tian YuchenAug 15, 2026
  24. repository: move fetch_if_missing into struct repositoryTian Yuchen, Aug 15, 2026
  25. Junio C HamanoAug 15, 2026
  26. Tian YuchenAug 16, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.