Auto-configure advertised remotes via URL whitelist
cover Auto-configure advertised remotes via URL whitelist
Currently, the "promisor-remote" protocol capability allows a server to advertise promisor remotes (and their tokens/filters), but the client's promisor.acceptFromServer mechanism requires these remotes to already exist in the config.
This is a significant burden for users and administrators who have to pre-configure remotes.
This patch series improves on this by introducing a new promisor.acceptFromServerUrl config option, which provides an additive, URL-based security whitelist.
Multiple promisor.acceptFromServerUrl config options can be provided in different config files. Each one should contain a URL glob pattern which can optionally be prefixed with a remote name in the "[<name>=]<pattern>" format.
With this new config option:
- The server can update fields (like tokens) for known remotes, provided their URL matches the whitelist, even if acceptFromServer is set to None.
- Unknown remotes advertised by the server can be automatically configured on the client if their URL matches the whitelist.
- If there is no <name> prefix before the glob pattern matched, the auto-configured remote is named using the "promisor-auto-<sanitized-url>" format. So the same auto-configured remote config entry will be reused for the same URL.
- If a <name> prefix is provided, it will be used for the auto-configured remote config entry.
- If the chosen name (auto-generated or prefixed) already exists but points to a different URL, overwriting the existing config is prevented by appending a numeric suffix (e.g., -1, -2) to the name and auto-configuring using that name.
- The server's originally advertised name is always saved in the remote.<name>.advertisedAs config variable of the auto-configured remote for tracing and debugging.
- To honor the server's recommendation, promisor_remote_get_direct() is updated to try accepted remotes first before falling back to other configured promisor remotes. This ensures auto-configured remotes are preferred over other remotes especially the partial-clone origin.
Security considerations:
- Advertised URLs are routed through url_normalize() before matching against the user's glob patterns to prevent percent-encoding, case variation, or path-traversal (../) bypasses.
- Auto-generated remote names are sanitized (non-alphanumeric characters are replaced with '-' and prefixed with 'promisor-auto-'). This guarantees safe config section names and prevents a server from maliciously overwriting standard remotes (like origin).
- The documentation explains in detail how to use secure glob patterns in promisor.acceptFromServerUrl.
High level description of the patches
=====================================
- Patch 1/16 ("promisor-remote: try accepted remotes before others in get_direct()"):
Fixes promisor_remote_get_direct() to prioritize accepted remotes. This could be a separate fix, but is needed towards the end of the series.
- Patches 2-3/16 ("urlmatch:*"):
Exposes and adapts helpers in the urlmatch API.
- Patches 4-11/16 ("promisor-remote:*"):
Big refactoring of filter_promisor_remote() and should_accept_remote(). This keeps struct promisor_info instances alive longer to anticipate possible state-desync bugs, decouples the server's advertised name from the local config name, and sanitizes control flow without changing the existing behavior.
- Patch 12/16 ("t5710:*"):
Cleans up how "file://" URIs are managed in the test script to prepare for URI normalization later in the series and avoid issues on Windows.
- Patches 13-15/16 ("promisor-remote:*"):
The core feature. Introduces the parsing machinery, adds the additive whitelist for known remotes (with url_normalize() security), and finally implements the auto-creation and collision resolution for unknown remotes.
- Patch 16/16 ("doc: promisor: improve acceptFromServer entry"):
Cleans up and modernizes the existing promisor.acceptFromServer documentation.
CI tests
========
They all pass, see:
https://github.com/chriscool/git/actions/runs/23350745268
Christian Couder (16):
promisor-remote: try accepted remotes before others in get_direct()
urlmatch: change 'allow_globs' arg to bool
urlmatch: add url_is_valid_pattern() helper
promisor-remote: clarify that a remote is ignored
promisor-remote: refactor has_control_char()
promisor-remote: refactor accept_from_server()
promisor-remote: keep accepted promisor_info structs alive
promisor-remote: remove the 'accepted' strvec
promisor-remote: add 'local_name' to 'struct promisor_info'
promisor-remote: pass config entry to all_fields_match() directly
promisor-remote: refactor should_accept_remote() control flow
t5710: use proper file:// URIs for absolute paths
promisor-remote: introduce promisor.acceptFromServerUrl
promisor-remote: trust known remotes matching acceptFromServerUrl
promisor-remote: auto-configure unknown remotes
doc: promisor: improve acceptFromServer entry
Documentation/config/promisor.adoc | 118 +++++- Documentation/config/remote.adoc | 9 + Documentation/gitprotocol-v2.adoc | 9 +- promisor-remote.c | 532 +++++++++++++++++++++----- t/t5710-promisor-remote-capability.sh | 250 ++++++++++-- urlmatch.c | 18 +- urlmatch.h | 11 + 7 files changed, 802 insertions(+), 145 deletions(-)
Signature · 1 line
2.53.0.625.g20f70b52bb
PATCH 1/16 promisor-remote: try accepted remotes before others in get_direct()
When a server advertises promisor remotes and the client accepts some of them, those remotes carry the server's intent: 'fetch missing objects preferably from here', and the client agrees with that for the remotes it accepts.
However promisor_remote_get_direct() actually iterates over all promisor remotes in list order, which is the order they appear in the config files (except perhaps for the one appearing in the extensions.partialClone config variable which is tried last).
This means an existing, but not accepted, promisor remote, could be tried before the accepted ones, which does not reflect the intent of the agreement between client and server.
If the client doesn't care about what the server suggests, it should accept nothing and rely on its remotes as they are already configured.
To better reflect the agreement between client and server, let's make promisor_remote_get_direct() try the accepted promisor remotes before the non-accepted ones.
Concretely, let's extract a try_promisor_remotes() helper and call it twice from promisor_remote_get_direct():
- first with an accepted_only=true argument to try only the accepted remotes,
- then with accepted_only=false to fall back to any remaining remote.
Ensuring that accepted remotes are preferred will be even more important if in the future a mechanism is developed to allow the client to auto-configure remotes that the server advertises. This will in particular avoid fetching from the server (which is already configured as a promisor remote) before trying the auto-configured remotes, as these new remotes would likely appear at the end of the config file, and as the server might not appear in the extensions.partialClone config variable.
--- promisor-remote.c | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-)
promisor-remote.c +33 -13
@@ -268,11 +268,37 @@ static int remove_fetched_oids(struct repository *repo,return remaining_nr; } +static int try_promisor_remotes (struct repository *repo, +struct object_id **remaining_oids, +int *remaining_nr,int *to_free, +bool accepted_only) +{ +struct promisor_remote *r = repo->promisor_remote_config->promisors; + +for (; r; r = r->next) { +if (accepted_only && !r->accepted) +continue ; +if (!accepted_only && r->accepted) +continue ; +if (fetch_objects (repo, r->name, *remaining_oids, *remaining_nr) <0 ) { +if (*remaining_nr ==1 ) +continue ; + *remaining_nr =remove_fetched_oids (repo, remaining_oids, + *remaining_nr, *to_free); +if (*remaining_nr) { + *to_free =1 ; +continue ; + } + } +return 1 ;/* all fetched */ + } +return 0 ; +} +void promisor_remote_get_direct (struct repository *repo,const struct object_id *oids,int oid_nr) { -struct promisor_remote *r;struct object_id *remaining_oids = (struct object_id *)oids;int remaining_nr = oid_nr;int to_free =0 ;
@@ -283,19 +309,13 @@ void promisor_remote_get_direct(struct repository *repo,promisor_remote_init (repo); -for (r = repo->promisor_remote_config->promisors; r; r = r->next) { -if (fetch_objects (repo, r->name, remaining_oids, remaining_nr) <0 ) { -if (remaining_nr ==1 ) -continue ; - remaining_nr =remove_fetched_oids (repo, &remaining_oids, - remaining_nr, to_free); -if (remaining_nr) { - to_free =1 ; -continue ; - } - } +/* Try accepted remotes first (those the server told us to use) */ +if (try_promisor_remotes (repo, &remaining_oids, &remaining_nr, + &to_free, true)) + goto all_fetched; +if (try_promisor_remotes (repo, &remaining_oids, &remaining_nr, + &to_free, false)) goto all_fetched; - }for (i =0 ; i < remaining_nr; i++) {if (is_promisor_object (repo, &remaining_oids[i]))
Signature · 1 line
2.53.0.625.g20f70b52bb
Re: [PATCH 01/16] promisor-remote: try accepted remotes before others in get_direct()
Quoted 14 lines · Christian Couder
When a server advertises promisor remotes and the client accepts some of them, those remotes carry the server's intent: 'fetch missing objects preferably from here', and the client agrees with that for the remotes it accepts.
However
promisor_remote_get_direct()actually iterates over all promisor remotes in list order, which is the order they appear in the config files (except perhaps for the one appearing in theextensions.partialCloneconfig variable which is tried last).This means an existing, but not accepted, promisor remote, could be tried before the accepted ones, which does not reflect the intent of the agreement between client and server.
Quoted 6 lines
If the client doesn't care about what the server suggests, it should accept nothing and rely on its remotes as they are already configured.
To better reflect the agreement between client and server, let's make
promisor_remote_get_direct()try the accepted promisor remotes before the non-accepted ones.
Interesting, and it feels sensible to me. Is it documented anywhere that the ordering of announced remotes is actually important?
Quoted 7 lines
Concretely, let's extract a
try_promisor_remotes()helper and call it twice frompromisor_remote_get_direct():- first with an
accepted_only=trueargument to try only the accepted remotes,
- then withaccepted_only=falseto fall back to any remaining remote.
Quoted 8 lines
Ensuring that accepted remotes are preferred will be even more important if in the future a mechanism is developed to allow the client to auto-configure remotes that the server advertises. This will in particular avoid fetching from the server (which is already configured as a promisor remote) before trying the auto-configured remotes, as these new remotes would likely appear at the end of the config file, and as the server might not appear in the
extensions.partialCloneconfig variable.
Not quite sure I correctly understand this paragraph. Is the idea that in the future, we might not even store announced promisors in the config at all but simply use whatever the server announces on any given fetch?
Quoted 10 lines
promisor-remote.c +2
-0@@ -268,11 +268,37 @@ static int remove_fetched_oids(struct repository *repo,return remaining_nr; } +static int try_promisor_remotes(struct repository *repo, + struct object_id **remaining_oids,
promisor-remote.c static int remove_fetched_oids(struct repository *repo, · line 282
Quoted 10 lines
promisor-remote.c +10
-0+ int *remaining_nr, int *to_free, + bool accepted_only) +{ + struct promisor_remote *r = repo->promisor_remote_config->promisors; + +for (; r; r = r->next) { +if (accepted_only && !r->accepted) +continue ; +if (!accepted_only && r->accepted) +continue ;
This can be simplified to if (!accepted_only != !r->accepted).
Also, can we maybe add a test for this to verify that we use the correct ordering now?
Patrick
Re: [PATCH 01/16] promisor-remote: try accepted remotes before others in get_direct()
Quoted 6 lines · Patrick Steinhardt
Quoted 3 lines
To better reflect the agreement between client and server, let's make
promisor_remote_get_direct()try the accepted promisor remotes before the non-accepted ones.Interesting, and it feels sensible to me. Is it documented anywhere that the ordering of announced remotes is actually important?
I have documented it in the next version of this patch (which I will send soon) by adding the following to "Documentation/gitprotocol-v2.adoc":
"The promisor remotes that the client accepted will be tried before the other configured promisor remotes when the client will attempt to fetch missing objects."
Quoted 9 lines
Quoted 8 lines
Ensuring that accepted remotes are preferred will be even more important if in the future a mechanism is developed to allow the client to auto-configure remotes that the server advertises. This will in particular avoid fetching from the server (which is already configured as a promisor remote) before trying the auto-configured remotes, as these new remotes would likely appear at the end of the config file, and as the server might not appear in the
extensions.partialCloneconfig variable.
Quoted 3 lines
Not quite sure I correctly understand this paragraph. Is the idea that in the future, we might not even store announced promisors in the config at all but simply use whatever the server announces on any given fetch?
Currently the promisor remotes are fetched from in the same order as their order in the config file, except that a remote whose name appears in the extensions.partialClone config variable is fetched from last.
The idea is that with promisor.acceptFromServerUrl it will be possible to store accepted promisors in the config, but the resulting config order will not be the best for fetching. Especially if the main remote doesn't appear in the extensions.partialClone config variable it will likely be tried before the accepted promisors which we do not want.
So fetching first from the accepted promisors will also make things work better when promisor.acceptFromServerUrl will be implemented.
Quoted 8 lines
Quoted 8 lines
promisor-remote.c +0
-0@@ -268,11 +268,37 @@ static int remove_fetched_oids(struct repository *repo,return remaining_nr; }
Quoted 14 lines
promisor-remote.c static int remove_fetched_oids(struct repository *repo, · line 282
Quoted 12 lines
promisor-remote.c +12
-0+static int try_promisor_remotes (struct repository *repo, +struct object_id **remaining_oids, +int *remaining_nr,int *to_free, +bool accepted_only) +{ +struct promisor_remote *r = repo->promisor_remote_config->promisors; + +for (; r; r = r->next) { +if (accepted_only && !r->accepted) +continue ; +if (!accepted_only && r->accepted) +continue ;This can be simplified to
if (!accepted_only != !r->accepted).
Right, but I think we should go for if (accepted_only != r->accepted). It's even simpler and works because r->accepted is a 1 bit bitfield and accepted_only a bool.
Quoted 2 lines
Also, can we maybe add a test for this to verify that we use the correct ordering now?
Yeah, I have added tests for this in the new version.
Thanks.
PATCH 2/16 urlmatch: change 'allow_globs' arg to bool
In reply to Christian CouderThe last argument of url_normalize_1() is char allow_globs but it is used as a boolean, not as a char.
Let's convert it to a bool, and while at it convert the two calls to url_normalize_1() so they pass 'true' or 'false' instead of '1' or '0'.
--- urlmatch.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
urlmatch.c +3 -3
@@ -111,7 +111,7 @@ static int match_host(const struct url_info *url_info,return (!url_len && !pat_len); } -static char *url_normalize_1 (const char *url,struct url_info *out_info,char allow_globs) +static char *url_normalize_1 (const char *url,struct url_info *out_info,bool allow_globs) {/* * Normalize NUL-terminated url using the following rules:
@@ -437,7 +437,7 @@ static char *url_normalize_1(const char *url, struct url_info *out_info, char alchar *url_normalize (const char *url,struct url_info *out_info) { -return url_normalize_1 (url, out_info,0 ); +return url_normalize_1 (url, out_info, false); } static size_t url_match_prefix(const char *url,
@@ -577,7 +577,7 @@ int urlmatch_config_entry(const char *var, const char *value,struct url_info norm_info; config_url =xmemdupz (key, dot - key); - norm_url =url_normalize_1 (config_url, &norm_info,1 ); + norm_url =url_normalize_1 (config_url, &norm_info, true);if (norm_url) retval =match_urls (url, &norm_info, &matched);else if (collect->fallback_match_fn)
Signature · 1 line
2.53.0.625.g20f70b52bb
PATCH 3/16 urlmatch: add url_is_valid_pattern() helper
In reply to Christian CouderIn a following commit, we will need to check if a URL that might have glob patterns looks valid, so let's export a dedicated helper function for that purpose.
--- urlmatch.c | 12 ++++++++++++ urlmatch.h | 11 +++++++++++ 2 files changed, 23 insertions(+)
urlmatch.c +12 -0
@@ -440,6 +440,18 @@ char *url_normalize(const char *url, struct url_info *out_info)return url_normalize_1 (url, out_info, false); } +bool url_is_valid_pattern (const char *url) +{ +char *normalized =url_normalize_1 (url,NULL , true); + +if (normalized) { +free (normalized); +return true; + } + +return false; +} +static size_t url_match_prefix (const char *url,const char *url_prefix,size_t url_prefix_len)
urlmatch.h +11 -0
@@ -36,6 +36,17 @@ struct url_info {char *url_normalize (const char *,struct url_info *); +/* +* Return 'true' if the string looks like a valid URL or a valid URL pattern +* (allowing '*' globs), 'false' otherwise. +* +* This is NOT a URL validation function. Full URL validation is NOT +* performed. Some invalid host names are passed through this function +* undetected. However, most all other problems that make a URL invalid +* will be detected (including a missing host for non file: URLs). +*/ +bool url_is_valid_pattern (const char *url); +struct urlmatch_item {size_t hostmatch_len;size_t pathmatch_len;
Signature · 1 line
2.53.0.625.g20f70b52bb
Re: [PATCH 03/16] urlmatch: add url_is_valid_pattern() helper
Quoted 9 lines · Christian Couder
urlmatch.c +1
-0@@ -440,6 +440,18 @@ char *url_normalize(const char *url, struct url_info *out_info)return url_normalize_1 (url, out_info, false); } +bool url_is_valid_pattern (const char *url)
urlmatch.c char *url_normalize(const char *url, struct url_info *out_info) · line 453
Quoted 10 lines
urlmatch.c +10
-0+{ +char *normalized =url_normalize_1 (url,NULL , true); + +if (normalized) { +free (normalized); +return true; + } + +return false; +}
We could simplify this implementation to:
bool url_is_valid_pattern(const char *url)
{
char *normalized = url_normalize_1(url, NULL, true);
free(normalized);
return !!normalized;
}Quoted 8 lines
urlmatch.h +0
-0@@ -36,6 +36,17 @@ struct url_info {char *url_normalize (const char *,struct url_info *);
urlmatch.h struct url_info { · line 48
Quoted 10 lines
urlmatch.h +10
-0+/* +* Return 'true' if the string looks like a valid URL or a valid URL pattern +* (allowing '*' globs), 'false' otherwise. +* +* This is NOT a URL validation function. Full URL validation is NOT +* performed. Some invalid host names are passed through this function +* undetected. However, most all other problems that make a URL invalid +* will be detected (including a missing host for non file: URLs). +*/ +bool url_is_valid_pattern (const char *url);
Okay, this comment is basically copied from url_normalize_1(), which makes sense.
Patrick
Re: [PATCH 03/16] urlmatch: add url_is_valid_pattern() helper
Quoted 17 lines · Patrick Steinhardt
urlmatch.c char *url_normalize(const char *url, struct url_info *out_info) · line 453
Quoted 11 lines · Christian Couder
urlmatch.c +11
-0+bool url_is_valid_pattern (const char *url) +{ +char *normalized =url_normalize_1 (url,NULL , true); + +if (normalized) { +free (normalized); +return true; + } + +return false; +}We could simplify this implementation to:
Quoted 6 lines
bool url_is_valid_pattern(const char *url)
{
char *normalized = url_normalize_1(url, NULL, true);
free(normalized);
return !!normalized;
}Thanks for the suggestion but this patch has been replaced by a patch adding url_normalize_pattern() in the v2 I just sent.
PATCH 4/16 promisor-remote: clarify that a remote is ignored
In reply to Christian CouderIn should_accept_remote() when a remote is ignored, we might tell users why it is ignored in a warning, but we don't tell them that the remote is actually ignored.
Let's clarify that, so users have a better idea of what's actually happening.
--- promisor-remote.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
promisor-remote.c +4 -3
@@ -660,15 +660,16 @@ static int should_accept_remote(enum accept_promisor accept,BUG ("Unhandled 'enum accept_promisor' value '%d'" , accept);if (!remote_url || !*remote_url) { -warning (_ ("no or empty URL advertised for remote '%s'" ), remote_name); +warning (_ ("no or empty URL advertised for remote '%s', " +"ignoring this remote" ), remote_name);return 0 ; }if (!strcmp (p->url, remote_url))return all_fields_match (advertised, config_info,0 ); -warning (_ ("known remote named '%s' but with URL '%s' instead of '%s'" ), - remote_name, p->url, remote_url); +warning (_ ("known remote named '%s' but with URL '%s' instead of '%s', " +"ignoring this remote" ), remote_name, p->url, remote_url);return 0 ; }
Signature · 1 line
2.53.0.625.g20f70b52bb
Re: [PATCH 04/16] promisor-remote: clarify that a remote is ignored
Quoted 6 lines · Christian Couder
In
should_accept_remote()when a remote is ignored, we might tell users why it is ignored in a warning, but we don't tell them that the remote is actually ignored.Let's clarify that, so users have a better idea of what's actually happening.
Interesting that this doesn't result in any test changes. Don't we have test coverage for should_accept_remote()?
Quoted 14 lines
promisor-remote.c +2
-1@@ -660,15 +660,16 @@ static int should_accept_remote(enum accept_promisor accept,BUG ("Unhandled 'enum accept_promisor' value '%d'" , accept);if (!remote_url || !*remote_url) { -warning (_ ("no or empty URL advertised for remote '%s'" ), remote_name); +warning (_ ("no or empty URL advertised for remote '%s', " +"ignoring this remote" ), remote_name);return 0 ; }
promisor-remote.c static int should_accept_remote(enum accept_promisor accept, · line 675
Quoted 10 lines
promisor-remote.c +2
-2if (!strcmp (p->url, remote_url))return all_fields_match (advertised, config_info,0 ); -warning (_ ("known remote named '%s' but with URL '%s' instead of '%s'" ), - remote_name, p->url, remote_url); +warning (_ ("known remote named '%s' but with URL '%s' instead of '%s', " +"ignoring this remote" ), remote_name, p->url, remote_url);return 0 ; }
The change itself seems sensible to me.
Patrick
Re: [PATCH 04/16] promisor-remote: clarify that a remote is ignored
Quoted 11 lines · Patrick Steinhardt
Quoted 6 lines · Christian Couder
In
should_accept_remote()when a remote is ignored, we might tell users why it is ignored in a warning, but we don't tell them that the remote is actually ignored.Let's clarify that, so users have a better idea of what's actually happening.
Interesting that this doesn't result in any test changes. Don't we have test coverage for
should_accept_remote()?
We have test coverage but we don't test the emitted warning, we test whether the remote is actually accepted and used.
Let me know if you think we should test the warnings too.
PATCH 5/16 promisor-remote: refactor has_control_char()
In reply to Christian CouderIn a following commit we are going to check if some strings contain control character, so let's refactor the logic to do that in a new has_control_char() helper function.
--- promisor-remote.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
promisor-remote.c +14 -10
@@ -632,6 +632,14 @@ static int all_fields_match(struct promisor_info *advertised,return 1 ; } +static bool has_control_char (const char *s) +{ +for (const char *c = s; *c; c++) +if (iscntrl (*c)) +return true; +return false; +} +static int should_accept_remote (enum accept_promisor accept,struct promisor_info *advertised,struct string_list *config_info)
@@ -762,18 +770,14 @@ static bool valid_filter(const char *filter, const char *remote_name)return !res; } -/* Check that a token doesn't contain any control character */ static bool valid_token (const char *token,const char *remote_name) { -const char *c = token; - -for (; *c; c++) -if (iscntrl (*c)) { -warning (_ ("invalid token '%s' for remote '%s' " -"will not be stored" ), - token, remote_name); -return false; - } +if (has_control_char (token)) { +warning (_ ("invalid token '%s' for remote '%s' " +"will not be stored" ), + token, remote_name); +return false; + }return true; }
Signature · 1 line
2.53.0.625.g20f70b52bb
PATCH 6/16 promisor-remote: refactor accept_from_server()
In reply to Christian CouderIn a following commit, we are going to add more logic to filter_promisor_remote() which is already doing a lot of things.
Let's alleviate that by moving the logic that checks and validates the value of the promisor.acceptFromServer config variable into its own accept_from_server() helper function.
--- promisor-remote.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
promisor-remote.c +17 -10
@@ -852,20 +852,12 @@ static bool promisor_store_advertised_fields(struct promisor_info *advertised,return reload_config; } -static void filter_promisor_remote (struct repository *repo, -struct strvec *accepted, -const char *info) +static enum accept_promisor accept_from_server (struct repository *repo) {const char *accept_str;enum accept_promisor accept =ACCEPT_NONE ; -struct string_list config_info =STRING_LIST_INIT_NODUP ; -struct string_list remote_info =STRING_LIST_INIT_DUP ; -struct store_info *store_info =NULL ; -struct string_list_item *item; -bool reload_config = false; -struct string_list accepted_filters =STRING_LIST_INIT_DUP ; -if (!repo_config_get_string_tmp (the_repository,"promisor.acceptfromserver" , &accept_str)) { +if (!repo_config_get_string_tmp (repo,"promisor.acceptfromserver" , &accept_str)) {if (!*accept_str || !strcasecmp ("None" , accept_str)) accept =ACCEPT_NONE ;else if (!strcasecmp ("KnownUrl" , accept_str))
@@ -879,6 +871,21 @@ static void filter_promisor_remote(struct repository *repo, accept_str, "promisor.acceptfromserver"); } +return accept; +} + +static void filter_promisor_remote (struct repository *repo, +struct strvec *accepted, +const char *info) +{ +struct string_list config_info =STRING_LIST_INIT_NODUP ; +struct string_list remote_info =STRING_LIST_INIT_DUP ; +struct store_info *store_info =NULL ; +struct string_list_item *item; +bool reload_config = false; +struct string_list accepted_filters =STRING_LIST_INIT_DUP ; +enum accept_promisor accept =accept_from_server (repo); +if (accept ==ACCEPT_NONE )return ;
Signature · 1 line
2.53.0.625.g20f70b52bb
PATCH 7/16 promisor-remote: keep accepted promisor_info structs alive
In reply to Christian CouderIn filter_promisor_remote(), the instances of struct promisor_info for accepted remotes are dismantled into separate parallel data structures (the 'accepted' strvec for server names, and 'accepted_filters' for filter strings) and then immediately freed.
Instead, let's keep these instances on an 'accepted_remotes' list.
This way the post-loop phase can iterate a single list to build the protocol reply, apply advertised filters, and mark remotes as accepted, rather than iterating three separate structures.
This refactoring also prepares for a following commit that will add a 'local_name' member to 'struct promisor_info'. Since struct instances stay alive, downstream code will be able to simply read both names from them rather than needing yet another parallel strvec.
--- promisor-remote.c | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-)
promisor-remote.c +17 -25
@@ -880,10 +880,10 @@ static void filter_promisor_remote(struct repository *repo, {struct string_list config_info =STRING_LIST_INIT_NODUP ;struct string_list remote_info =STRING_LIST_INIT_DUP ; +struct string_list accepted_remotes =STRING_LIST_INIT_NODUP ;struct store_info *store_info =NULL ;struct string_list_item *item;bool reload_config = false; -struct string_list accepted_filters =STRING_LIST_INIT_DUP ;enum accept_promisor accept =accept_from_server (repo);if (accept ==ACCEPT_NONE )
@@ -912,17 +912,10 @@ static void filter_promisor_remote(struct repository *repo,if (promisor_store_advertised_fields (advertised, store_info)) reload_config = true; -strvec_push (accepted, advertised->name); - -/* Capture advertised filters for accepted remotes */ -if (advertised->filter) { -struct string_list_item *i; - i =string_list_append (&accepted_filters, advertised->name); - i->util =xstrdup (advertised->filter); - } +string_list_append (&accepted_remotes, advertised->name)->util = advertised; + }else { +promisor_info_free (advertised); } - -promisor_info_free (advertised); }promisor_info_list_clear (&config_info);
@@ -932,24 +925,23 @@ static void filter_promisor_remote(struct repository *repo,if (reload_config)repo_promisor_remote_reinit (repo); -/* Apply accepted remote filters to the stable repo state */ -for_each_string_list_item (item, &accepted_filters) { -struct promisor_remote *r =repo_promisor_remote_find (repo, item->string); -if (r) { -free (r->advertised_filter); - r->advertised_filter = item->util; - item->util =NULL ; - } - } +/* Apply accepted remotes to the stable repo state */ +for_each_string_list_item (item, &accepted_remotes) { +struct promisor_info *info = item->util; +struct promisor_remote *r =repo_promisor_remote_find (repo, info->name); -string_list_clear (&accepted_filters,1 ); +strvec_push (accepted, info->name); -/* Mark the remotes as accepted in the repository state */ -for (size_t i =0 ; i < accepted->nr; i++) { -struct promisor_remote *r =repo_promisor_remote_find (repo, accepted->v[i]); -if (r) +if (r) { r->accepted =1 ; +if (info->filter) { +free (r->advertised_filter); + r->advertised_filter =xstrdup (info->filter); + } + } } + +promisor_info_list_clear (&accepted_remotes); }void promisor_remote_reply (const char *info,char **accepted_out)
Signature · 1 line
2.53.0.625.g20f70b52bb
Re: [PATCH 07/16] promisor-remote: keep accepted promisor_info structs alive
promisor-remote.c static void filter_promisor_remote(struct repository *repo, · line 915
Quoted 9 lines · Christian Couder
promisor-remote.c +0
-1@@ -912,17 +912,10 @@ static void filter_promisor_remote(struct repository *repo,if (promisor_store_advertised_fields (advertised, store_info)) reload_config = true; -strvec_push (accepted, advertised->name);
Okay, here we used to store the name of the accepted remote...
promisor-remote.c static void filter_promisor_remote(struct repository *repo, · line 922
Quoted 6 lines
promisor-remote.c +0
-6-/* Capture advertised filters for accepted remotes */ -if (advertised->filter) { -struct string_list_item *i; - i =string_list_append (&accepted_filters, advertised->name); - i->util =xstrdup (advertised->filter); - }
... and here we used to store the filter, if any.
promisor-remote.c static void filter_promisor_remote(struct repository *repo, · line 915
Quoted 1 line
promisor-remote.c +1
-0+string_list_append (&accepted_remotes, advertised->name)->util = advertised;
Instead, we now store the whole remote, ...
promisor-remote.c static void filter_promisor_remote(struct repository *repo, · line 917
Quoted 2 lines
promisor-remote.c +2
-0+ }else { +promisor_info_free (advertised);
... unless we don't want to accept it, in which case we free it now. Makes sense.
Quoted 7 lines
promisor-remote.c +0
-3@@ -932,24 +925,23 @@ static void filter_promisor_remote(struct repository *repo,if (reload_config)repo_promisor_remote_reinit (repo); -/* Apply accepted remote filters to the stable repo state */ -for_each_string_list_item (item, &accepted_filters) { -struct promisor_remote *r =repo_promisor_remote_find (repo, item->string);
promisor-remote.c static void filter_promisor_remote(struct repository *repo, · line 931
Quoted 10 lines
promisor-remote.c +4
-6-if (r) { -free (r->advertised_filter); - r->advertised_filter = item->util; - item->util =NULL ; - } - } +/* Apply accepted remotes to the stable repo state */ +for_each_string_list_item (item, &accepted_remotes) { +struct promisor_info *info = item->util; +struct promisor_remote *r =repo_promisor_remote_find (repo, info->name);
And instead of iterating through the accepted filters we now iterate through the accepted remotes and take their respective filters from the promisor remote info.
Quoted 8 lines
promisor-remote.c +2
-5-string_list_clear (&accepted_filters,1 ); +strvec_push (accepted, info->name); -/* Mark the remotes as accepted in the repository state */ -for (size_t i =0 ; i < accepted->nr; i++) { -struct promisor_remote *r =repo_promisor_remote_find (repo, accepted->v[i]); -if (r) +if (r) {
promisor-remote.c static void filter_promisor_remote(struct repository *repo, · line 945
Quoted 10 lines
promisor-remote.c +7
-0r->accepted =1 ; +if (info->filter) { +free (r->advertised_filter); + r->advertised_filter =xstrdup (info->filter); + } + } } + +promisor_info_list_clear (&accepted_remotes); }
Patrick
PATCH 8/16 promisor-remote: remove the 'accepted' strvec
In reply to Christian CouderIn a previous commit, filter_promisor_remote() was refactored to keep accepted 'struct promisor_info' instances alive instead of dismantling them into separate parallel data structures.
Let's go one step further and replace the 'struct strvec *accepted' argument passed to filter_promisor_remote() with a 'struct string_list *accepted_remotes' argument.
--- promisor-remote.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-)
promisor-remote.c +12 -15
@@ -875,12 +875,11 @@ static enum accept_promisor accept_from_server(struct repository *repo) }static void filter_promisor_remote (struct repository *repo, -struct strvec *accepted, +struct string_list *accepted_remotes,const char *info) {struct string_list config_info =STRING_LIST_INIT_NODUP ;struct string_list remote_info =STRING_LIST_INIT_DUP ; -struct string_list accepted_remotes =STRING_LIST_INIT_NODUP ;struct store_info *store_info =NULL ;struct string_list_item *item;bool reload_config = false;
@@ -912,7 +911,7 @@ static void filter_promisor_remote(struct repository *repo,if (promisor_store_advertised_fields (advertised, store_info)) reload_config = true; -string_list_append (&accepted_remotes, advertised->name)->util = advertised; +string_list_append (accepted_remotes, advertised->name)->util = advertised; }else {promisor_info_free (advertised); }
@@ -926,12 +925,10 @@ static void filter_promisor_remote(struct repository *repo,repo_promisor_remote_reinit (repo);/* Apply accepted remotes to the stable repo state */ -for_each_string_list_item (item, &accepted_remotes) { +for_each_string_list_item (item, accepted_remotes) {struct promisor_info *info = item->util;struct promisor_remote *r =repo_promisor_remote_find (repo, info->name); -strvec_push (accepted, info->name); -if (r) { r->accepted =1 ;if (info->filter) {
@@ -940,23 +937,23 @@ static void filter_promisor_remote(struct repository *repo, } } } - -promisor_info_list_clear (&accepted_remotes); }void promisor_remote_reply (const char *info,char **accepted_out) { -struct strvec accepted =STRVEC_INIT ; +struct string_list accepted_remotes =STRING_LIST_INIT_NODUP ; -filter_promisor_remote (the_repository, &accepted, info); +filter_promisor_remote (the_repository, &accepted_remotes, info);if (accepted_out) { -if (accepted.nr) { +if (accepted_remotes.nr) {struct strbuf reply =STRBUF_INIT ; -for (size_t i =0 ; i < accepted.nr; i++) { -if (i) +struct string_list_item *item; + +for_each_string_list_item (item, &accepted_remotes) { +if (reply.len)strbuf_addch (&reply,';' ); -strbuf_addstr_urlencode (&reply, accepted.v[i], allow_unsanitized); +strbuf_addstr_urlencode (&reply, item->string, allow_unsanitized); } *accepted_out =strbuf_detach (&reply,NULL ); }else {
@@ -964,7 +961,7 @@ void promisor_remote_reply(const char *info, char **accepted_out) } } -strvec_clear (&accepted); +promisor_info_list_clear (&accepted_remotes); }void mark_promisor_remotes_as_accepted (struct repository *r,const char *remotes)
Signature · 1 line
2.53.0.625.g20f70b52bb
Re: [PATCH 08/16] promisor-remote: remove the 'accepted' strvec
Quoted 7 lines · Christian Couder
In a previous commit,
filter_promisor_remote()was refactored to keep accepted 'structpromisor_info' instances alive instead of dismantling them into separate parallel data structures.Let's go one step further and replace the 'struct strvec *accepted' argument passed to
filter_promisor_remote()with a 'structstring_list*accepted_remotes' argument.
Right, this is indeed something I was wondering about given that we now effectively stored the remote name twice.
Patrick
Re: [PATCH 08/16] promisor-remote: remove the 'accepted' strvec
Quoted 6 lines · Patrick Steinhardt
Quoted 4 lines · Christian Couder
In a previous commit,
filter_promisor_remote()was refactored to keep accepted 'structpromisor_info' instances alive instead of dismantling them into separate parallel data structures.
Quoted 6 lines
Quoted 3 lines
Let's go one step further and replace the 'struct strvec *accepted' argument passed to
filter_promisor_remote()with a 'structstring_list*accepted_remotes' argument.Right, this is indeed something I was wondering about given that we now effectively stored the remote name twice.
Yeah, I think both patches together result in a nice code simplification.
Thanks for taking a close look at them.
PATCH 9/16 promisor-remote: add 'local_name' to 'struct promisor_info'
In reply to Christian CouderIn a following commit, we will store promisor remote information under a remote name different than the one the server advertised.
To prepare for this change, let's add a new 'char* local_name' member to 'struct promisor_info', and let's update the related functions.
While at it, let's also add a small promisor_info_internal_name() helper that returns local_name when set, name otherwise, and let's use this small helper in promisor_store_advertised_fields() and in the post-loop of filter_promisor_remote() so that lookups against the local repo configuration use the right name.
--- promisor-remote.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-)
promisor-remote.c +18 -7
@@ -434,15 +434,19 @@ static struct string_list *fields_stored(void)/* * Struct for promisor remotes involved in the "promisor-remote" -* protocol capability. +* protocol capability: * -* Except for "name", each <member> in this struct and its <value> -* should correspond (either on the client side or on the server side) -* to a "remote.<name>.<member>" config variable set to <value> where -* "<name>" is a promisor remote name. +* - "name" is the name the server advertised. +* - "local_name" is the name we use locally (may be auto-generated). +* +* Except for "name" and "local_name", each <member> in this struct +* and its <value> should correspond (either on the client side or on +* the server side) to a "remote.<name>.<member>" config variable set +* to <value> where "<name>" is a promisor remote name. */ struct promisor_info {const char *name; +const char *local_name;const char *url;const char *filter;const char *token;
@@ -451,6 +455,7 @@ struct promisor_info {static void promisor_info_free (struct promisor_info *p) {free ((char *)p->name); +free ((char *)p->local_name);free ((char *)p->url);free ((char *)p->filter);free ((char *)p->token);
@@ -464,6 +469,11 @@ static void promisor_info_list_clear(struct string_list *list)string_list_clear (list,0 ); } +static const char *promisor_info_internal_name (struct promisor_info *p) +{ +return p->local_name ? p->local_name : p->name; +} +static void set_one_field (struct promisor_info *p,const char *field,const char *value) {
@@ -819,7 +829,7 @@ static bool promisor_store_advertised_fields(struct promisor_info *advertised, {struct promisor_info *p;struct string_list_item *item; -const char *remote_name = advertised->name; +const char *remote_name =promisor_info_internal_name (advertised);bool reload_config = false;if (!(store_info->store_filter || store_info->store_token))
@@ -927,7 +937,8 @@ static void filter_promisor_remote(struct repository *repo,/* Apply accepted remotes to the stable repo state */ for_each_string_list_item (item, accepted_remotes) {struct promisor_info *info = item->util; -struct promisor_remote *r =repo_promisor_remote_find (repo, info->name); +const char *local =promisor_info_internal_name (info); +struct promisor_remote *r =repo_promisor_remote_find (repo, local);if (r) { r->accepted =1 ;
Signature · 1 line
2.53.0.625.g20f70b52bb
Re: [PATCH 09/16] promisor-remote: add 'local_name' to 'struct promisor_info'
Quoted 4 lines · Christian Couder
In a following commit, we will store promisor remote information under a remote name different than the one the server advertised.
To prepare for this change, let's add a new 'char*
local_name' member
Micronit: s/char* local_name/char *local_name/
Quoted 19 lines
promisor-remote.c +5
-5@@ -434,15 +434,19 @@ static struct string_list *fields_stored(void)/* * Struct for promisor remotes involved in the "promisor-remote" -* protocol capability. +* protocol capability: * -* Except for "name", each <member> in this struct and its <value> -* should correspond (either on the client side or on the server side) -* to a "remote.<name>.<member>" config variable set to <value> where -* "<name>" is a promisor remote name. +* - "name" is the name the server advertised. +* - "local_name" is the name we use locally (may be auto-generated). +* +* Except for "name" and "local_name", each <member> in this struct
promisor-remote.c static struct string_list *fields_stored(void) · line 452
Quoted 10 lines
promisor-remote.c +4
-0+* and its <value> should correspond (either on the client side or on +* the server side) to a "remote.<name>.<member>" config variable set +* to <value> where "<name>" is a promisor remote name. */ struct promisor_info {const char *name; +const char *local_name;const char *url;const char *filter;const char *token;
I think it would be easier to follow if the struct-level comment applied to the general description of the struct, and individual members would then have their own comments describing their intent.
Quoted 22 lines
promisor-remote.c +6
-1@@ -464,6 +469,11 @@ static void promisor_info_list_clear(struct string_list *list)string_list_clear (list,0 ); } +static const char *promisor_info_internal_name (struct promisor_info *p) +{ +return p->local_name ? p->local_name : p->name; +} +static void set_one_field (struct promisor_info *p,const char *field,const char *value) {@@ -819,7 +829,7 @@ static bool promisor_store_advertised_fields(struct promisor_info *advertised, {struct promisor_info *p;struct string_list_item *item; -const char *remote_name = advertised->name; +const char *remote_name =promisor_info_internal_name (advertised);bool reload_config = false;if (!(store_info->store_filter || store_info->store_token))
promisor-remote.c static void filter_promisor_remote(struct repository *repo, · line 944
Quoted 9 lines
promisor-remote.c +2
-1@@ -927,7 +937,8 @@ static void filter_promisor_remote(struct repository *repo,/* Apply accepted remotes to the stable repo state */ for_each_string_list_item (item, accepted_remotes) {struct promisor_info *info = item->util; -struct promisor_remote *r =repo_promisor_remote_find (repo, info->name); +const char *local =promisor_info_internal_name (info); +struct promisor_remote *r =repo_promisor_remote_find (repo, local);if (r) { r->accepted =1 ;
Okay. These hunks are essentially a no-op for now given that we don't yet store a local name.
Patrick
Re: [PATCH 09/16] promisor-remote: add 'local_name' to 'struct promisor_info'
Quoted 8 lines · Patrick Steinhardt
Quoted 4 lines · Christian Couder
In a following commit, we will store promisor remote information under a remote name different than the one the server advertised.
To prepare for this change, let's add a new 'char*
local_name' memberMicronit: s/char* local_name/char *local_name/
Fixed in the v2 I just sent.
Quoted 25 lines
Quoted 25 lines
promisor-remote.c +8
-5@@ -434,15 +434,19 @@ static struct string_list *fields_stored(void)/* * Struct for promisor remotes involved in the "promisor-remote" -* protocol capability. +* protocol capability: * -* Except for "name", each <member> in this struct and its <value> -* should correspond (either on the client side or on the server side) -* to a "remote.<name>.<member>" config variable set to <value> where -* "<name>" is a promisor remote name. +* - "name" is the name the server advertised. +* - "local_name" is the name we use locally (may be auto-generated). +* +* Except for "name" and "local_name", each <member> in this struct +* and its <value> should correspond (either on the client side or on +* the server side) to a "remote.<name>.<member>" config variable set +* to <value> where "<name>" is a promisor remote name. */ struct promisor_info {const char *name;
Quoted 8 lines
promisor-remote.c static struct string_list *fields_stored(void) · line 452
Quoted 4 lines
promisor-remote.c +1
-0+const char *local_name;const char *url;const char *filter;const char *token;I think it would be easier to follow if the struct-level comment applied to the general description of the struct, and individual members would then have their own comments describing their intent.
Right, the diff looks like the following in the v2:
@@ -434,13 +434,14 @@ static struct string_list *fields_stored(void)
* Struct for promisor remotes involved in the "promisor-remote"
* protocol capability.
*
- * Except for "name", each <member> in this struct and its <value>
- * should correspond (either on the client side or on the server side)
- * to a "remote.<name>.<member>" config variable set to <value> where
- * "<name>" is a promisor remote name.
+ * Except for "name" and "local_name", each <member> in this struct
+ * and its <value> should correspond (either on the client side or on
+ * the server side) to a "remote.<name>.<member>" config variable set
+ * to <value> where "<name>" is a promisor remote name.
*/
struct promisor_info {
- const char *name;
+ const char *name; /* name the server advertised */
+ const char *local_name; /* name used locally (may be auto-generated) */
const char *url;
const char *filter;
const char *token;Thanks.
PATCH 10/16 promisor-remote: pass config entry to all_fields_match() directly
In reply to Christian CouderThe in_list == 0 path of all_fields_match() re-looks up the remote in config_info by advertised->name, even though every caller in should_accept_remote() has already performed this lookup and holds the result in 'p'.
To avoid this useless work, let's replace the int in_list parameter with a struct promisor_info *config_entry pointer:
- When NULL (ACCEPT_ALL mode): scan the whole config_info list, as the old in_list == 1 path did.
- When non-NULL: match against that single config entry directly, avoiding the redundant string_list_lookup() call.
This removes the hidden dependency on advertised->name inside all_fields_match(), which would be wrong in the following commits when auto-configured remotes will be implemented as the local config name may differ from the server's advertised name.
--- promisor-remote.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)
promisor-remote.c +18 -12
@@ -598,9 +598,18 @@ static int match_field_against_config(const char *field, const char *value,return 0 ; } +/* +* Check that the advertised fields match the local configuration. +* +* When 'config_entry' is NULL (ACCEPT_ALL mode), every checked field +* must match at least one remote in 'config_info'. +* +* When 'config_entry' points to a specific remote's config, the +* checked fields are compared against that single remote only. +*/ static int all_fields_match (struct promisor_info *advertised,struct string_list *config_info, -int in_list) +struct promisor_info *config_entry) {struct string_list *fields =fields_checked ();struct string_list_item *item_checked;
@@ -609,7 +618,6 @@ static int all_fields_match(struct promisor_info *advertised,int match =0 ;const char *field = item_checked->string;const char *value =NULL ; -struct string_list_item *item;if (!strcasecmp (field, promisor_field_filter)) value = advertised->filter;
@@ -619,7 +627,11 @@ static int all_fields_match(struct promisor_info *advertised,if (!value)return 0 ; -if (in_list) { +if (config_entry) { + match =match_field_against_config (field, value, + config_entry); + }else { +struct string_list_item *item;for_each_string_list_item (item, config_info) {struct promisor_info *p = item->util;if (match_field_against_config (field, value, p)) {
@@ -627,12 +639,6 @@ static int all_fields_match(struct promisor_info *advertised,break ; } } - }else { - item =string_list_lookup (config_info, advertised->name); -if (item) { -struct promisor_info *p = item->util; - match =match_field_against_config (field, value, p); - } }if (!match)
@@ -660,7 +666,7 @@ static int should_accept_remote(enum accept_promisor accept,const char *remote_url = advertised->url;if (accept ==ACCEPT_ALL ) -return all_fields_match (advertised, config_info,1 ); +return all_fields_match (advertised, config_info,NULL );/* Get config info for that promisor remote */ item =string_list_lookup (config_info, remote_name);
@@ -672,7 +678,7 @@ static int should_accept_remote(enum accept_promisor accept, p = item->util;if (accept ==ACCEPT_KNOWN_NAME ) -return all_fields_match (advertised, config_info,0 ); +return all_fields_match (advertised, config_info, p);if (accept !=ACCEPT_KNOWN_URL )BUG ("Unhandled 'enum accept_promisor' value '%d'" , accept);
@@ -684,7 +690,7 @@ static int should_accept_remote(enum accept_promisor accept, }if (!strcmp (p->url, remote_url)) -return all_fields_match (advertised, config_info,0 ); +return all_fields_match (advertised, config_info, p);warning (_ ("known remote named '%s' but with URL '%s' instead of '%s', " "ignoring this remote" ), remote_name, p->url, remote_url);
Signature · 1 line
2.53.0.625.g20f70b52bb
Re: [PATCH 10/16] promisor-remote: pass config entry to all_fields_match() directly
Quoted 1 line · Christian Couder
The
in_list == 0path ofall_fields_match()re-looks up the
This reads a bit weird. How about "looks up the remote in config_info by advertised->name repeatedly" instead?
Quoted 20 lines
promisor-remote.c +5
-1@@ -619,7 +627,11 @@ static int all_fields_match(struct promisor_info *advertised,if (!value)return 0 ; -if (in_list) { +if (config_entry) { + match =match_field_against_config (field, value, + config_entry); + }else { +struct string_list_item *item;for_each_string_list_item (item, config_info) {struct promisor_info *p = item->util;if (match_field_against_config (field, value, p)) {@@ -627,12 +639,6 @@ static int all_fields_match(struct promisor_info *advertised,break ; }
promisor-remote.c static int all_fields_match(struct promisor_info *advertised, · line 644
Quoted 10 lines
promisor-remote.c +0
-6} - }else { - item =string_list_lookup (config_info, advertised->name); -if (item) { -struct promisor_info *p = item->util; - match =match_field_against_config (field, value, p); - } }if (!match)
Okay, the logic is reversed now, which makes sense as we now pass NULL instead of 1, and the promisor info instead of 0.
The change itself makes sense, but other than that I have a very hard time understanding these two functions. I think they would strongly benefit from some comments explaining what's going on, what the input is and what we're trying to do. Of course that doesn't have to be part of this commit here, but I would appreciate a preparatory commit that helps guide the reader a bit.
Patrick
Re: [PATCH 10/16] promisor-remote: pass config entry to all_fields_match() directly
Quoted 6 lines · Patrick Steinhardt
Quoted 1 line · Christian Couder
The
in_list == 0path ofall_fields_match()re-looks up theThis reads a bit weird. How about "looks up the remote in
config_infobyadvertised->namerepeatedly" instead?
Yeah, this is better. It's now used in the next version.
Quoted 34 lines
Quoted 20 lines
promisor-remote.c +5
-1@@ -619,7 +627,11 @@ static int all_fields_match(struct promisor_info *advertised,if (!value)return 0 ; -if (in_list) { +if (config_entry) { + match =match_field_against_config (field, value, + config_entry); + }else { +struct string_list_item *item;for_each_string_list_item (item, config_info) {struct promisor_info *p = item->util;if (match_field_against_config (field, value, p)) {@@ -627,12 +639,6 @@ static int all_fields_match(struct promisor_info *advertised,break ; }promisor-remote.c static int all_fields_match(struct promisor_info *advertised, · line 644
Quoted 10 lines
promisor-remote.c +0
-6} - }else { - item =string_list_lookup (config_info, advertised->name); -if (item) { -struct promisor_info *p = item->util; - match =match_field_against_config (field, value, p); - } }if (!match)Okay, the logic is reversed now, which makes sense as we now pass
NULLinstead of1, and the promisor info instead of0.
Quoted 6 lines
The change itself makes sense, but other than that I have a very hard time understanding these two functions. I think they would strongly benefit from some comments explaining what's going on, what the input is and what we're trying to do. Of course that doesn't have to be part of this commit here, but I would appreciate a preparatory commit that helps guide the reader a bit.
The patch already added a comment in front of all_fields_match() but not in front of match_field_against_config(). Now it adds comments in front of both.
Thanks.
PATCH 11/16 promisor-remote: refactor should_accept_remote() control flow
In reply to Christian CouderIn following commits, we are going to add URL-based acceptance logic into should_accept_remote().
To prepare for the upcoming changes, let's restructure the control flow in should_accept_remote().
Concretely, let's:
- Move the empty-URL check to the very top of the function, so that every acceptance mode, instead of only ACCEPT_KNOWN_URL, rejects remotes with a missing or blank URL early.
- Invert the URL comparison: instead of returning on match and warning on mismatch, return early on mismatch and let the match case fall through. This opens a single exit path at the bottom of the function for following commits to extend.
Anyway the server shouldn't send any empty URL in the first place, so this shouldn't change any behavior in practice.
--- promisor-remote.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
promisor-remote.c +11 -10
@@ -665,6 +665,12 @@ static int should_accept_remote(enum accept_promisor accept,const char *remote_name = advertised->name;const char *remote_url = advertised->url; +if (!remote_url || !*remote_url) { +warning (_ ("no or empty URL advertised for remote '%s', " +"ignoring this remote" ), remote_name); +return 0 ; + } +if (accept ==ACCEPT_ALL )return all_fields_match (advertised, config_info,NULL );
@@ -683,19 +689,14 @@ static int should_accept_remote(enum accept_promisor accept,if (accept !=ACCEPT_KNOWN_URL )BUG ("Unhandled 'enum accept_promisor' value '%d'" , accept); -if (!remote_url || !*remote_url) { -warning (_ ("no or empty URL advertised for remote '%s', " -"ignoring this remote" ), remote_name); +if (strcmp (p->url, remote_url)) { +warning (_ ("known remote named '%s' but with URL '%s' instead of '%s', " +"ignoring this remote" ), + remote_name, p->url, remote_url);return 0 ; } -if (!strcmp (p->url, remote_url)) -return all_fields_match (advertised, config_info, p); - -warning (_ ("known remote named '%s' but with URL '%s' instead of '%s', " -"ignoring this remote" ), remote_name, p->url, remote_url); - -return 0 ; +return all_fields_match (advertised, config_info, p); }static int skip_field_name_prefix (const char *elem,const char *field_name,const char **value)
Signature · 1 line
2.53.0.625.g20f70b52bb
Re: [PATCH 11/16] promisor-remote: refactor should_accept_remote() control flow
Quoted 7 lines · Christian Couder
promisor-remote.c +0
-0@@ -665,6 +665,12 @@ static int should_accept_remote(enum accept_promisor accept,const char *remote_name = advertised->name;const char *remote_url = advertised->url;
promisor-remote.c static int should_accept_remote(enum accept_promisor accept, · line 676
Quoted 10 lines
promisor-remote.c +6
-0+if (!remote_url || !*remote_url) { +warning (_ ("no or empty URL advertised for remote '%s', " +"ignoring this remote" ), remote_name); +return 0 ; + } +if (accept ==ACCEPT_ALL )return all_fields_match (advertised, config_info,NULL );
You mention that it shouldn't change behaviour in well-defined cases where the remote sends non-empty URLs. But does it change behaviour in ill-defined cases where the remote sends empty ones?
In other words, does this fix a bug that can be hit in the real world?
Patrick
Re: [PATCH 11/16] promisor-remote: refactor should_accept_remote() control flow
Quoted 10 lines · Patrick Steinhardt
Quoted 8 lines · Christian Couder
promisor-remote.c +0
-0@@ -665,6 +665,12 @@ static int should_accept_remote(enum accept_promisor accept,const char *remote_name = advertised->name;const char *remote_url = advertised->url;
Quoted 12 lines
promisor-remote.c static int should_accept_remote(enum accept_promisor accept, · line 675
Quoted 8 lines
promisor-remote.c +6
-0+if (!remote_url || !*remote_url) { +warning (_ ("no or empty URL advertised for remote '%s', " +"ignoring this remote" ), remote_name); +return 0 ; + } +if (accept ==ACCEPT_ALL )return all_fields_match (advertised, config_info,NULL );You mention that it shouldn't change behaviour in well-defined cases where the remote sends non-empty URLs. But does it change behaviour in ill-defined cases where the remote sends empty ones?
Yes, it could change the behavior in the ill-defined case where the remote sends empty URLs.
So I have added a new patch to catch advertised empty URLs and empty remote names at parsing time. It is patch 4/10 ("promisor-remote:
reject empty name or URL in advertised remote") in the preparatory series I will send very soon now.
Quoted 1 line
In other words, does this fix a bug that can be hit in the real world?
No, because I think Git has the only implementation of the "promisor-remote" capability, and a Git server doesn't advertise empty URLs. (promisor_config_info_list() ignores empty URLs.)
So the ill-defined case could only happen if people use their own fork of either Git (with a hacked the "promisor-remote" capability) or an implementation of Git (that implements the "promisor-remote" capability differently). So not likely in practice.
Thanks.
PATCH 12/16 t5710: use proper file:// URIs for absolute paths
In reply to Christian CouderIn t5710, we frequently construct local file URIs using file://$(pwd). On Unix-like systems, $(pwd) returns an absolute path starting with a slash (e.g., /tmp/repo), resulting in a valid 3-slash URI with an empty host (file:///tmp/repo).
However, on Windows, $(pwd) returns a path starting with a drive letter (e.g., D:/a/repo). This results in a 2-slash URI (file://D:/a/repo). Standard URI parsers misinterpret this format, treating D: as the host rather than part of the absolute path.
While this hasn't broken the existing tests (because the old promisor.acceptFromServer logic relies entirely on strict strcmp without normalizing the URLs), it will break future commits that pass these URLs through url_normalize().
To future-proof the tests and ensure cross-platform URI compliance, let's introduce a $PWD_URL helper that explicitly guarantees a leading slash for the path component, ensuring valid 3-slash file:/// URIs on all operating systems.
While at it, let's also introduce $ENCODED_PWD_URL to handle spaces in directory paths (which is needed for URL glob pattern matching).
Then let's replace all instances of file://$(pwd) with $PWD_URL across the test script, and let's simplify the ENCODED_URL constructions in the sendFields and checkFields tests to use $ENCODED_PWD_URL directly.
--- t/t5710-promisor-remote-capability.sh | 55 ++++++++++++++++----------- 1 file changed, 32 insertions(+), 23 deletions(-)
t/t5710-promisor-remote-capability.sh +32 -23
@@ -76,6 +76,17 @@ copy_to_lop () { cp "$path" "$path2" } +# On Windows, 'pwd' returns a path like 'D:/foo/bar'. Prepend '/' to turn +# it into '/D:/foo/bar', which is what git expects in file:// URLs on Windows. +# On Unix, the path already starts with '/', so this is a no-op. +pwd_path=$(pwd) +case "$pwd_path" in +[a-zA-Z]:*) pwd_path="/$pwd_path" ;; +esac +PWD_URL="file://$pwd_path" +# Same as PWD_URL but with spaces percent-encoded, for use in URL patterns. +ENCODED_PWD_URL="file://$(echo "$pwd_path" | sed "s/ /%20/g")" + test_expect_success "setup for testing promisor remote advertisement" ' # Create another bare repo called "lop" (for Large Object Promisor) git init --bare lop &&
@@ -88,7 +99,7 @@ test_expect_success "setup for testing promisor remote advertisement" ' initialize_server 1 "$oid" && # Configure lop as promisor remote for server - git -C server remote add lop "file://$(pwd)/lop" && + git -C server remote add lop "$PWD_URL/lop" && git -C server config remote.lop.promisor true && git -C lop config uploadpack.allowFilter true &&
@@ -104,7 +115,7 @@ test_expect_success "clone with promisor.advertise set to 'true'" ' # Clone from server to create a client GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ - -c remote.lop.url="file://$(pwd)/lop" \ + -c remote.lop.url="$PWD_URL/lop" \ -c promisor.acceptfromserver=All \ --no-local --filter="blob:limit=5k" server client &&
@@ -119,7 +130,7 @@ test_expect_success "clone with promisor.advertise set to 'false'" ' # Clone from server to create a client GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ - -c remote.lop.url="file://$(pwd)/lop" \ + -c remote.lop.url="$PWD_URL/lop" \ -c promisor.acceptfromserver=All \ --no-local --filter="blob:limit=5k" server client &&
@@ -137,7 +148,7 @@ test_expect_success "clone with promisor.acceptfromserver set to 'None'" ' # Clone from server to create a client GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ - -c remote.lop.url="file://$(pwd)/lop" \ + -c remote.lop.url="$PWD_URL/lop" \ -c promisor.acceptfromserver=None \ --no-local --filter="blob:limit=5k" server client &&
@@ -156,8 +167,8 @@ test_expect_success "init + fetch with promisor.advertise set to 'true'" ' git -C client init && git -C client config remote.lop.promisor true && git -C client config remote.lop.fetch "+refs/heads/*:refs/remotes/lop/*" && - git -C client config remote.lop.url "file://$(pwd)/lop" && - git -C client config remote.server.url "file://$(pwd)/server" && + git -C client config remote.lop.url "$PWD_URL/lop" && + git -C client config remote.server.url "$PWD_URL/server" && git -C client config remote.server.fetch "+refs/heads/*:refs/remotes/server/*" && git -C client config promisor.acceptfromserver All && GIT_NO_LAZY_FETCH=0 git -C client fetch --filter="blob:limit=5k" server &&
@@ -173,7 +184,7 @@ test_expect_success "clone with promisor.acceptfromserver set to 'KnownName'" ' # Clone from server to create a client GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ - -c remote.lop.url="file://$(pwd)/lop" \ + -c remote.lop.url="$PWD_URL/lop" \ -c promisor.acceptfromserver=KnownName \ --no-local --filter="blob:limit=5k" server client &&
@@ -188,7 +199,7 @@ test_expect_success "clone with 'KnownName' and different remote names" ' # Clone from server to create a client GIT_NO_LAZY_FETCH=0 git clone -c remote.serverTwo.promisor=true \ -c remote.serverTwo.fetch="+refs/heads/*:refs/remotes/lop/*" \ - -c remote.serverTwo.url="file://$(pwd)/lop" \ + -c remote.serverTwo.url="$PWD_URL/lop" \ -c promisor.acceptfromserver=KnownName \ --no-local --filter="blob:limit=5k" server client &&
@@ -225,7 +236,7 @@ test_expect_success "clone with promisor.acceptfromserver set to 'KnownUrl'" ' # Clone from server to create a client GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ - -c remote.lop.url="file://$(pwd)/lop" \ + -c remote.lop.url="$PWD_URL/lop" \ -c promisor.acceptfromserver=KnownUrl \ --no-local --filter="blob:limit=5k" server client &&
@@ -242,7 +253,7 @@ test_expect_success "clone with 'KnownUrl' and different remote urls" ' # Clone from server to create a client GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ - -c remote.lop.url="file://$(pwd)/serverTwo" \ + -c remote.lop.url="$PWD_URL/serverTwo" \ -c promisor.acceptfromserver=KnownUrl \ --no-local --filter="blob:limit=5k" server client &&
@@ -257,7 +268,7 @@ test_expect_success "clone with 'KnownUrl' and url not configured on the server" git -C server config promisor.advertise true && test_when_finished "rm -rf client" && - test_when_finished "git -C server config set remote.lop.url \"file://$(pwd)/lop\"" && + test_when_finished "git -C server config set remote.lop.url \"$PWD_URL/lop\"" && git -C server config unset remote.lop.url && # Clone from server to create a client
@@ -266,7 +277,7 @@ test_expect_success "clone with 'KnownUrl' and url not configured on the server" # missing, so the remote name will be used instead which will fail. test_must_fail env GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ - -c remote.lop.url="file://$(pwd)/lop" \ + -c remote.lop.url="$PWD_URL/lop" \ -c promisor.acceptfromserver=KnownUrl \ --no-local --filter="blob:limit=5k" server client &&
@@ -278,7 +289,7 @@ test_expect_success "clone with 'KnownUrl' and empty url, so not advertised" ' git -C server config promisor.advertise true && test_when_finished "rm -rf client" && - test_when_finished "git -C server config set remote.lop.url \"file://$(pwd)/lop\"" && + test_when_finished "git -C server config set remote.lop.url \"$PWD_URL/lop\"" && git -C server config set remote.lop.url "" && # Clone from server to create a client
@@ -287,7 +298,7 @@ test_expect_success "clone with 'KnownUrl' and empty url, so not advertised" ' # so the remote name will be used instead which will fail. test_must_fail env GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ - -c remote.lop.url="file://$(pwd)/lop" \ + -c remote.lop.url="$PWD_URL/lop" \ -c promisor.acceptfromserver=KnownUrl \ --no-local --filter="blob:limit=5k" server client &&
@@ -311,13 +322,12 @@ test_expect_success "clone with promisor.sendFields" ' GIT_TRACE_PACKET="$(pwd)/trace" GIT_NO_LAZY_FETCH=0 git clone \ -c remote.lop.promisor=true \ -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ - -c remote.lop.url="file://$(pwd)/lop" \ + -c remote.lop.url="$PWD_URL/lop" \ -c promisor.acceptfromserver=All \ --no-local --filter="blob:limit=5k" server client && # Check that fields are properly transmitted - ENCODED_URL=$(echo "file://$(pwd)/lop" | sed -e "s/ /%20/g") && - PR1="name=lop,url=$ENCODED_URL,partialCloneFilter=blob:none" && + PR1="name=lop,url=$ENCODED_PWD_URL/lop,partialCloneFilter=blob:none" && PR2="name=otherLop,url=https://invalid.invalid,partialCloneFilter=blob:limit=10k,token=fooBar" && test_grep "clone< promisor-remote=$PR1;$PR2" trace && test_grep "clone> promisor-remote=lop;otherLop" trace &&
@@ -342,15 +352,14 @@ test_expect_success "clone with promisor.checkFields" ' GIT_TRACE_PACKET="$(pwd)/trace" GIT_NO_LAZY_FETCH=0 git clone \ -c remote.lop.promisor=true \ -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ - -c remote.lop.url="file://$(pwd)/lop" \ + -c remote.lop.url="$PWD_URL/lop" \ -c remote.lop.partialCloneFilter="blob:none" \ -c promisor.acceptfromserver=All \ -c promisor.checkFields=partialcloneFilter \ --no-local --filter="blob:limit=5k" server client && # Check that fields are properly transmitted - ENCODED_URL=$(echo "file://$(pwd)/lop" | sed -e "s/ /%20/g") && - PR1="name=lop,url=$ENCODED_URL,partialCloneFilter=blob:none" && + PR1="name=lop,url=$ENCODED_PWD_URL/lop,partialCloneFilter=blob:none" && PR2="name=otherLop,url=https://invalid.invalid,partialCloneFilter=blob:limit=10k,token=fooBar" && test_grep "clone< promisor-remote=$PR1;$PR2" trace && test_grep "clone> promisor-remote=lop" trace &&
@@ -380,7 +389,7 @@ test_expect_success "clone with promisor.storeFields=partialCloneFilter" ' GIT_TRACE_PACKET="$(pwd)/trace" GIT_NO_LAZY_FETCH=0 git clone \ -c remote.lop.promisor=true \ -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ - -c remote.lop.url="file://$(pwd)/lop" \ + -c remote.lop.url="$PWD_URL/lop" \ -c remote.lop.token="fooYYY" \ -c remote.lop.partialCloneFilter="blob:none" \ -c promisor.acceptfromserver=All \
@@ -432,7 +441,7 @@ test_expect_success "clone and fetch with --filter=auto" ' GIT_TRACE_PACKET="$(pwd)/trace" GIT_NO_LAZY_FETCH=0 git clone \ -c remote.lop.promisor=true \ - -c remote.lop.url="file://$(pwd)/lop" \ + -c remote.lop.url="$PWD_URL/lop" \ -c promisor.acceptfromserver=All \ --no-local --filter=auto server client 2>err &&
@@ -489,7 +498,7 @@ test_expect_success "clone with promisor.advertise set to 'true' but don't delet # Clone from server to create a client GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ - -c remote.lop.url="file://$(pwd)/lop" \ + -c remote.lop.url="$PWD_URL/lop" \ -c promisor.acceptfromserver=All \ --no-local --filter="blob:limit=5k" server client &&
Signature · 1 line
2.53.0.625.g20f70b52bb
Re: [PATCH 12/16] t5710: use proper file:// URIs for absolute paths
Quoted 8 lines · Christian Couder
t/t5710-promisor-remote-capability.sh +0
-0@@ -76,6 +76,17 @@ copy_to_lop () { cp "$path" "$path2" }
t/t5710-promisor-remote-capability.sh copy_to_lop () { · line 88
Quoted 10 lines
t/t5710-promisor-remote-capability.sh +10
-0+# On Windows, 'pwd' returns a path like 'D:/foo/bar'. Prepend '/' to turn +# it into '/D:/foo/bar', which is what git expects in file:// URLs on Windows. +# On Unix, the path already starts with '/', so this is a no-op. +pwd_path=$(pwd) +case "$pwd_path" in +[a-zA-Z]:*) pwd_path="/$pwd_path" ;; +esac +PWD_URL="file://$pwd_path" +# Same as PWD_URL but with spaces percent-encoded, for use in URL patterns. +ENCODED_PWD_URL="file://$(echo "$pwd_path" | sed "s/ /%20/g")"
Can't we do this unconditionally on all platforms? "file:////foobar" should be valid on Unix systems, too, shouldn't it?
Patrick
Re: [PATCH 12/16] t5710: use proper file:// URIs for absolute paths
Quoted 10 lines · Patrick Steinhardt
Quoted 8 lines · Christian Couder
t/t5710-promisor-remote-capability.sh +0
-0@@ -76,6 +76,17 @@ copy_to_lop () { cp "$path" "$path2" }
Quoted 13 lines
t/t5710-promisor-remote-capability.sh copy_to_lop () { · line 88
Quoted 10 lines
t/t5710-promisor-remote-capability.sh +10
-0+# On Windows, 'pwd' returns a path like 'D:/foo/bar'. Prepend '/' to turn +# it into '/D:/foo/bar', which is what git expects in file:// URLs on Windows. +# On Unix, the path already starts with '/', so this is a no-op. +pwd_path=$(pwd) +case "$pwd_path" in +[a-zA-Z]:*) pwd_path="/$pwd_path" ;; +esac +PWD_URL="file://$pwd_path" +# Same as PWD_URL but with spaces percent-encoded, for use in URL patterns. +ENCODED_PWD_URL="file://$(echo "$pwd_path" | sed "s/ /%20/g")"Can't we do this unconditionally on all platforms? "file:////foobar" should be valid on Unix systems, too, shouldn't it?
It depends what you mean by "valid". Perhaps it works and would simplify this code a bit, but I think the standard is 'RFC 8089: The "file" URI Scheme' which seems to says that the // prefix with an empty local host must be followed by an absolute path starting with a slash, resulting in exactly 3 slashes (file:///foobar). (See:
https://www.rfc-editor.org/rfc/rfc8089#section-2)
Appendix E.2 of RFC 8089 also seems to say that file:///c:/path/to/file is the standard representation for Windows drive letters.
So it seems safer to follow that standard in our parsers and tests, as we could then refer users to the standard and possibly make our parsers strictly follow it and test them against it in the future.
PATCH 13/16 promisor-remote: introduce promisor.acceptFromServerUrl
In reply to Christian CouderThe "promisor-remote" protocol capability allows servers to advertise promisor remotes, but doesn't allow these remotes to be automatically configured on the client.
Let's introduce a new promisor.acceptFromServerUrl config variable which contains a glob pattern, so that advertised remotes with a URL matching that pattern will be automatically configured.
The glob pattern can optionally be prefixed with a remote name which will be used as the name of the new local remote.
For now though, let's only introduce the functions to read and validate the glob patterns and the optional prefixes.
Checking if the URLs of the advertised remotes match the glob patterns and taking the appropriate action is left for a following commit.
--- promisor-remote.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+)
promisor-remote.c +73 -0
@@ -12,6 +12,7 @@#include "packfile.h" #include "environment.h" #include "url.h" +#include "urlmatch.h" #include "version.h" struct promisor_remote_config {
@@ -656,6 +657,76 @@ static bool has_control_char(const char *s)return false; } +struct allowed_url { +char *remote_name; +char *url_pattern; +}; + +static struct allowed_url *valid_accept_url (const char *url) +{ +char *dup, *p; +struct allowed_url *allowed; + +if (!url) +return NULL ; + + dup =xstrdup (url); + p =strchr (dup,'=' ); +if (p) { + *p ='\0' ; +if (!valid_remote_name (dup)) { +warning (_ ("invalid remote name '%s' before '=' sign " +"in '%s' from promisor.acceptFromServerUrl config" ), + dup, url); +free (dup); +return NULL ; + } + p++; + }else { + p = dup; + } + +if (has_control_char (p) || !url_is_valid_pattern (p)) { +warning (_ ("invalid url pattern '%s' " +"in '%s' from promisor.acceptFromServerUrl config" ), p, url); +free (dup); +return NULL ; + } + + allowed =xmalloc (sizeof (*allowed)); + allowed->remote_name = (p == dup) ?NULL : dup; + allowed->url_pattern = p; + +return allowed; +} + +static struct string_list *accept_from_server_url (struct repository *repo) +{ +static struct string_list accept_urls =STRING_LIST_INIT_DUP ; +static int initialized; +const struct string_list *config_urls; + +if (initialized) +return &accept_urls; + + initialized =1 ; + +if (!repo_config_get_string_multi (repo,"promisor.acceptfromserverurl" , &config_urls)) { +struct string_list_item *item; + +for_each_string_list_item (item, config_urls) { +struct allowed_url *allowed =valid_accept_url (item->string); +if (allowed) { +struct string_list_item *new; + new =string_list_append (&accept_urls, item->string); + new->util = allowed; + } + } + } + +return &accept_urls; +} +static int should_accept_remote (enum accept_promisor accept,struct promisor_info *advertised,struct string_list *config_info)
@@ -901,6 +972,8 @@ static void filter_promisor_remote(struct repository *repo,struct string_list_item *item;bool reload_config = false;enum accept_promisor accept =accept_from_server (repo); +/* Pre-load and validate the acceptFromServerUrl config */ + (void )accept_from_server_url (repo);if (accept ==ACCEPT_NONE )return ;
Signature · 1 line
2.53.0.625.g20f70b52bb
Re: [PATCH 13/16] promisor-remote: introduce promisor.acceptFromServerUrl
Quoted 4 lines · Christian Couder
promisor-remote.c +0
-0
[snip]
Quoted 16 lines
promisor-remote.c +16
-0+static struct string_list *accept_from_server_url (struct repository *repo) +{ +static struct string_list accept_urls =STRING_LIST_INIT_DUP ; +static int initialized; +const struct string_list *config_urls; + +if (initialized) +return &accept_urls; + + initialized =1 ; + +if (!repo_config_get_string_multi (repo,"promisor.acceptfromserverurl" , &config_urls)) { +struct string_list_item *item; + +for_each_string_list_item (item, config_urls) { +struct allowed_url *allowed =valid_accept_url (item->string);
promisor-remote.c static bool has_control_char(const char *s) · line 728
Quoted 10 lines
promisor-remote.c +10
-0+if (allowed) { +struct string_list_item *new; + new =string_list_append (&accept_urls, item->string); + new->util = allowed; + } + } + } + +return &accept_urls; +}
I'm still not much of a fan of us getting more and more function-local static variables. It just feels wrong to me, and like we're accruing technical debt. I also doubt that the performance overhead of storing this on the stack with proper lifecycle management will matter at all given that we're in a context where we talk with a remote anyway. The handful of allocations really shouldn't matter in that context.
Patrick
Re: [PATCH 13/16] promisor-remote: introduce promisor.acceptFromServerUrl
Quoted 32 lines · Patrick Steinhardt
Quoted 4 lines · Christian Couder
promisor-remote.c +0
-0[snip]
Quoted 25 lines
promisor-remote.c +25
-0+static struct string_list *accept_from_server_url (struct repository *repo) +{ +static struct string_list accept_urls =STRING_LIST_INIT_DUP ; +static int initialized; +const struct string_list *config_urls; + +if (initialized) +return &accept_urls; + + initialized =1 ; + +if (!repo_config_get_string_multi (repo,"promisor.acceptfromserverurl" , &config_urls)) { +struct string_list_item *item; + +for_each_string_list_item (item, config_urls) { +struct allowed_url *allowed =valid_accept_url (item->string); +if (allowed) { +struct string_list_item *new; + new =string_list_append (&accept_urls, item->string); + new->util = allowed; + } + } + } + +return &accept_urls;
Quoted 8 lines
Quoted 1 line
+}
I'm still not much of a fan of us getting more and more function-local static variables. It just feels wrong to me, and like we're accruing technical debt. I also doubt that the performance overhead of storing this on the stack with proper lifecycle management will matter at all given that we're in a context where we talk with a remote anyway. The handful of allocations really shouldn't matter in that context.
OK, I have removed the static variables and it looks like the following in v2:
+static void load_accept_from_server_url(struct repository *repo,
+ struct string_list *accept_urls)
+{
+ const struct string_list *config_urls;
+
+ if (!repo_config_get_string_multi(repo,
"promisor.acceptfromserverurl", &config_urls)) {
+ struct string_list_item *item;
+
+ for_each_string_list_item(item, config_urls) {
+ struct allowed_url *allowed =valid_accept_url(item->string);
+ if (allowed) {
+ struct string_list_item *new;
+ new = string_list_append(accept_urls,item->string);
+ new->util = allowed;
+ }
+ }
+ }
+}
+
static int should_accept_remote(enum accept_promisor accept,
struct promisor_info *advertised, struct string_list *config_info)
@@ -901,6 +986,10 @@ static void filter_promisor_remote(struct repository *repo,
struct string_list_item *item;
bool reload_config = false;
enum accept_promisor accept = accept_from_server(repo);+ struct string_list accept_urls = STRING_LIST_INIT_DUP;
+
+ /* Load and validate the acceptFromServerUrl config */
+ load_accept_from_server_url(repo, &accept_urls);
if (accept == ACCEPT_NONE)
return;PATCH 14/16 promisor-remote: trust known remotes matching acceptFromServerUrl
In reply to Christian CouderA previous commit introduced the promisor.acceptFromServerUrl config variable along with the machinery to parse and validate the URL glob patterns and optional remote name prefixes it contains. However, these URL patterns are not yet tied into the client's acceptance logic.
When a promisor remote is already configured locally, its fields (like authentication tokens) may occasionally need to be refreshed by the server. If promisor.acceptFromServer is set to the secure default ("None"), these updates are rejected, potentially causing future fetches to fail.
To enable such targeted updates for trusted URLs, let's use the URL patterns from promisor.acceptFromServerUrl as an additional URL based whitelist.
Concretely, let's check the advertised URLs against the URL glob patterns by introducing a new small helper function called url_matches_accept_list(), which iterates over the glob patterns and returns the first matching allowed_url entry (or NULL).
(Before matching, the advertised URL is passed through url_normalize() so that case variations in the scheme/host, percent-encoding tricks, and ".." path segments cannot bypass the whitelist.)
Let's then use this helper at the tail of should_accept_remote() so that, when accept == ACCEPT_NONE, a known remote whose URL matches the whitelist is still accepted.
To prepare for this new logic, let's also:
- Add an 'accept_urls' parameter to should_accept_remote().
- Replace the BUG() guard in the ACCEPT_KNOWN_URL case with an explicit 'if (accept == ACCEPT_KNOWN_URL) return' and a new BUG() guard in the ACCEPT_NONE case, so url_matches_accept_list() is only called in the ACCEPT_NONE case.
- Call accept_from_server_url() from filter_promisor_remote() and relax its early return so that the function is entered when accept_urls has entries even if accept == ACCEPT_NONE.
Let's then properly document promisor.acceptFromServerUrl in "promisor.adoc" as an additive security whitelist for known remotes, including the URL normalization behavior, and let's mention it in "gitprotocol-v2.adoc".
--- Documentation/config/promisor.adoc | 46 +++++++++++++++++ Documentation/gitprotocol-v2.adoc | 9 ++-- promisor-remote.c | 50 +++++++++++++++--- t/t5710-promisor-remote-capability.sh | 73 +++++++++++++++++++++++++++ 4 files changed, 166 insertions(+), 12 deletions(-)
Documentation/config/promisor.adoc +46 -0
@@ -51,6 +51,52 @@ promisor.acceptFromServer:: to "fetch" and "clone" requests from the client. Name and URL comparisons are case sensitive. See linkgit:gitprotocol-v2[5]. +promisor.acceptFromServerUrl:: + A glob pattern to specify which URLs advertised by a server + are considered trusted by the client. This option acts as an + additive security whitelist that works in conjunction with + `promisor.acceptFromServer`. ++ +This option can appear multiple times in config files. An advertised +URL will be accepted if it matches _ANY_ glob pattern specified by +this option in _ANY_ config file read by Git. ++ +Be _VERY_ careful with these glob patterns, as it can be a big +security hole to allow any advertised remote to be auto-configured! +To minimize security risks, follow these guidelines: ++ +1. Start with a secure protocol scheme, like `https://` or `ssh://`. ++ +2. Only allow domain names or paths where you control and trust _ALL_ + the content. Be especially careful with shared hosting platforms + like `github.com` or `gitlab.com`. A broad pattern like + `https://gitlab.com/*` is dangerous because it trusts every + repository on the entire platform. Always restrict such patterns to + your specific organization or namespace (e.g., + `https://gitlab.com/your-org/*`). ++ +3. Don't use globs (`*`) in the domain name. For example + `https://cdn.example.com/*` is much safer than + `https://*.example.com/*`, because the latter matches + `https://evil-hacker.net/fake.example.com/repo`. ++ +4. Make sure to have a `/` at the end of the domain name (or the end + of specific directories). For example `https://cdn.example.com/*` + is much safer than `https://cdn.example.com*`, because the latter + matches `https://cdn.example.com.hacker.net/repo`. ++ +Before matching, the advertised URL is normalized: the scheme and +host are lowercased, percent-encoded characters are decoded where +possible, and path segments like `..` are resolved. Glob patterns +are matched against this normalized URL as-is, so patterns should +be written in normalized form (e.g., lowercase scheme and host). ++ +Even if `promisor.acceptFromServer` is set to `None` (the default), +Git will still accept field updates (like tokens) for known remotes, +provided their URLs match a pattern in +`promisor.acceptFromServerUrl`. See linkgit:gitprotocol-v2[5] for +details on the protocol. + promisor.checkFields:: A comma or space separated list of additional remote related field names. A client checks if the values of these fields
Documentation/gitprotocol-v2.adoc +5 -4
@@ -862,10 +862,11 @@ the server advertised, the client shouldn't advertise the On the server side, the "promisor.advertise" and "promisor.sendFields" configuration options can be used to control what it advertises. On -the client side, the "promisor.acceptFromServer" configuration option -can be used to control what it accepts, and the "promisor.storeFields" -option, to control what it stores. See the documentation of these -configuration options in linkgit:git-config[1] for more information. +the client side, the "promisor.acceptFromServer" and +"promisor.acceptFromServerUrl" configuration options can be used to +control what it accepts, and the "promisor.storeFields" option, to +control what it stores. See the documentation of these configuration +options in linkgit:git-config[1] for more information. Note that in the future it would be nice if the "promisor-remote" protocol capability could be used by the server, when responding to
promisor-remote.c +42 -8
89 lines not on this page · raw message
t/t5710-promisor-remote-capability.sh +73 -0
83 lines not on this page · raw message
Signature · 1 line
2.53.0.625.g20f70b52bb
Re: [PATCH 14/16] promisor-remote: trust known remotes matching acceptFromServerUrl
Documentation/config/promisor.adoc promisor.acceptFromServer:: · line 58
Quoted 13 lines · Christian Couder
Documentation/config/promisor.adoc +5
-0@@ -51,6 +51,52 @@ promisor.acceptFromServer:: to "fetch" and "clone" requests from the client. Name and URL comparisons are case sensitive. See linkgit:gitprotocol-v2[5]. +promisor.acceptFromServerUrl:: + A glob pattern to specify which URLs advertised by a server + are considered trusted by the client. This option acts as an + additive security whitelist that works in conjunction with + `promisor.acceptFromServer`.
Between the first sentence and the second one, I think there needs to be an explanation on what "trusted" means in this context. Is it trusted so that the URL can feed random configuration variable=value pairs for the client to blindly apply? Or is it trusted to do very limited things that other remotes can do, and if so what are these limited things? Without knowing that, the end-users cannot assess the security implications of setting this option.
I am guessing that the client would behave as if the existing promisor.acceptFromServer configuration variable were set to "all" when talking with a remote whose URL matches one of the patterns listed?
By the way, some people may suggest "white" -> "allow".
Documentation/config/promisor.adoc promisor.acceptFromServer:: · line 68
Quoted 1 line
Documentation/config/promisor.adoc +1
-0+1. Start with a secure protocol scheme, like `https://` or `ssh://`.
Is there a practical reason why people would want to use schemes other than the above two? This sounds like something a small amount of code can easily enforce.
Documentation/config/promisor.adoc promisor.acceptFromServer:: · line 61
Quoted 2 lines
Documentation/config/promisor.adoc +2
-0+2. Only allow domain names or paths where you control and trust _ALL_ + the content.
Obviously.
Documentation/config/promisor.adoc promisor.acceptFromServer:: · line 81
Quoted 4 lines
Documentation/config/promisor.adoc +4
-0+3. Don't use globs (`*`) in the domain name. For example + `https://cdn.example.com/*` is much safer than + `https://*.example.com/*`, because the latter matches + `https://evil-hacker.net/fake.example.com/repo`.
Is there a practical use case where allowing '*' to match anything that contains a slash '/' is useful?
Documentation/config/promisor.adoc promisor.acceptFromServer:: · line 86
Quoted 4 lines
Documentation/config/promisor.adoc +4
-0+4. Make sure to have a `/` at the end of the domain name (or the end + of specific directories). For example `https://cdn.example.com/*` + is much safer than `https://cdn.example.com*`, because the latter + matches `https://cdn.example.com.hacker.net/repo`.
Ditto. The above two points sound like excuses to keep sloppy asterisk matching logic. Yes, retroactively tightening rules always have risk to break existing deployments, but if existing code paths of urlmatch do not have any good reason to allow '*' to match a string that contains a slash '/', perhaps there is no fallout.
Re: [PATCH 14/16] promisor-remote: trust known remotes matching acceptFromServerUrl
Quoted 15 lines · Junio C Hamano
Obviously.
Documentation/config/promisor.adoc promisor.acceptFromServer:: · line 81
Quoted 4 lines
+3. Don't use globs (
*) in the domain name. For exampleDocumentation/config/promisor.adoc +3
-0+ `https://cdn.example.com/*` is much safer than + `https://*.example.com/*`, because the latter matches + `https://evil-hacker.net/fake.example.com/repo`.Is there a practical use case where allowing '*' to match anything that contains a slash '/' is useful?
Documentation/config/promisor.adoc promisor.acceptFromServer:: · line 86
Quoted 4 lines
+4. Make sure to have a
/at the end of the domain name (or the endDocumentation/config/promisor.adoc +3
-0+ of specific directories). For example `https://cdn.example.com/*` + is much safer than `https://cdn.example.com*`, because the latter + matches `https://cdn.example.com.hacker.net/repo`.
Quoted 5 lines
Ditto. The above two points sound like excuses to keep sloppy asterisk matching logic. Yes, retroactively tightening rules always have risk to break existing deployments, but if existing code paths of urlmatch do not have any good reason to allow '*' to match a string that contains a slash '/', perhaps there is no fallout.
I probably should caution the readers not to take the above too literally. Forbidding an asterisk '*' glob not to match '/' anywhere in urlmatch will obviusly break existing deployments that does this
[http "https://example.com/*"]
var = val
and expects it to catch any URL pointing into the site.
But I still do think the matcher should be more intelligent than the current implementation to avoid pitfalls like #3 and #4 above.
Perhaps if an additional rule says that '*' after the scheme:// part before the first '/' in the pattern, e.g.,
https://*.example.com/ https://*.example.com https://example.com*
unlike '*' that appear anywhere else, never matches a substring that contains a slash '/' in it, it would cover plausible mistakes that the above #3 and #4 are trying to catch, without hurting any real world use case?
Re: [PATCH 14/16] promisor-remote: trust known remotes matching acceptFromServerUrl
In reply to Junio C HamanoQuoted 11 lines · Junio C Hamano
Quoted 8 lines · Christian Couder
Documentation/config/promisor.adoc +0
-0@@ -51,6 +51,52 @@ promisor.acceptFromServer:: to "fetch" and "clone" requests from the client. Name and URL comparisons are case sensitive. See linkgit:gitprotocol-v2[5].
Quoted 13 lines
Documentation/config/promisor.adoc promisor.acceptFromServer:: · line 58
Quoted 5 lines
Documentation/config/promisor.adoc +5
-0+promisor.acceptFromServerUrl:: + A glob pattern to specify which URLs advertised by a server + are considered trusted by the client. This option acts as an + additive security whitelist that works in conjunction with + `promisor.acceptFromServer`.Between the first sentence and the second one, I think there needs to be an explanation on what "trusted" means in this context. Is it trusted so that the URL can feed random configuration variable=value pairs for the client to blindly apply? Or is it trusted to do very limited things that other remotes can do, and if so what are these limited things? Without knowing that, the end-users cannot assess the security implications of setting this option.
Yeah, in the current version, the following is used, which is more explicit:
A glob pattern to specify which server-advertised URLs a client is allowed to act on. When a URL matches, the client will accept the advertised remote as a promisor remote and may automatically accept field updates (such as authentication tokens) from the server, even if promisor.acceptFromServer is set to none (the default).
Quoted 4 lines
I am guessing that the client would behave as if the existing promisor.acceptFromServer configuration variable were set to "all" when talking with a remote whose URL matches one of the patterns listed?
Yes, that's the idea.
Quoted 1 line
By the way, some people may suggest "white" -> "allow".
Right, I have changed all the "whitelist" instances with "allowlist".
Quoted 5 lines
Documentation/config/promisor.adoc promisor.acceptFromServer:: · line 68
Quoted 1 line
Documentation/config/promisor.adoc +1
-0+1. Start with a secure protocol scheme, like `https://` or `ssh://`.Is there a practical reason why people would want to use schemes other than the above two? This sounds like something a small amount of code can easily enforce.
The main issue is that some remote helper schemes might be secure, while it might be difficult to maintain a hardcoded allowlist of them. (Different implementations might exist out there with the same scheme name but different security properties.)
Also file:// and http:// for example might be OK in some corporate setups.
We could add yet another config variable (or env variable) for an allowlist of schemes (on top of https:// and ssh:// which would be the only ones accepted by default), but maybe we can do that in a future patch series.
[...]
Quoted 24 lines
Quoted 13 lines
Documentation/config/promisor.adoc promisor.acceptFromServer:: · line 81
Quoted 4 lines
+3. Don't use globs (
*) in the domain name. For exampleDocumentation/config/promisor.adoc +3
-0+ `https://cdn.example.com/*` is much safer than + `https://*.example.com/*`, because the latter matches + `https://evil-hacker.net/fake.example.com/repo`.Is there a practical use case where allowing '*' to match anything that contains a slash '/' is useful?
Documentation/config/promisor.adoc promisor.acceptFromServer:: · line 86
Quoted 4 lines
+4. Make sure to have a
/at the end of the domain name (or the endDocumentation/config/promisor.adoc +3
-0+ of specific directories). For example `https://cdn.example.com/*` + is much safer than `https://cdn.example.com*`, because the latter + matches `https://cdn.example.com.hacker.net/repo`.Quoted 5 lines
Ditto. The above two points sound like excuses to keep sloppy asterisk matching logic. Yes, retroactively tightening rules always have risk to break existing deployments, but if existing code paths of urlmatch do not have any good reason to allow '*' to match a string that contains a slash '/', perhaps there is no fallout.
I probably should caution the readers not to take the above too literally. Forbidding an asterisk '*' glob not to match '/' anywhere in urlmatch will obviusly break existing deployments that does this
Quoted 4 lines
[http "https://example.com/*"]
var = valand expects it to catch any URL pointing into the site.
Yeah, the main reason for allowing an asterisk '*' glob to match '/' is to allow something like:
git config set --global promisor.acceptFromServerUrl "https://my-org.com/*"
to be all what is needed for most internal work in many random orgs.
Quoted 6 lines
But I still do think the matcher should be more intelligent than the current implementation to avoid pitfalls like #3 and #4 above.
Perhaps if an additional rule says that '*' after the scheme:// part before the first '/' in the pattern, e.g.,
Quoted 8 lines
https://*.example.com/ https://*.example.com https://example.com*unlike '*' that appear anywhere else, never matches a substring that contains a slash '/' in it, it would cover plausible mistakes that the above #3 and #4 are trying to catch, without hurting any real world use case?
I agree that it is better security wise, so I have implemented it in the current version. Now the scheme and port parts must match exactly while * match any sequence of characters within the host and path parts but cannot cross part boundaries.
It's not a panacea though. Users still have to be very careful.
The current documentation looks like this:
--------------------
promisor.acceptFromServerUrl::
A glob pattern to specify which server-advertised URLs a client is allowed to act on. When a URL matches, the client will accept the advertised remote as a promisor remote and may automatically accept field updates (such as authentication tokens) from the server, even if promisor.acceptFromServer is set to none (the default).
+
This option can appear multiple times in config files. An advertised URL will be accepted if it matches _ANY_ glob pattern specified by this option in _ANY_ config file read by Git.
+
Be _VERY_ careful with these patterns: * matches any sequence of characters within the 'host' and 'path' parts of a URL (but cannot cross part boundaries). An overly broad pattern is a major security risk, as a matching URL allows a server to update fields (such as authentication tokens) on known remotes without further confirmation. To minimize security risks, follow these guidelines:
+
1. Start with a secure protocol scheme, like https:// or ssh://. +
2. Only allow domain names or paths where you control and trust _ALL_ the content. Be especially careful with shared hosting platforms like github.com or gitlab.com. A broad pattern like https://gitlab.com/* is dangerous because it trusts every repository on the entire platform. Always restrict such patterns to your specific organization or namespace (e.g., https://gitlab.com/your-org/*).
+
3. Never use globs at the end of domain names. For example, https://cdn.your-org.com/* might be safe, but https://cdn.your-org.com*/* is a major security risk because the latter matches https://cdn.your-org.com.hacker.net/repo.
+
4. Be careful using globs at the beginning of domain names. While the code ensures a * in the host cannot cross into the path, a pattern like https://*.example.com/* will still match any subdomain. This is extremely dangerous on shared hosting platforms (e.g., https://*.github.io/* trusts every user's site on the entire platform).
+
Before matching, both the advertised URL and the pattern are
normalized: the scheme and host are lowercased, percent-encoded characters are decoded where possible, and path segments like .. are resolved. The port must also match exactly (e.g., https://example.com:8080/* will not match a URL advertised on port 9999).
+
For the security implications of accepting a promisor remote, see the documentation of promisor.acceptFromServer. For details on the protocol, see linkgit:gitprotocol-v2[5].
--------------------
I will work on the suggestions Patrick made before sending the v2 (which I may split into 2 patch series as Patrick suggested).
Thanks.
Re: [PATCH 14/16] promisor-remote: trust known remotes matching acceptFromServerUrl
Quoted 10 lines · Christian Couder
Quoted 7 lines
Between the first sentence and the second one, I think there needs to be an explanation on what "trusted" means in this context. Is it trusted so that the URL can feed random configuration variable=value pairs for the client to blindly apply? Or is it trusted to do very limited things that other remotes can do, and if so what are these limited things? Without knowing that, the end-users cannot assess the security implications of setting this option.
Yeah, in the current version, the following is used, which is more explicit:
...
Do you mean by "the current version", the one you are preparing as an updated iteration?
If so, let me mark the topic to be expecting a reroll. From the reviews by Patrick, I am not sure if I should also add the usual "(hopefully small and final)" in this case, not just yet, though.
Thanks.
Re: [PATCH 14/16] promisor-remote: trust known remotes matching acceptFromServerUrl
Quoted 11 lines · Junio C Hamano
Quoted 8 lines · Christian Couder
Quoted 7 lines
Between the first sentence and the second one, I think there needs to be an explanation on what "trusted" means in this context. Is it trusted so that the URL can feed random configuration variable=value pairs for the client to blindly apply? Or is it trusted to do very limited things that other remotes can do, and if so what are these limited things? Without knowing that, the end-users cannot assess the security implications of setting this option.
Quoted 5 lines
Quoted 2 lines
Yeah, in the current version, the following is used, which is more explicit:
...Do you mean by "the current version", the one you are preparing as an updated iteration?
Yes, but I am going to split the series as Patrick suggested into:
1) a preparatory series which adds fixes, refactorings and cleanups,
2) a series which adds the new features related to the new acceptFromServerUrl config variable.
I will send 1) soon, and 2) later when it looks like 1) has graduated or will graduate soon.
Quoted 3 lines
If so, let me mark the topic to be expecting a reroll. From the reviews by Patrick, I am not sure if I should also add the usual "(hopefully small and final)" in this case, not just yet, though.
You can also just drop it or mark it as superseded by 1) when I have sent it.
Thanks.
Re: [PATCH 14/16] promisor-remote: trust known remotes matching acceptFromServerUrl
In reply to Christian CouderQuoted 10 lines · Christian Couder
A previous commit introduced the
promisor.acceptFromServerUrlconfig variable along with the machinery to parse and validate the URL glob patterns and optional remote name prefixes it contains. However, these URL patterns are not yet tied into the client's acceptance logic.When a promisor remote is already configured locally, its fields (like authentication tokens) may occasionally need to be refreshed by the server. If
promisor.acceptFromServeris set to the secure default ("None"), these updates are rejected, potentially causing future fetches to fail.
This only talks about already-configured remotes, and so I was naturally wondering what about not-yet-configured remotes. But looking ahead a bit shows that this is implemented in the next commit. Good.
Quoted 26 lines
To enable such targeted updates for trusted URLs, let's use the URL patterns from
promisor.acceptFromServerUrlas an additional URL based whitelist.Concretely, let's check the advertised URLs against the URL glob patterns by introducing a new small helper function called
url_matches_accept_list(), which iterates over the glob patterns and returns the first matchingallowed_urlentry (or NULL).(Before matching, the advertised URL is passed through
url_normalize()so that case variations in the scheme/host, percent-encoding tricks, and ".." path segments cannot bypass the whitelist.)Let's then use this helper at the tail of
should_accept_remote()so that, whenaccept == ACCEPT_NONE, a known remote whose URL matches the whitelist is still accepted.To prepare for this new logic, let's also:
- Add an '
accept_urls' parameter toshould_accept_remote().- Replace the
BUG()guard in theACCEPT_KNOWN_URLcase with an explicit 'if (accept ==ACCEPT_KNOWN_URL) return' and a newBUG()guard in theACCEPT_NONEcase, sourl_matches_accept_list()is only called in theACCEPT_NONEcase.
Quoted 8 lines
- Call
accept_from_server_url()fromfilter_promisor_remote()and relax its early return so that the function is entered whenaccept_urlshas entries even ifaccept == ACCEPT_NONE.Let's then properly document
promisor.acceptFromServerUrlin "promisor.adoc" as an additive security whitelist for known remotes, including the URL normalization behavior, and let's mention it in "gitprotocol-v2.adoc".
I feel like the description is steering a bit too strongly into the direction of a step-by-step instruction of how to implement the change rather than explaining what's done and why it's done this way.
Quoted 51 lines
Signed-off-by Christian Couder <[email protected]>--- Documentation/config/promisor.adoc | 46 +++++++++++++++++ Documentation/gitprotocol-v2.adoc | 9 ++-- promisor-remote.c | 50 +++++++++++++++--- t/t5710-promisor-remote-capability.sh | 73 +++++++++++++++++++++++++++ 4 files changed, 166 insertions(+), 12 deletions(-)Documentation/config/promisor.adoc +35
-0@@ -51,6 +51,52 @@ promisor.acceptFromServer:: to "fetch" and "clone" requests from the client. Name and URL comparisons are case sensitive. See linkgit:gitprotocol-v2[5]. +promisor.acceptFromServerUrl:: + A glob pattern to specify which URLs advertised by a server + are considered trusted by the client. This option acts as an + additive security whitelist that works in conjunction with + `promisor.acceptFromServer`. ++ +This option can appear multiple times in config files. An advertised +URL will be accepted if it matches _ANY_ glob pattern specified by +this option in _ANY_ config file read by Git. ++ +Be _VERY_ careful with these glob patterns, as it can be a big +security hole to allow any advertised remote to be auto-configured! +To minimize security risks, follow these guidelines: ++ +1. Start with a secure protocol scheme, like `https://` or `ssh://`. ++ +2. Only allow domain names or paths where you control and trust _ALL_ + the content. Be especially careful with shared hosting platforms + like `github.com` or `gitlab.com`. A broad pattern like + `https://gitlab.com/*` is dangerous because it trusts every + repository on the entire platform. Always restrict such patterns to + your specific organization or namespace (e.g., + `https://gitlab.com/your-org/*`). ++ +3. Don't use globs (`*`) in the domain name. For example + `https://cdn.example.com/*` is much safer than + `https://*.example.com/*`, because the latter matches + `https://evil-hacker.net/fake.example.com/repo`. ++ +4. Make sure to have a `/` at the end of the domain name (or the end + of specific directories). For example `https://cdn.example.com/*` + is much safer than `https://cdn.example.com*`, because the latter + matches `https://cdn.example.com.hacker.net/repo`. ++ +Before matching, the advertised URL is normalized: the scheme and
Documentation/config/promisor.adoc promisor.acceptFromServer:: · line 98
Quoted 10 lines
Documentation/config/promisor.adoc +10
-0+host are lowercased, percent-encoded characters are decoded where +possible, and path segments like `..` are resolved. Glob patterns +are matched against this normalized URL as-is, so patterns should +be written in normalized form (e.g., lowercase scheme and host). ++ +Even if `promisor.acceptFromServer` is set to `None` (the default), +Git will still accept field updates (like tokens) for known remotes, +provided their URLs match a pattern in +`promisor.acceptFromServerUrl`. See linkgit:gitprotocol-v2[5] for +details on the protocol.
Given that there's a bunch to process here, would it make sense to give users an example for how to do it properly?
I also wonder why we require a new config entry instead of extending promisor.acceptFromRemote to have for example a new "url:https://..." setting. Are there cases where you would ever want to use the new URL-based schema with a different setting than "all"?
I guess the case with "none" is exactly that, where you may auto-update configured remotes. But I wonder whether it would be more sensible to split out behaviour of accepting and updating promisors into separate configuration variables. These are ultimately different concerns, and the interaction as layed out in this commit is somewhat non-obvious to me.
Patrick
Re: [PATCH 14/16] promisor-remote: trust known remotes matching acceptFromServerUrl
Quoted 33 lines · Patrick Steinhardt
Quoted 30 lines · Christian Couder
To enable such targeted updates for trusted URLs, let's use the URL patterns from
promisor.acceptFromServerUrlas an additional URL based whitelist.Concretely, let's check the advertised URLs against the URL glob patterns by introducing a new small helper function called
url_matches_accept_list(), which iterates over the glob patterns and returns the first matchingallowed_urlentry (or NULL).(Before matching, the advertised URL is passed through
url_normalize()so that case variations in the scheme/host, percent-encoding tricks, and ".." path segments cannot bypass the whitelist.)Let's then use this helper at the tail of
should_accept_remote()so that, whenaccept == ACCEPT_NONE, a known remote whose URL matches the whitelist is still accepted.To prepare for this new logic, let's also:
- Add an '
accept_urls' parameter toshould_accept_remote().- Replace the
BUG()guard in theACCEPT_KNOWN_URLcase with an explicit 'if (accept ==ACCEPT_KNOWN_URL) return' and a newBUG()guard in theACCEPT_NONEcase, sourl_matches_accept_list()is only called in theACCEPT_NONEcase.- Call
accept_from_server_url()fromfilter_promisor_remote()and relax its early return so that the function is entered whenaccept_urlshas entries even ifaccept == ACCEPT_NONE.
Quoted 8 lines
Quoted 4 lines
Let's then properly document
promisor.acceptFromServerUrlin "promisor.adoc" as an additive security whitelist for known remotes, including the URL normalization behavior, and let's mention it in "gitprotocol-v2.adoc".I feel like the description is steering a bit too strongly into the direction of a step-by-step instruction of how to implement the change rather than explaining what's done and why it's done this way.
I have added the following:
"With this, many organizations may only need something like:
git config set --global \
promisor.acceptFromServerUrl "https://my-org.com/*"to accept only their own remotes. And if they need to accept additional remotes in some specific repos, they can also set:
git config set promisor.acceptFromServer knownUrl
and configure the additional remote manually only in the repos where they are needed."
Quoted 40 lines
Quoted 40 lines
Documentation/config/promisor.adoc +40
-0+promisor.acceptFromServerUrl:: + A glob pattern to specify which URLs advertised by a server + are considered trusted by the client. This option acts as an + additive security whitelist that works in conjunction with + `promisor.acceptFromServer`. ++ +This option can appear multiple times in config files. An advertised +URL will be accepted if it matches _ANY_ glob pattern specified by +this option in _ANY_ config file read by Git. ++ +Be _VERY_ careful with these glob patterns, as it can be a big +security hole to allow any advertised remote to be auto-configured! +To minimize security risks, follow these guidelines: ++ +1. Start with a secure protocol scheme, like `https://` or `ssh://`. ++ +2. Only allow domain names or paths where you control and trust _ALL_ + the content. Be especially careful with shared hosting platforms + like `github.com` or `gitlab.com`. A broad pattern like + `https://gitlab.com/*` is dangerous because it trusts every + repository on the entire platform. Always restrict such patterns to + your specific organization or namespace (e.g., + `https://gitlab.com/your-org/*`). ++ +3. Don't use globs (`*`) in the domain name. For example + `https://cdn.example.com/*` is much safer than + `https://*.example.com/*`, because the latter matches + `https://evil-hacker.net/fake.example.com/repo`. ++ +4. Make sure to have a `/` at the end of the domain name (or the end + of specific directories). For example `https://cdn.example.com/*` + is much safer than `https://cdn.example.com*`, because the latter + matches `https://cdn.example.com.hacker.net/repo`. ++ +Before matching, the advertised URL is normalized: the scheme and +host are lowercased, percent-encoded characters are decoded where +possible, and path segments like `..` are resolved. Glob patterns +are matched against this normalized URL as-is, so patterns should +be written in normalized form (e.g., lowercase scheme and host). ++
Quoted 8 lines
Documentation/config/promisor.adoc promisor.acceptFromServer:: · line 98
Quoted 5 lines
Documentation/config/promisor.adoc +5
-0+Even if `promisor.acceptFromServer` is set to `None` (the default), +Git will still accept field updates (like tokens) for known remotes, +provided their URLs match a pattern in +`promisor.acceptFromServerUrl`. See linkgit:gitprotocol-v2[5] for +details on the protocol.Given that there's a bunch to process here, would it make sense to give users an example for how to do it properly?
I can give an example like the one I added to the commit message (see above), but it might be too lax for some use cases. Perhaps in many organizations only a single repo will ever require to accept promisor remotes, so giving an example with the --global flag like:
git config set --global promisor.acceptFromServerUrl "https://my-org.com/*"
could make everyone's config a bit more vulnerable than necessary.
I think it's better to nudge people to think through the four steps above, rather than to encourage them to copy-paste something that might not be very well suited to their needs.
Quoted 4 lines
I also wonder why we require a new config entry instead of extending
promisor.acceptFromRemoteto have for example a new "url:https://..." setting. Are there cases where you would ever want to use the new URL-based schema with a different setting than "all"?
Yes, I think the example in the commit message shows why having both:
- promisor.acceptFromRemote that you can set for example to "knownUrl" only in some specific repos where you accept external promisor remotes that you configure manually, and
- promisor.acceptFromRemoteUrl that you can set for example to "https://my-org.com/*" globally
can be relatively simple and quite powerful:
- all internal remotes (with URLs in https://my-org.com/) are automatically accepted in all the repos,
- in certain specific repos, some external remotes (with names and URLs that are manually configured in the repos) are also accepted.
Quoted 6 lines
I guess the case with "none" is exactly that, where you may auto-update configured remotes. But I wonder whether it would be more sensible to split out behaviour of accepting and updating promisors into separate configuration variables. These are ultimately different concerns, and the interaction as layed out in this commit is somewhat non-obvious to me.
Let me know if there are things I could clarify more in the above explanations. I am also open to concrete suggestions.
Thanks.
PATCH 15/16 promisor-remote: auto-configure unknown remotes
In reply to Christian CouderPrevious commits have introduced the promisor.acceptFromServerUrl config variable to whitelist some URLs advertised by a server through the "promisor-remote" protocol capability.
However the new promisor.acceptFromServerUrl mechanism, like the old promisor.acceptFromServer mechanism, still requires a remote to already exist in the client's local configuration before it can be accepted. This places a significant manual burden on users to pre-configure these remotes, and creates friction for administrators who have to troubleshoot or manually provision these setups for their teams.
To eliminate this burden, let's automatically create a new [remote] section in the client's config when a server advertises an unknown remote whose URL matches a promisor.acceptFromServerUrl glob pattern.
Concretely, let's add four helpers:
- sanitize_remote_name(): turn an arbitrary URL-derived string into a valid remote name by replacing non-alphanumeric characters, collapsing runs of '-', and prepending "promisor-auto-".
- promisor_remote_name_from_url(): normalize the URL and extract host+port+path to build a human-readable base name, then pass it through sanitize_remote_name().
- configure_auto_promisor_remote(): write the remote.*.url, remote.*.promisor and remote.*.advertisedAs keys to the repo config.
- handle_matching_allowed_url(): pick the final name (user-supplied alias or auto-generated), handle collisions by appending "-1", "-2", etc., then call configure_auto_promisor_remote().
Let's also add should_accept_new_remote_url() which reuses the url_matches_accept_list() helper introduced in a previous commit to find a matching pattern, then delegates to handle_matching_allowed_url() to create the remote.
And then let's call should_accept_new_remote_url() from the '!item' (unknown remote) branch of should_accept_remote(), setting reload_config so that the newly-written config is picked up.
Finally let's document all that by:
- expanding the promisor.acceptFromServerUrl entry to describe auto-creation, the optional "name=" prefix syntax, the "promisor-auto-*" generation rules, and numeric-suffix collision handling, and by
- adding a "remote.<name>.advertisedAs" entry to "remote.adoc".
--- Documentation/config/promisor.adoc | 35 ++++- Documentation/config/remote.adoc | 9 ++ promisor-remote.c | 202 +++++++++++++++++++++++++- t/t5710-promisor-remote-capability.sh | 122 ++++++++++++++++ 4 files changed, 355 insertions(+), 13 deletions(-)
Documentation/config/promisor.adoc +27 -8
@@ -53,9 +53,11 @@ promisor.acceptFromServer:: promisor.acceptFromServerUrl:: A glob pattern to specify which URLs advertised by a server - are considered trusted by the client. This option acts as an - additive security whitelist that works in conjunction with - `promisor.acceptFromServer`. + are allowed to be auto-configured (created and persisted) on + the client side. Unlike `promisor.acceptFromServer`, which + only accepts already configured remotes, a match against this + option instructs Git to write a new `[remote "<name>"]` + section to the client's configuration. + This option can appear multiple times in config files. An advertised URL will be accepted if it matches _ANY_ glob pattern specified by
@@ -91,11 +93,28 @@ possible, and path segments like `..` are resolved. Glob patterns are matched against this normalized URL as-is, so patterns should be written in normalized form (e.g., lowercase scheme and host). + -Even if `promisor.acceptFromServer` is set to `None` (the default), -Git will still accept field updates (like tokens) for known remotes, -provided their URLs match a pattern in -`promisor.acceptFromServerUrl`. See linkgit:gitprotocol-v2[5] for -details on the protocol. +The glob pattern can optionally be prefixed with a remote name and an +equals sign (e.g., `cdn=https://cdn.example.com/*`). If such a prefix +is provided, accepted remotes will be saved under that name. If no +such prefix is provided, a safe remote name will be automatically +generated by sanitizing the URL and prefixing it with +`promisor-auto-`. If a remote with the chosen name already exists but +points to a different URL, Git will append a numeric suffix (e.g., +`-1`, `-2`) to the name to prevent overwriting existing +configurations. You should make sure that this doesn't happen often +though, as remotes will be rejected if the numeric suffix increases +too much. In all cases, the original name advertised by the server is +recorded in the `remote.<name>.advertisedAs` configuration variable +for tracing and debugging purposes. ++ +Note that this option acts as an additive security whitelist. It works +in conjunction with `promisor.acceptFromServer` (see the documentation +of that option for the implications of accepting a promisor +remote). Even if `promisor.acceptFromServer` is set to `None` (the +default), Git will still automatically configure new remotes, and +accept field updates (like tokens) for known remotes, provided their +URLs match a pattern in `promisor.acceptFromServerUrl`. See +linkgit:gitprotocol-v2[5] for details on the protocol. promisor.checkFields:: A comma or space separated list of additional remote related
Documentation/config/remote.adoc +9 -0
@@ -91,6 +91,15 @@ remote.<name>.promisor:: When set to true, this remote will be used to fetch promisor objects. +remote.<name>.advertisedAs:: + When a promisor remote is automatically configured using + information advertised by a server through the + `promisor-remote` protocol capability (see + `promisor.acceptFromServerUrl`), the server's originally + advertised name is saved in this variable. This is for + information, tracing and debugging purposes. Users should not + typically modify or create such configuration entries. + remote.<name>.partialclonefilter:: The filter that will be applied when fetching from this promisor remote. Changing or clearing this value will only affect fetches for new commits.
promisor-remote.c +197 -5
223 lines not on this page · raw message
t/t5710-promisor-remote-capability.sh +122 -0
128 lines not on this page · raw message
Signature · 1 line
2.53.0.625.g20f70b52bb
Re: [PATCH 15/16] promisor-remote: auto-configure unknown remotes
Quoted 12 lines · Christian Couder
Previous commits have introduced the
promisor.acceptFromServerUrlconfig variable to whitelist some URLs advertised by a server through the "promisor-remote" protocol capability.However the new
promisor.acceptFromServerUrlmechanism, like the oldpromisor.acceptFromServermechanism, still requires a remote to already exist in the client's local configuration before it can be accepted. This places a significant manual burden on users to pre-configure these remotes, and creates friction for administrators who have to troubleshoot or manually provision these setups for their teams.
Quoted 3 lines
To eliminate this burden, let's automatically create a new
[remote]section in the client's config when a server advertises an unknown remote whose URL matches apromisor.acceptFromServerUrlglob pattern.
Would it make sense to extend git-clone(1) to have a command line option that basically does this as a one-shot? Something like git clone --accept-promisors=url:https://gitlab.com/*? I assume that many users may not want to keep on updating their configured promisors all the time.
Furthermore, this here reconfirms my thought on the previous commit that it would make sense to detangle accepting promisors, storing them in the configuration and updating them automatically. These are all different things:
- Accepting promisors is basically an ongoing runtime thing where you start to use announced promisors even though they are not configured at all.
- Storing promisors is typically a one-time thing that you'd want to do when creating a new repository.
- Updating promisors automatically is probably something you want to do on an ongoing basis when you have stored promisors.
We're currently putting all of these use cases into the same bag, but they have very different characteristics. I guess the most common use case will eventually be to never auto-accept promisors, store them at clone time, and keep them updated whenever they change. This cannot be expressed with "promisor.acceptFromServerUrl" as far as I understand.
So ideally, we'd have:
- "acceptFromServer" to configure ongoing runtime behaviour.
- "storeFromServer" and a one-time command-line option for git-clone(1) to configure which remotes to persist.
- "updateFromServer" to update stored promisors.
Patrick
Re: [PATCH 15/16] promisor-remote: auto-configure unknown remotes
Quoted 18 lines · Patrick Steinhardt
Quoted 12 lines · Christian Couder
Previous commits have introduced the
promisor.acceptFromServerUrlconfig variable to whitelist some URLs advertised by a server through the "promisor-remote" protocol capability.However the new
promisor.acceptFromServerUrlmechanism, like the oldpromisor.acceptFromServermechanism, still requires a remote to already exist in the client's local configuration before it can be accepted. This places a significant manual burden on users to pre-configure these remotes, and creates friction for administrators who have to troubleshoot or manually provision these setups for their teams.Quoted 3 lines
To eliminate this burden, let's automatically create a new
[remote]section in the client's config when a server advertises an unknown remote whose URL matches apromisor.acceptFromServerUrlglob pattern.
Quoted 5 lines
Would it make sense to extend git-clone(1) to have a command line option that basically does this as a one-shot? Something like
git clone --accept-promisors=url:https://gitlab.com/*? I assume that many users may not want to keep on updating their configured promisors all the time.
I don't understand why you say "many users may not want to keep on updating their configured promisors all the time". It seems to me that what I propose requires even less effort from users than what you suggest.
If users set up something like:
git config set --global promisor.acceptFromServerUrl "https://my-org.com/*"
or:
git config set --global promisor.acceptFromServerUrl
"https://gitlab.com/my-org/*"
they would then automatically accept the promisor remotes with an URL matching the pattern when they make a partial clone.
So it's a one time setup instead of having to use --accept-promisors=url:... each time they clone.
Also git -c promisor.acceptFromServerUrl="..." clone can basically be used to get the same thing as the --accept-promisors=url:... flag you suggest.
Quoted 8 lines
Furthermore, this here reconfirms my thought on the previous commit that it would make sense to detangle accepting promisors, storing them in the configuration and updating them automatically. These are all different things:
- Accepting promisors is basically an ongoing runtime thing where you start to use announced promisors even though they are not configured at all.
Why an "ongoing runtime thing"? If users think it's fine to accept promisors from their own domain, why should they have to confirm that every time they clone?
Quoted 2 lines
- Storing promisors is typically a one-time thing that you'd want to do when creating a new repository.
Except that some fields and maybe sometimes URLs might change on the server side and it would be nice if this didn't require manual updates on the client side.
Quoted 2 lines
- Updating promisors automatically is probably something you want to do on an ongoing basis when you have stored promisors.
Yeah, so it's similar in many ways to storing promisors.
Quoted 2 lines
We're currently putting all of these use cases into the same bag, but they have very different characteristics.
I don't think all use cases are put in the same bag. There are a number of config options already that allow a lot of customization. Adding "promisor.acceptFromServerUrl" as a separate option from "promisor.acceptFromServer" also only increases the possibilities for users.
Quoted 3 lines
I guess the most common use
case will eventually be to never auto-accept promisors, store them at clone time, and keep them updated whenever they change.
I am not sure at all this is the most common use case.
If you require a --accept-promisors=url:https://my-org.com/* each time, people might just copy-paste it or create an alias for that and then use it all the time and you won't get much more security than something like:
git config set --global promisor.acceptFromServerUrl "https://my-org.com/*"
once and then regular git clone ...
When users have to often pass parameters manually, the typos and misconfiguration risks also increase compared to admins setting things up globally for everyone, or even users doing it once for themselves.
Quoted 2 lines
This cannot be
expressed with "promisor.acceptFromServerUrl" as far as I understand.
git -c promisor.acceptFromServerUrl="..." clone is basically the same as the option you suggest.
PATCH 16/16 doc: promisor: improve acceptFromServer entry
In reply to Christian CouderThe entry for the promisor.acceptFromServer in "Documentation/config/promisor.adoc" has a number of issues:
- it's not clear if new remotes and URLs can be created,
- it looks like a big block of text,
- it's not easy to see all the options,
- it's not easy to see which option is the default one,
- for "knownName", it says "advertised by the client" instead of "advertised by the server",
- it doesn't refer to the new related acceptFromServerUrl option.
Let's address all these issues by rewording large parts of it and using bullet points for the different options.
--- Documentation/config/promisor.adoc | 53 ++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 18 deletions(-)
Documentation/config/promisor.adoc +35 -18
@@ -32,24 +32,41 @@ variable is set to "true", and the "name" and "url" fields are always advertised regardless of this setting. promisor.acceptFromServer:: - If set to "all", a client will accept all the promisor remotes - a server might advertise using the "promisor-remote" - capability. If set to "knownName" the client will accept - promisor remotes which are already configured on the client - and have the same name as those advertised by the client. This - is not very secure, but could be used in a corporate setup - where servers and clients are trusted to not switch name and - URLs. If set to "knownUrl", the client will accept promisor - remotes which have both the same name and the same URL - configured on the client as the name and URL advertised by the - server. This is more secure than "all" or "knownName", so it - should be used if possible instead of those options. Default - is "none", which means no promisor remote advertised by a - server will be accepted. By accepting a promisor remote, the - client agrees that the server might omit objects that are - lazily fetchable from this promisor remote from its responses - to "fetch" and "clone" requests from the client. Name and URL - comparisons are case sensitive. See linkgit:gitprotocol-v2[5]. + Controls which promisor remotes advertised by a server (using the + "promisor-remote" protocol capability) a client will accept. By + accepting a promisor remote, the client agrees that the server + might omit objects that are lazily fetchable from this promisor + remote from its responses to "fetch" and "clone" requests. ++ +Note that this option does not cause new remotes to be automatically +created in the client's configuration. It only allows remotes which +are somehow already configured to be trusted for the current +operation, or their fields to be updated (if `promisor.storeFields` is +set and the remote already exists locally). To allow Git to +automatically create and persist new remotes from server +advertisements, use `promisor.acceptFromServerUrl`. ++ +The available options are: ++ +* `none` (default): No promisor remote advertised by a server will be + accepted. ++ +* `knownUrl`: The client will accept promisor remotes that are already + configured on the client and have both the same name and the same URL + as advertised by the server. This is more secure than `all` or + `knownName`, and should be used if possible instead of those options. ++ +* `knownName`: The client will accept promisor remotes that are already + configured on the client and have the same name as those advertised + by the server. This is not very secure, but could be used in a corporate + setup where servers and clients are trusted to not switch names and URLs. ++ +* `all`: The client will accept all the promisor remotes a server might + advertise. This is the least secure option and should only be used in + fully trusted environments. ++ +Name and URL comparisons are case-sensitive. See linkgit:gitprotocol-v2[5] +for protocol details. promisor.acceptFromServerUrl:: A glob pattern to specify which URLs advertised by a server
Signature · 1 line
2.53.0.625.g20f70b52bb
Quoted 35 lines · Christian Couder
High level description of the patches
=====================================- Patch 1/16 ("promisor-remote: try accepted remotes before others in
get_direct()"):Fixes
promisor_remote_get_direct()to prioritize accepted remotes. This could be a separate fix, but is needed towards the end of the series.- Patches 2-3/16 ("urlmatch:*"):
Exposes and adapts helpers in the urlmatch API.
- Patches 4-11/16 ("promisor-remote:*"):
Big refactoring of
filter_promisor_remote()andshould_accept_remote(). This keepsstruct promisor_infoinstances alive longer to anticipate possible state-desync bugs, decouples the server's advertised name from the local config name, and sanitizes control flow without changing the existing behavior.- Patch 12/16 ("t5710:*"):
Cleans up how "file://" URIs are managed in the test script to prepare for URI normalization later in the series and avoid issues on Windows.
- Patches 13-15/16 ("promisor-remote:*"):
The core feature. Introduces the parsing machinery, adds the additive whitelist for known remotes (with
url_normalize()security), and finally implements the auto-creation and collision resolution for unknown remotes.
Quoted 4 lines
- Patch 16/16 ("doc: promisor: improve acceptFromServer entry"):
Cleans up and modernizes the existing
promisor.acceptFromServerdocumentation.
I wonder whether it would make sense to split up this series into two. The first 12 patches and parts of 16 are all sensible improvements that can land independent of the patches that introduce the new logic. And given that I expect some discussion around the new logic itself, I expect that these refactorings can land way faster on their own.
It would also help reduce the review load a bit if one then ultimately only has to review three patches for the new feature.
Patrick
Quoted 8 lines · Patrick Steinhardt
I wonder whether it would make sense to split up this series into two. The first 12 patches and parts of 16 are all sensible improvements that can land independent of the patches that introduce the new logic. And given that I expect some discussion around the new logic itself, I expect that these refactorings can land way faster on their own.
It would also help reduce the review load a bit if one then ultimately only has to review three patches for the new feature.
Fine with me. I will send a preparatory series with 10 patches; one new and 9 from the 16 patch series. Then I expect that the series with the new logic will only be around 7 patches.