From: blanet via GitGitGadget Date: Mon, 23 Sep 2024 12:17:53 GMT Subject: [PATCH v2 0/5] Support server option from configuration Message-ID: In-Reply-To: We have multiple internal repositories configured with a huge number of CI tasks, each requiring code preparation (either via clone or fetch). These CI tasks, triggered by post-receive hooks, often fetch the same code (usually using --depth=1) concurrently. To reduce performance impacts on the git server caused by these tasks, we want to deploy a special designed pack-objects-hook. This hook would allow the packs generated by git-pack-objects to be reused. Since not all clone/fetch operations will benefit from this caching (e.g., pulls from developers' environments), clients need to pass a special identifier to indicate whether caching should be enabled for a particular operation. Using server options is a suitable method for this. However, server options can only be specified via the command line option (via --server-option or -o), which is inconvenient and requires CI script modifications. A configuration-based approach is easier to propagate (by changing the global configuration ~/.gitconfig) and avoids issues with older Git versions that don't support --server-option. This patch series introduces a new multi-valued configuration, remote..serverOption, similar to push.pushOption, to specify default server options for the corresponding remote. * Patch 1~3 is the main change for introducing the new configuration. * Patch 4 fixes a issue for git-fetch not sending server-options when fetching multiple remotes. * Patch 5 is a minor fix for a server options-related memory leak. Xing Xin (5): transport: introduce parse_transport_option() method remote: introduce remote..serverOption configuration transport.c::handshake: make use of server options from remote fetch: respect --server-option when fetching multiple remotes ls-remote: leakfix for not clearing server_options Documentation/config/remote.txt | 10 +++ Documentation/fetch-options.txt | 3 + Documentation/git-clone.txt | 3 + Documentation/git-ls-remote.txt | 3 + builtin/fetch.c | 2 + builtin/ls-remote.c | 1 + builtin/push.c | 9 +-- remote.c | 7 ++ remote.h | 3 + t/t5702-protocol-v2.sh | 133 ++++++++++++++++++++++++++++++++ transport.c | 15 ++++ transport.h | 4 + 12 files changed, 185 insertions(+), 8 deletions(-) base-commit: 4590f2e9412378c61eac95966709c78766d326ba Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1776%2Fblanet%2Fxx%2Fadd-server-option-from-config-v2 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1776/blanet/xx/add-server-option-from-config-v2 Pull-Request: https://github.com/git/git/pull/1776 Range-diff vs v1: 1: 5c8f3c166a5 ! 1: c95ed5e0dd5 transport: add parse_transport_option() method @@ Metadata Author: Xing Xin ## Commit message ## - transport: add parse_transport_option() method + transport: introduce parse_transport_option() method - Introduce the `parse_transport_option()` method used to parse - `push.pushOption` configuration values. This method will be further - utilized in subsequent commits to parse a newly added - `fetch.serverOption` configuration for fetches, which aligns with the - design pattern of `push.pushOption`. + Add the `parse_transport_option()` method to parse the `push.pushOption` + configuration. This method will also be used in the next commit to + handle the new `remote..serverOption` configuration for setting + server options in Git protocol v2. Signed-off-by: Xing Xin ## builtin/push.c ## @@ builtin/push.c: static int git_push_config(const char *k, const char *v, + RECURSE_SUBMODULES_ON_DEMAND : RECURSE_SUBMODULES_OFF; + recurse_submodules = val; } else if (!strcmp(k, "push.pushoption")) { - if (!v) - return config_error_nonbool(k); +- if (!v) +- return config_error_nonbool(k); - else - if (!*v) - string_list_clear(&push_options_config, 0); - else - string_list_append(&push_options_config, v); -+ parse_transport_option(v, &push_options_config); - return 0; +- return 0; ++ return parse_transport_option(k, v, &push_options_config); } else if (!strcmp(k, "color.push")) { push_use_color = git_config_colorbool(k, v); + return 0; ## transport.c ## @@ transport.c: int is_transport_allowed(const char *type, int from_user) BUG("invalid protocol_allow_config type"); } -+void parse_transport_option(const char *option, struct string_list *transport_options) ++int parse_transport_option(const char *var, const char *value, ++ struct string_list *transport_options) +{ -+ if (!*option) ++ if (!value) ++ return config_error_nonbool(var); ++ if (!*value) + string_list_clear(transport_options, 0); + else -+ string_list_append(transport_options, option); ++ string_list_append(transport_options, value); ++ return 0; +} + void transport_check_allowed(const char *type) @@ transport.h: void transport_print_push_status(const char *dest, struct ref *refs /* common method used by transport-helper.c and send-pack.c */ void reject_atomic_push(struct ref *refs, int mirror_mode); -+/* common method to parse push-option for pushes or server-option for fetches */ -+void parse_transport_option(const char *option, struct string_list *transport_options); ++/* common method to parse push-option or server-option from config */ ++int parse_transport_option(const char *var, const char *value, ++ struct string_list *transport_options); + #endif 2: 7e2d5c504d7 < -: ----------- builtin/fetch.c: add fetch.serverOption configuration -: ----------- > 2: 2474b4c69d6 remote: introduce remote..serverOption configuration 3: 7c3ebda513d ! 3: a7f3e458501 builtin/clone.c: recognize fetch.serverOption configuration @@ Metadata Author: Xing Xin ## Commit message ## - builtin/clone.c: recognize fetch.serverOption configuration + transport.c::handshake: make use of server options from remote - Teach git-clone to recognize the `fetch.serverOption` configuration as a - default list of server options to send for Git protocol v2, if server - options are not explicitly set via the command line. + Utilize the `server_options` from the corresponding remote during the + handshake in `transport.c` when Git protocol v2 is detected. This helps + initialize the `server_options` in `transport.h:transport` if no server + options are set for the transport (typically via `--server-option` or + `-o`). - Note that `builtin/clone.c:cmd_clone` originally read the git config - twice via `builtin/clone.c:git_clone_config`, which would duplicate - server options if parsing logic were added there. Upon investigation, it - was found that the first config read is unnecessary since all the global - variables it sets are actually used after the second config read. - Therefore, the first config read is replaced with a simple - `config.c:git_default_config`. + While another potential place to incorporate server options from the + remote is in `transport.c:transport_get`, setting server options for a + transport using a protocol other than v2 could lead to unexpected errors + (see `transport.c:die_if_server_options`). - Tests and documentation have been updated accordingly. + Relevant tests and documentation have been updated accordingly. Signed-off-by: Xing Xin + ## Documentation/fetch-options.txt ## +@@ Documentation/fetch-options.txt: endif::git-pull[] + unknown ones, is server-specific. + When multiple `--server-option=