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

Re: [PATCH v2] clone: add clone.<url>.defaultObjectFilter config

From
ABAlan Braithwaite <alan@braithwaite.dev>
Date
Mar 5, 2026, 23:11 UTC
Message-ID
<f0521097-1ec6-4e47-88d5-8c5be47ded3b@app.fastmail.com>
In-Reply-To
<xmqqcy1i3xt4.fsf@gitster.g>
Junio C Hamano wrote:
Show 5 quoted lines
> This is unlike how http.<url>.<var> configuration variables work,
> and while I can see that server operators may not want to see users
> set clone.defaultObjectFilter and affect traffic with _all_ sites, I
> am afraid that this design choice may appear a bit counter-intuitive
> to end users.

Funny enough, I actually prefer that but gathered from the previous commentary that it wasn't desired. I'd be more than content to add it.

Junio C Hamano wrote:
> I cannot convince myself that a new structure only to hold a single
> "char *" member is not over-engineering.  Wouldn't it work equally
> well (unless you have an immediate plan to add more members to the
> struct, that is):

You're right, it's been a while I've written C. Thanks for catching that. I think my mind was going somewhere else with it, but YAGNI.

Junio C Hamano wrote:
> However, I think you want to leave the .cascade_fn NULL; you do not
> want urlmatch_config_entry() to call git_clone_config() AGAIN on the
> configuration variables, as the first call to repo_config() before
> we call parse_options() should have already handled them, no?

Good catch. I'll fix it. Will set cascade_fn to NULL so the second pass only looks at clone.<url>.defaultObjectFilter entries.

Thanks for the review and for your patience as I shake the gopher out of me and figure out how to do real programming again.

