[Outreachy PATCH v2] list-objects-filter-options: pass repository to partial clone helpers
- From
- Dorine Tipo <dorine.a.tipo@gmail.com>
- Date
- Oct 30, 2026, 16:59 UTC
- Message-ID
- <20261030165923.53000-1-dorine.a.tipo@gmail.com>
- In-Reply-To
- <20261025190253.2207856-1-dorine.a.tipo@gmail.com>
partial_clone_register() and partial_clone_get_default_filter_spec() use `the_repository` to look up promisor remotes and to update the repository's configuration, which ties them to the main repository of the process.
Accept the repository as a parameter instead, and have the callers in builtin/clone.c and builtin/fetch.c pass `the_repository` explicitly. This moves the dependency on the global one level up, without changing behavior.
Remove the USE_THE_REPOSITORY_VARIABLE definition from list-objects-filter-options.c, as the file no longer uses `the_repository`.
Helped-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com> Signed-off-by: Dorine Tipo <dorine.a.tipo@gmail.com> --- Changes since v1: - Drop USE_THE_REPOSITORY_VARIABLE, which is no longer needed
builtin/clone.c | 3 ++- builtin/fetch.c | 7 +++++-- list-objects-filter-options.c | 16 ++++++++-------- list-objects-filter-options.h | 3 +++ 4 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/builtin/clone.c b/builtin/clone.c index 44037dd428..5a6859065e 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -1619,7 +1619,8 @@ int cmd_clone(int argc, remote_head_points_at, &branch_top); if (filter_options.choice) - partial_clone_register(remote_name, &filter_options); + partial_clone_register(the_repository, remote_name, + &filter_options); if (is_local) clone_local(path, git_dir); diff --git a/builtin/fetch.c b/builtin/fetch.c index 1f76ae6242..5277047476 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -2436,7 +2436,8 @@ static inline void fetch_one_setup_partial(struct remote *remote, * remote if there is currently no default filter-spec. */ if (filter_options->choice) { - partial_clone_register(remote->name, filter_options); + partial_clone_register(the_repository, remote->name, + filter_options); return; } @@ -2446,7 +2447,9 @@ static inline void fetch_one_setup_partial(struct remote *remote, * the config. */ if (!filter_options->choice) - partial_clone_get_default_filter_spec(filter_options, remote->name); + partial_clone_get_default_filter_spec(the_repository, + filter_options, + remote->name); return; } diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c index bc5d98f9e6..b74caf3bf7 100644 --- a/list-objects-filter-options.c +++ b/list-objects-filter-options.c @@ -1,5 +1,3 @@ -#define USE_THE_REPOSITORY_VARIABLE - #include "git-compat-util.h" #include "config.h" #include "gettext.h" @@ -362,6 +360,7 @@ void list_objects_filter_release( } void partial_clone_register( + struct repository *repo, const char *remote, struct list_objects_filter_options *filter_options) { @@ -370,7 +369,7 @@ void partial_clone_register( char *filter_name; /* Check if it is already registered */ - if ((promisor_remote = repo_promisor_remote_find(the_repository, remote))) { + if ((promisor_remote = repo_promisor_remote_find(repo, remote))) { if (promisor_remote->partial_clone_filter) /* * Remote is already registered and a filter is already @@ -378,12 +377,12 @@ void partial_clone_register( */ return; } else { - if (upgrade_repository_format(the_repository, 1) < 0) + if (upgrade_repository_format(repo, 1) < 0) die(_("unable to upgrade repository format to support partial clone")); /* Add promisor config for the remote */ cfg_name = xstrfmt("remote.%s.promisor", remote); - repo_config_set(the_repository, cfg_name, "true"); + repo_config_set(repo, cfg_name, "true"); free(cfg_name); } @@ -393,19 +392,20 @@ void partial_clone_register( */ filter_name = xstrfmt("remote.%s.partialclonefilter", remote); /* NEEDSWORK: 'expand' result leaking??? */ - repo_config_set(the_repository, filter_name, + repo_config_set(repo, filter_name, expand_list_objects_filter_spec(filter_options)); free(filter_name); /* Make sure the config info are reset */ - repo_promisor_remote_reinit(the_repository); + repo_promisor_remote_reinit(repo); } void partial_clone_get_default_filter_spec( + struct repository *repo, struct list_objects_filter_options *filter_options, const char *remote) { - struct promisor_remote *promisor = repo_promisor_remote_find(the_repository, + struct promisor_remote *promisor = repo_promisor_remote_find(repo, remote); struct strbuf errbuf = STRBUF_INIT; diff --git a/list-objects-filter-options.h b/list-objects-filter-options.h index 77d7bbc846..6a349cb4da 100644 --- a/list-objects-filter-options.h +++ b/list-objects-filter-options.h @@ -6,6 +6,7 @@ #include "strbuf.h" struct option; +struct repository; /* * The list of defined filters for list-objects. @@ -158,9 +159,11 @@ static inline void list_objects_filter_set_no_filter( } void partial_clone_register( + struct repository *repo, const char *remote, struct list_objects_filter_options *filter_options); void partial_clone_get_default_filter_spec( + struct repository *repo, struct list_objects_filter_options *filter_options, const char *remote);
-- 2.34.1