From: Junio C Hamano <gitster@pobox.com>
To: Tian Yuchen <cat@malon.dev>
Cc: git@vger.kernel.org,
Christian Couder <christian.couder@gmail.com>,
Ayush Chandekar <ayu.chandekar@gmail.com>,
Olamide Caleb Bello <belkid98@gmail.com>
Subject: Re: [PATCH v4] repository: move fetch_if_missing into struct repository
Date: Thu, 13 Aug 2026 09:32:24 -0700 [thread overview]
Message-ID: <xmqqfr0it207.fsf@gitster.g> (raw)
In-Reply-To: <20260813061125.1089553-1-cat@malon.dev> (Tian Yuchen's message of "Thu, 13 Aug 2026 14:11:25 +0800")
Tian Yuchen <cat@malon.dev> writes:
> 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.
prev parent reply other threads:[~2026-08-13 16:32 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-15 1:18 [PATCH v1] repository: move fetch_if_missing into struct repository Tian Yuchen
2026-07-15 3:27 ` Junio C Hamano
2026-07-15 4:58 ` Tian Yuchen
2026-07-15 6:35 ` Patrick Steinhardt
2026-07-16 7:06 ` Tian Yuchen
2026-07-16 15:28 ` Junio C Hamano
2026-07-16 7:29 ` [PATCH v2] " Tian Yuchen
2026-08-01 15:53 ` Tian Yuchen
2026-08-04 8:24 ` Patrick Steinhardt
2026-08-04 17:38 ` Junio C Hamano
2026-08-05 12:34 ` Tian Yuchen
2026-08-05 12:10 ` Tian Yuchen
2026-08-07 9:41 ` [PATCH v3] " Tian Yuchen
2026-08-07 17:03 ` Junio C Hamano
2026-08-09 15:00 ` Tian Yuchen
2026-08-13 6:11 ` [PATCH v4] " Tian Yuchen
2026-08-13 16:32 ` Junio C Hamano [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqfr0it207.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=ayu.chandekar@gmail.com \
--cc=belkid98@gmail.com \
--cc=cat@malon.dev \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox