Git development
 help / color / mirror / Atom feed
* [Outreachy PATCH] list-objects-filter-options: pass repository to partial clone helpers
@ 2026-10-25 19:02 Dorine Tipo
  0 siblings, 0 replies; only message in thread
From: Dorine Tipo @ 2026-10-25 19:02 UTC (permalink / raw)
  To: git
  Cc: ps, kaartic.sivaraam, christian.couder, siddharthasthana31,
	usmanakinyemi202, Dorine Tipo

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.

Signed-off-by: Dorine Tipo <dorine.a.tipo@gmail.com>
---
The file no longer uses `the_repository` after this change. I left
USE_THE_REPOSITORY_VARIABLE in place to keep this patch focused, and
can drop it here or in a follow-up, whichever is preferred.

 builtin/clone.c               |  3 ++-
 builtin/fetch.c               |  7 +++++--
 list-objects-filter-options.c | 14 ++++++++------
 list-objects-filter-options.h |  3 +++
 4 files changed, 18 insertions(+), 9 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..178624f6f5 100644
--- a/list-objects-filter-options.c
+++ b/list-objects-filter-options.c
@@ -362,6 +362,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 +371,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 +379,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 +394,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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-10-25 19:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-25 19:02 [Outreachy PATCH] list-objects-filter-options: pass repository to partial clone helpers Dorine Tipo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox