git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 4/9] fetch: make filter_options local to cmd_fetch()

From
Christian Couder <christian.couder@gmail.com>
Date
Feb 16, 2026, 13:23 UTC
Message-ID
<20260216132317.15894-5-christian.couder@gmail.com>
In-Reply-To
<20260216132317.15894-1-christian.couder@gmail.com>

The `struct list_objects_filter_options filter_options` variable used in "builtin/fetch.c" to store the parsed filters specified by `--filter=<filterspec>` is currently a static variable global to the file.

As we are going to use it more in a following commit, it could become a bit less easy to understand how it's managed.

To avoid that, let's make it clear that it's owned by cmd_fetch() by moving its definition into that function and making it non-static.

This requires passing a pointer to it through the prepare_transport(), do_fetch(), backfill_tags(), fetch_one_setup_partial(), and fetch_one() functions, but it's quite straightforward.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 builtin/fetch.c | 48 +++++++++++++++++++++++++++---------------------
 1 file changed, 27 insertions(+), 21 deletions(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index a3bc7e9380..8fbf3557ce 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -97,7 +97,6 @@ static struct strbuf default_rla = STRBUF_INIT;
 static struct transport *gtransport;
 static struct transport *gsecondary;
 static struct refspec refmap = REFSPEC_INIT_FETCH;
-static struct list_objects_filter_options filter_options = LIST_OBJECTS_FILTER_INIT;
 static struct string_list server_options = STRING_LIST_INIT_DUP;
 static struct string_list negotiation_tip = STRING_LIST_INIT_NODUP;
 
@@ -1562,7 +1561,8 @@ static void add_negotiation_tips(struct git_transport_options *smart_options)
 	smart_options->negotiation_tips = oids;
 }
 