Thanks,
- Alan
On Thu, Mar 5, 2026, at 11:01, Junio C Hamano wrote:
Show 144 quoted lines
> "Alan Braithwaite via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
>> From: Alan Braithwaite <alan@braithwaite.dev>
>>
>> Add a new configuration option that lets users specify a default
>> partial clone filter per URL pattern.  When cloning a repository
>> whose URL matches a configured pattern, git-clone automatically
>> applies the filter, equivalent to passing --filter on the command
>> line.
>>
>>     [clone "https://github.com/"]
>>         defaultObjectFilter = blob:limit=5m
>>
>>     [clone "https://internal.corp.com/large-project/"]
>>         defaultObjectFilter = blob:none
>>
>> URL matching uses the existing urlmatch_config_entry() infrastructure,
>> following the same rules as http.<url>.* — you can match a domain,
>> a namespace path, or a specific project, and the most specific match
>> wins.
>>
>> The config only affects the initial clone.  Once the clone completes,
>> the filter is recorded in remote.<name>.partialCloneFilter, so
>> subsequent fetches inherit it automatically.  An explicit --filter
>> flag on the command line takes precedence.
>
> The motivation behind the change is clearly described.  Reusing the
> existing urlmatch_config_entry() infrastructure is very appropriate
> as it makes the feature intuitive for those familiar with
> http.<url>.* settings.
>
>> Only the URL-qualified form (clone.<url>.defaultObjectFilter) is
>> honored; a bare clone.defaultObjectFilter without a URL subsection
>> is ignored.
>
> This is unlike how http.<url>.<var> configuration variables work,
> and while I can see that server operators may not want to see users
> set clone.defaultObjectFilter and affect traffic with _all_ sites, I
> am afraid that this design choice may appear a bit counter-intuitive
> to end users.
>
>
>> Signed-off-by: Alan Braithwaite <alan@braithwaite.dev>
>
>>  Documentation/config/clone.adoc | 26 ++++++++++++
>>  builtin/clone.c                 | 68 ++++++++++++++++++++++++++++++
>>  t/t5616-partial-clone.sh        | 73 +++++++++++++++++++++++++++++++++
>>  3 files changed, 167 insertions(+)
>>
>> diff --git a/builtin/clone.c b/builtin/clone.c
>> index 45d8fa0eed..5e20b5343d 100644
>> --- a/builtin/clone.c
>> +++ b/builtin/clone.c
>> @@ -44,6 +44,7 @@
>>  #include "path.h"
>>  #include "pkt-line.h"
>>  #include "list-objects-filter-options.h"
>> +#include "urlmatch.h"
>>  #include "hook.h"
>>  #include "bundle.h"
>>  #include "bundle-uri.h"
>> @@ -757,6 +758,65 @@ static int git_clone_config(const char *k, const char *v,
>>  	return git_default_config(k, v, ctx, cb);
>>  }
>>  
>> +struct clone_filter_data {
>> +	char *default_object_filter;
>> +};
>> +
>> +static int clone_filter_collect(const char *var, const char *value,
>> +				const struct config_context *ctx UNUSED,
>> +				void *cb)
>> +{
>> +	struct clone_filter_data *data = cb;
>> +
>> +	if (!strcmp(var, "clone.defaultobjectfilter")) {
>> +		free(data->default_object_filter);
>> +		data->default_object_filter = xstrdup(value);
>> +	}
>> +	return 0;
>> +}
>
> This will segfault with a "value-less truth", i.e.,
>
> 	[clone "<URL>"]
> 		defaultObjectFilter
>
> so there should be 
>
> 		if (!value)
> 			return config_error_nonbool(var);
>
> in it.
>
> I cannot convince myself that a new structure only to hold a single
> "char *" member is not over-engineering.  Wouldn't it work equally
> well (unless you have an immediate plan to add more members to the
> struct, that is):
>
> 	char **filter_spec_p = cb;
>
> 	if (!strcmp(var, "clone.defaultobjectfilter")) {
> 		if (!value)
> 			retgurn config_error_nonbool(var);
> 		free(*filter_spec_p);
> 		*filter_spec_p = xstrdup(value);
> 	}
> 	return 0;
>
>> +/*
>> + * Look up clone.<url>.defaultObjectFilter using the urlmatch
>> + * infrastructure.  Only URL-qualified forms are supported; a bare
>> + * clone.defaultObjectFilter (without a URL) is ignored.
>> + */
>> +static char *get_default_object_filter(const char *url)
>> +{
>> +	struct urlmatch_config config = URLMATCH_CONFIG_INIT;
>> +	struct clone_filter_data data = { 0 };
>> +	struct string_list_item *item;
>> +	char *normalized_url;
>> +
>> +	config.section = "clone";
>> +	config.key = "defaultobjectfilter";
>> +	config.collect_fn = clone_filter_collect;
>> +	config.cascade_fn = git_clone_config;
>> +	config.cb = &data;
>> +
>> +	normalized_url = url_normalize(url, &config.url);
>> +
>> +	repo_config(the_repository, urlmatch_config_entry, &config);
>> +	free(normalized_url);
>
> This forces a second full scan of the configuration space.  But it
> cannot be avoided, because the existing repo_config() call has to
> happen early before we call parse_options() to give us the
> configured default to overwrite with the command line, and we would
> not know what our URL is before we called parse_options().
>
> However, I thihk you want to leave the .cascade_fn NULL; you do not
> want urlmatch_config_entry() to call git_clone_config() AGAIN on the
> configuration variables, as the first call to repo_config() before
> we call parse_options() should have already handled them, no?
>
> Thanks.
Previous: Junio C HamanoNext: Alan Braithwaite via GitGitGadget
Message 15 of 30 in “fetch, clone: add fetch.blobSizeLimit config”
  1. fetch, clone: add fetch.blobSizeLimit configAlan Braithwaite via GitGitGadget, Mar 1, 2026
  2. Patrick SteinhardtMar 2, 2026
  3. Jeff KingMar 2, 2026
  4. Junio C HamanoMar 2, 2026
  5. Alan BraithwaiteMar 2, 2026
  6. Patrick SteinhardtMar 3, 2026
  7. Alan BraithwaiteMar 3, 2026
  8. Patrick SteinhardtMar 3, 2026
  9. Junio C HamanoMar 3, 2026
  10. Patrick SteinhardtMar 4, 2026
  11. Junio C HamanoMar 3, 2026
  12. Jeff KingMar 3, 2026
  13. clone: add clone.<url>.defaultObjectFilter configAlan Braithwaite via GitGitGadget, Mar 5, 2026
  14. Junio C HamanoMar 5, 2026
  15. Alan BraithwaiteMar 5, 2026
  16. clone: add clone.<url>.defaultObjectFilter configAlan Braithwaite via GitGitGadget, Mar 6, 2026
  17. brian m. carlsonMar 6, 2026
  18. Junio C HamanoMar 6, 2026
  19. Alan BraithwaiteMar 6, 2026
  20. clone: add clone.<url>.defaultObjectFilter configAlan Braithwaite via GitGitGadget, Mar 6, 2026
  21. Junio C HamanoMar 6, 2026
  22. Alan BraithwaiteMar 7, 2026
  23. clone: add clone.<url>.defaultObjectFilter configAlan Braithwaite via GitGitGadget, Mar 7, 2026
  24. Patrick SteinhardtMar 11, 2026
  25. Alan BraithwaiteMar 15, 2026
  26. clone: add clone.<url>.defaultObjectFilter configAlan Braithwaite via GitGitGadget, Mar 15, 2026
  27. Junio C HamanoMar 15, 2026
  28. Patrick SteinhardtMar 16, 2026
  29. Junio C HamanoMay 11, 2026
  30. Patrick SteinhardtMay 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.