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

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

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 13, 2026, 16:32 UTC
Message-ID
<xmqqfr0it207.fsf@gitster.g>
In-Reply-To
<20260813061125.1089553-1-cat@malon.dev>
Tian Yuchen <cat@malon.dev> writes:
Show 44 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>
> ---
>
> Changes since v3:
>
>  - Use revs->repo in revision.c instead of the_repository.
>
>  - Coordinate the other topics. Specifically, for common-init.c, use
>  the_repository->fetch_if_missing in setup_environment(), etc. This patch
>  currently does not conflict with seen or next.
>
>  Documentation/technical/partial-clone.adoc |  2 +-
>  builtin/fetch-pack.c                       |  2 +-
>  builtin/fsck.c                             |  6 +++---
>  builtin/index-pack.c                       |  8 ++++----
>  builtin/pack-objects.c                     | 14 +++++++-------
>  builtin/prune.c                            |  2 +-
>  builtin/rev-list.c                         | 10 +++++-----
>  common-init.c                              |  2 +-
>  git.c                                      |  2 +-
>  midx-write.c                               |  2 +-
>  odb.c                                      |  4 +---
>  odb.h                                      |  8 --------
>  repository.c                               |  1 +
>  repository.h                               |  6 ++++++
>  revision.c                                 |  2 +-
>  15 files changed, 34 insertions(+), 37 deletions(-)

There still are references to the_repository->fetch_if_missing remaining in the codebase with this change.

        $ git grep -l -e 'the_repository->fetch_if_missing'
        builtin/fetch-pack.c
        builtin/pack-objects.c
        builtin/rev-list.c
        common-init.c
        git.c

Some of them I suspect should just use the caller supplied 'repo', possibly after removing the UNUSED marker. For example:

        int cmd_fetch_pack(int argc,
                           const char **argv,
                           const char *prefix UNUSED,
                           struct repository *repo UNUSED)
        {
                int i, ret;
        ...
                enum protocol_version version;
                the_repository->fetch_if_missing = 0;
                packet_trace_identity("fetch-pack");
                memset(&args, 0, sizeof(args));
                list_objects_filter_init(&args.filter_options);
                args.uploadpack = "git-upload-pack";
                show_usage_if_asked(argc, argv, fetch_pack_usage);

As { "fetch-pack", cmd_fetch_pack } in the git.c:commands[] array is marked as RUN_SETUP, repo will not be NULL unless "git fetch-pack -h" is requested, and when repo is NULL, show_usage_if_asked() will give the short help text and never return.

So I think it makes sense to set 'fetch_if_missing' *after* the call to show_usage_if_asked() and set it in 'repo', not in 'the_repository'.

Other hits in the above "git grep" output looked similar. The code paths in pack-objects.c may need a preliminary clean-up patch (or two) before moving fetch_if_missing to the repository instance. I.e., pass repo through the call graph from cmd_pack_objects() to read_stdin_packs(), and then update assignments to fetch_if_missing variable to instead assign to repo->fetch_if_missing in a second step. There are other code paths that want similar clean-up.

HTH.
Previous: Tian YuchenNext: Tian Yuchen
Message 17 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.