-static struct transport *prepare_transport(struct remote *remote, int deepen)
+static struct transport *prepare_transport(struct remote *remote, int deepen,
+					   struct list_objects_filter_options *filter_options)
 {
 	struct transport *transport;
 
@@ -1586,9 +1586,9 @@ static struct transport *prepare_transport(struct remote *remote, int deepen)
 		set_option(transport, TRANS_OPT_UPDATE_SHALLOW, "yes");
 	if (refetch)
 		set_option(transport, TRANS_OPT_REFETCH, "yes");
-	if (filter_options.choice) {
+	if (filter_options->choice) {
 		const char *spec =
-			expand_list_objects_filter_spec(&filter_options);
+			expand_list_objects_filter_spec(filter_options);
 		set_option(transport, TRANS_OPT_LIST_OBJECTS_FILTER, spec);
 		set_option(transport, TRANS_OPT_FROM_PROMISOR, "1");
 	}
@@ -1607,7 +1607,8 @@ static int backfill_tags(struct display_state *display_state,
 			 struct ref *ref_map,
 			 struct fetch_head *fetch_head,
 			 const struct fetch_config *config,
-			 struct ref_update_display_info_array *display_array)
+			 struct ref_update_display_info_array *display_array,
+			 struct list_objects_filter_options *filter_options)
 {
 	int retcode, cannot_reuse;
 
@@ -1621,7 +1622,7 @@ static int backfill_tags(struct display_state *display_state,
 	cannot_reuse = transport->cannot_reuse ||
 		deepen_since || deepen_not.nr;
 	if (cannot_reuse) {
-		gsecondary = prepare_transport(transport->remote, 0);
+		gsecondary = prepare_transport(transport->remote, 0, filter_options);
 		transport = gsecondary;
 	}
 
@@ -1834,7 +1835,8 @@ static int commit_ref_transaction(struct ref_transaction **transaction,
 
 static int do_fetch(struct transport *transport,
 		    struct refspec *rs,
-		    const struct fetch_config *config)
+		    const struct fetch_config *config,
+		    struct list_objects_filter_options *filter_options)
 {
 	struct ref_transaction *transaction = NULL;
 	struct ref *ref_map = NULL;
@@ -1997,7 +1999,7 @@ static int do_fetch(struct transport *transport,
 			 * the transaction and don't commit anything.
 			 */
 			if (backfill_tags(&display_state, transport, transaction, tags_ref_map,
-					  &fetch_head, config, &display_array))
+					  &fetch_head, config, &display_array, filter_options))
 				retcode = 1;
 		}
 
@@ -2339,20 +2341,21 @@ static int fetch_multiple(struct string_list *list, int max_children,
  * Fetching from the promisor remote should use the given filter-spec
  * or inherit the default filter-spec from the config.
  */
-static inline void fetch_one_setup_partial(struct remote *remote)
+static inline void fetch_one_setup_partial(struct remote *remote,
+					   struct list_objects_filter_options *filter_options)
 {
 	/*
 	 * Explicit --no-filter argument overrides everything, regardless
 	 * of any prior partial clones and fetches.
 	 */
-	if (filter_options.no_filter)
+	if (filter_options->no_filter)
 		return;
 
 	/*
 	 * If no prior partial clone/fetch and the current fetch DID NOT
 	 * request a partial-fetch, do a normal fetch.
 	 */
-	if (!repo_has_promisor_remote(the_repository) && !filter_options.choice)
+	if (!repo_has_promisor_remote(the_repository) && !filter_options->choice)
 		return;
 
 	/*
@@ -2361,8 +2364,8 @@ static inline void fetch_one_setup_partial(struct remote *remote)
 	 * filter-spec as the default for subsequent fetches to this
 	 * remote if there is currently no default filter-spec.
 	 */
-	if (filter_options.choice) {
-		partial_clone_register(remote->name, &filter_options);
+	if (filter_options->choice) {
+		partial_clone_register(remote->name, filter_options);
 		return;
 	}
 
@@ -2371,14 +2374,15 @@ static inline void fetch_one_setup_partial(struct remote *remote)
 	 * explicitly given filter-spec or inherit the filter-spec from
 	 * the config.
 	 */
-	if (!filter_options.choice)
-		partial_clone_get_default_filter_spec(&filter_options, remote->name);
+	if (!filter_options->choice)
+		partial_clone_get_default_filter_spec(filter_options, remote->name);
 	return;
 }
 
 static int fetch_one(struct remote *remote, int argc, const char **argv,
 		     int prune_tags_ok, int use_stdin_refspecs,
-		     const struct fetch_config *config)
+		     const struct fetch_config *config,
+		     struct list_objects_filter_options *filter_options)
 {
 	struct refspec rs = REFSPEC_INIT_FETCH;
 	int i;
@@ -2390,7 +2394,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv,
 		die(_("no remote repository specified; please specify either a URL or a\n"
 		      "remote name from which new revisions should be fetched"));
 
-	gtransport = prepare_transport(remote, 1);
+	gtransport = prepare_transport(remote, 1, filter_options);
 
 	if (prune < 0) {
 		/* no command line request */
@@ -2445,7 +2449,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv,
 	sigchain_push_common(unlock_pack_on_signal);
 	atexit(unlock_pack_atexit);
 	sigchain_push(SIGPIPE, SIG_IGN);
-	exit_code = do_fetch(gtransport, &rs, config);
+	exit_code = do_fetch(gtransport, &rs, config, filter_options);
 	sigchain_pop(SIGPIPE);
 	refspec_clear(&rs);
 	transport_disconnect(gtransport);
@@ -2470,6 +2474,7 @@ int cmd_fetch(int argc,
 	const char *submodule_prefix = "";
 	const char *bundle_uri;
 	struct string_list list = STRING_LIST_INIT_DUP;
+	struct list_objects_filter_options filter_options = LIST_OBJECTS_FILTER_INIT;
 	struct remote *remote = NULL;
 	int all = -1, multiple = 0;
 	int result = 0;
@@ -2735,7 +2740,7 @@ int cmd_fetch(int argc,
 		trace2_region_enter("fetch", "negotiate-only", the_repository);
 		if (!remote)
 			die(_("must supply remote when using --negotiate-only"));
-		gtransport = prepare_transport(remote, 1);
+		gtransport = prepare_transport(remote, 1, &filter_options);
 		if (gtransport->smart_options) {
 			gtransport->smart_options->acked_commits = &acked_commits;
 		} else {
@@ -2757,12 +2762,12 @@ int cmd_fetch(int argc,
 	} else if (remote) {
 		if (filter_options.choice || repo_has_promisor_remote(the_repository)) {
 			trace2_region_enter("fetch", "setup-partial", the_repository);
-			fetch_one_setup_partial(remote);
+			fetch_one_setup_partial(remote, &filter_options);
 			trace2_region_leave("fetch", "setup-partial", the_repository);
 		}
 		trace2_region_enter("fetch", "fetch-one", the_repository);
 		result = fetch_one(remote, argc, argv, prune_tags_ok, stdin_refspecs,
-				   &config);
+				   &config, &filter_options);
 		trace2_region_leave("fetch", "fetch-one", the_repository);
 	} else {
 		int max_children = max_jobs;
@@ -2868,5 +2873,6 @@ int cmd_fetch(int argc,
 
  cleanup:
 	string_list_clear(&list, 0);
+	list_objects_filter_release(&filter_options);
 	return result;
 }
-- 
2.53.0.77.g4627d513d6
Previous: Christian CouderNext: Christian Couder
Message 61 of 111 in “Implement `promisor.storeFields` and `--filter=auto`”
  1. 0/9 Implement `promisor.storeFields` and `--filter=auto`Christian Couder, Dec 23, 2025
  2. 1/9 promisor-remote: refactor initialising field listsChristian Couder, Dec 23, 2025
  3. 2/9 promisor-remote: allow a client to store fieldsChristian Couder, Dec 23, 2025
  4. Patrick SteinhardtJan 7, 2026
  5. Christian CouderFeb 4, 2026
  6. 3/9 clone: make filter_options local to cmd_clone()Christian Couder, Dec 23, 2025
  7. 4/9 fetch: make filter_options local to cmd_fetch()Christian Couder, Dec 23, 2025
  8. Patrick SteinhardtJan 7, 2026
  9. 5/9 doc: fetch: document `--filter=<filter-spec>` optionChristian Couder, Dec 23, 2025
  10. Jean-Noël AVILADec 26, 2025
  11. Christian CouderFeb 4, 2026
  12. 6/9 list-objects-filter-options: support 'auto' mode for --filterChristian Couder, Dec 23, 2025
  13. Patrick SteinhardtJan 7, 2026
  14. Christian CouderFeb 4, 2026
  15. 7/9 list-objects-filter-options: implement auto filter resolutionChristian Couder, Dec 23, 2025
  16. Patrick SteinhardtJan 7, 2026
  17. Christian CouderFeb 4, 2026
  18. Patrick SteinhardtFeb 11, 2026
  19. Christian CouderFeb 12, 2026
  20. 8/9 promisor-remote: keep advertised filter in memoryChristian Couder, Dec 23, 2025
  21. Patrick SteinhardtJan 7, 2026
  22. Christian CouderFeb 4, 2026
  23. Patrick SteinhardtFeb 11, 2026
  24. Junio C HamanoFeb 11, 2026
  25. Christian CouderFeb 12, 2026
  26. 9/9 fetch-pack: wire up and enable auto filter logicChristian Couder, Dec 23, 2025
  27. Patrick SteinhardtJan 7, 2026
  28. Christian CouderFeb 4, 2026
  29. 0/8 Implement `promisor.storeFields` and `--filter=auto`Christian Couder, Feb 4, 2026
  30. 1/8 promisor-remote: refactor initialising field listsChristian Couder, Feb 4, 2026
  31. 2/8 promisor-remote: allow a client to store fieldsChristian Couder, Feb 4, 2026
  32. 3/8 clone: make filter_options local to cmd_clone()Christian Couder, Feb 4, 2026
  33. 4/8 fetch: make filter_options local to cmd_fetch()Christian Couder, Feb 4, 2026
  34. 5/8 doc: fetch: document `--filter=<filter-spec>` optionChristian Couder, Feb 4, 2026
  35. Patrick SteinhardtFeb 11, 2026
  36. Christian CouderFeb 12, 2026
  37. 6/8 list-objects-filter-options: support 'auto' mode for --filterChristian Couder, Feb 4, 2026
  38. 7/8 promisor-remote: keep advertised filters in memoryChristian Couder, Feb 4, 2026
  39. 8/8 fetch-pack: wire up and enable auto filter logicChristian Couder, Feb 4, 2026
  40. Patrick SteinhardtFeb 11, 2026
  41. Christian CouderFeb 12, 2026
  42. 0/9 Implement `promisor.storeFields` and `--filter=auto`Christian Couder, Feb 12, 2026
  43. 1/9 promisor-remote: refactor initialising field listsChristian Couder, Feb 12, 2026
  44. 2/9 promisor-remote: allow a client to store fieldsChristian Couder, Feb 12, 2026
  45. 3/9 clone: make filter_options local to cmd_clone()Christian Couder, Feb 12, 2026
  46. 4/9 fetch: make filter_options local to cmd_fetch()Christian Couder, Feb 12, 2026
  47. 5/9 doc: fetch: document `--filter=<filter-spec>` optionChristian Couder, Feb 12, 2026
  48. 6/9 list-objects-filter-options: support 'auto' mode for --filterChristian Couder, Feb 12, 2026
  49. Jeff KingFeb 14, 2026
  50. Christian CouderFeb 16, 2026
  51. 7/9 promisor-remote: keep advertised filters in memoryChristian Couder, Feb 12, 2026
  52. 8/9 promisor-remote: change promisor_remote_reply()'s signatureChristian Couder, Feb 12, 2026
  53. Patrick SteinhardtFeb 13, 2026
  54. 9/9 fetch-pack: wire up and enable auto filter logicChristian Couder, Feb 12, 2026
  55. Patrick SteinhardtFeb 13, 2026
  56. Patrick SteinhardtFeb 13, 2026
  57. 0/9 Implement `promisor.storeFields` and `--filter=auto`Christian Couder, Feb 16, 2026
  58. 1/9 promisor-remote: refactor initialising field listsChristian Couder, Feb 16, 2026
  59. 2/9 promisor-remote: allow a client to store fieldsChristian Couder, Feb 16, 2026
  60. 3/9 clone: make filter_options local to cmd_clone()Christian Couder, Feb 16, 2026
  61. 4/9 fetch: make filter_options local to cmd_fetch()Christian Couder, Feb 16, 2026
  62. 5/9 doc: fetch: document `--filter=<filter-spec>` optionChristian Couder, Feb 16, 2026
  63. 6/9 list-objects-filter-options: support 'auto' mode for --filterChristian Couder, Feb 16, 2026
  64. 7/9 promisor-remote: keep advertised filters in memoryChristian Couder, Feb 16, 2026
  65. 8/9 promisor-remote: change promisor_remote_reply()'s signatureChristian Couder, Feb 16, 2026
  66. 9/9 fetch-pack: wire up and enable auto filter logicChristian Couder, Feb 16, 2026
  67. 0/8 Auto-configure advertised remotes via URL allowlistChristian Couder, Apr 27, 2026
  68. 1/8 t5710: simplify 'mkdir X' followed by 'git -C X init'Christian Couder, Apr 27, 2026
  69. 2/8 urlmatch: change 'allow_globs' arg to boolChristian Couder, Apr 27, 2026
  70. 3/8 urlmatch: add url_normalize_pattern() helperChristian Couder, Apr 27, 2026
  71. 4/8 promisor-remote: add 'local_name' to 'struct promisor_info'Christian Couder, Apr 27, 2026
  72. Toon ClaesMay 4, 2026
  73. 5/8 promisor-remote: introduce promisor.acceptFromServerUrlChristian Couder, Apr 27, 2026
  74. 6/8 promisor-remote: trust known remotes matching acceptFromServerUrlChristian Couder, Apr 27, 2026
  75. Toon ClaesMay 8, 2026
  76. Christian CouderMay 19, 2026
  77. Toon ClaesMay 11, 2026
  78. Christian CouderMay 19, 2026
  79. 7/8 promisor-remote: auto-configure unknown remotesChristian Couder, Apr 27, 2026
  80. Toon ClaesMay 11, 2026
  81. Christian CouderMay 19, 2026
  82. 8/8 doc: promisor: improve acceptFromServer entryChristian Couder, Apr 27, 2026
  83. Christian CouderApr 27, 2026
  84. 0/8 Auto-configure advertised remotes via URL allowlistChristian Couder, May 19, 2026
  85. 1/8 t5710: simplify 'mkdir X' followed by 'git -C X init'Christian Couder, May 19, 2026
  86. 2/8 urlmatch: change 'allow_globs' arg to boolChristian Couder, May 19, 2026
  87. 3/8 urlmatch: add url_normalize_pattern() helperChristian Couder, May 19, 2026
  88. 4/8 promisor-remote: add 'local_name' to 'struct promisor_info'Christian Couder, May 19, 2026
  89. Junio C HamanoMay 20, 2026
  90. Christian CouderMay 27, 2026
  91. 5/8 promisor-remote: introduce promisor.acceptFromServerUrlChristian Couder, May 19, 2026
  92. 6/8 promisor-remote: trust known remotes matching acceptFromServerUrlChristian Couder, May 19, 2026
  93. Kristoffer HaugsbakkMay 23, 2026
  94. Christian CouderMay 27, 2026
  95. 7/8 promisor-remote: auto-configure unknown remotesChristian Couder, May 19, 2026
  96. 8/8 doc: promisor: improve acceptFromServer entryChristian Couder, May 19, 2026
  97. 0/8 Auto-configure advertised remotes via URL allowlistChristian Couder, May 27, 2026
  98. 1/8 t5710: simplify 'mkdir X' followed by 'git -C X init'Christian Couder, May 27, 2026
  99. 2/8 urlmatch: change 'allow_globs' arg to boolChristian Couder, May 27, 2026
  100. 3/8 urlmatch: add url_normalize_pattern() helperChristian Couder, May 27, 2026
  101. 4/8 promisor-remote: add 'local_name' to 'struct promisor_info'Christian Couder, May 27, 2026
  102. 5/8 promisor-remote: introduce promisor.acceptFromServerUrlChristian Couder, May 27, 2026
  103. 6/8 promisor-remote: trust known remotes matching acceptFromServerUrlChristian Couder, May 27, 2026
  104. 7/8 promisor-remote: auto-configure unknown remotesChristian Couder, May 27, 2026
  105. 8/8 doc: promisor: improve acceptFromServer entryChristian Couder, May 27, 2026
  106. Kristoffer HaugsbakkJul 4, 2026
  107. Toon ClaesJun 9, 2026
  108. Christian CouderJun 9, 2026
  109. Toon ClaesJun 9, 2026
  110. Junio C HamanoJun 10, 2026
  111. Christian CouderJun 11, 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.