From patchwork Mon Sep 23 12:17:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 13809543 Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0600880038 for ; Mon, 23 Sep 2024 12:18:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727093885; cv=none; b=HZhsFyH16sWydIZ6zNwIaDwRPQ5xr7xFWlHBJdPv+kwAOa5ezXIA/4a7wpYnTxGHvtmcZaJImDRTzcCciBCvNeErQvfeYN2Y17/0er5OjdfxAxYPWkQZyFXp5uT0qbfTOCAAJfdoxXGrX7EJUzjHeYQ7mOLk2QwJh7rsj51etZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727093885; c=relaxed/simple; bh=WYRM6wyff+20KFjQl8qJ7HpOU5N9qHrlpNCaA0RWhno=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=A1YAWhAZ9JfchCKA/w/oIinN3N1FEc4sugXtfT4wchpqSLl6l3/uD8JMpu5M+x4KCHMuWWuCE8T/8iK9lfe9cc6GWNPuggMO8k4QAB9LaGdZnjvurK/IW7jy49vvXoXz7XDVnmMtu86QWqlCP/Oq1os2Sjr6K3sMbARI6r1Lj14= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EPxjsUYz; arc=none smtp.client-ip=209.85.208.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EPxjsUYz" Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2f75c205e4aso43623091fa.0 for ; Mon, 23 Sep 2024 05:18:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727093881; x=1727698681; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=02H85lhZU9IJ9wZ1YxKwIBj2MFkv32MBKXN7V5+U/xA=; b=EPxjsUYzHfMZwuaCe4I7ag8pG6kAXD+hUiagV3GxUQbZ5EXWt1OSg/rPXcvbT//RDQ bUFDiu2bitiLfCRWicPaxZumm0abFCibQVYyJW04wD61rB9gU1w8dFHnTtjjZyPAhshR xor0vEcZ71aaohijc29VedTi2TohnEcYXpJLzhleSp8gT7Wh5uj/039DcM4C7eB5czLo KNbma4yZ3Zaj+hTuGoZgQxrF+Wx0xa5HW/44a+z7ssFp0c96XiOi+tbcRHcjRfCIRDUv Cnk7xbvtc3v+7o/hYbqTxdNBvOP3aVcShHHAfrkdLVFe45DE78rcesSmwvU1d7EPArQ4 piHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727093881; x=1727698681; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=02H85lhZU9IJ9wZ1YxKwIBj2MFkv32MBKXN7V5+U/xA=; b=QOwmrAdYijBsDCApcWb+6NnaeUHwJEJC4Qb1kxMSLLz5+XzL1QdrrsRgy2Tbo46vFx TCpe3rR5vOmlBCobg3wn9sNMFqnsgfdRW93oETjdK+jwnaebtLez9Y/DM76+BNBcislb XBkRK69gbMDToy33oSEnPmXHeE9sbvuH54PY79PYWN471ZqBzkE4IDRnbS4iUoL0BQwh BffRk9GvtieV/KWIVa/L+dpA1Mee/lC4hl3ipdct7D0OXbnqJ0TcBjtdZLDwTrjwMuBy sJR/5CSP2odk5XnC1wVB0CviguIg+LcWCWVVimLyXCFE7WL0X5+E03YBHAmd2oGQh7wq 4SSw== X-Gm-Message-State: AOJu0Yw5BYMILLd8v677ELA54uru4ueNls1sqbfnZZBfYxqq3LxYc0iG PUOHcEC+KVA4o+iT5xJ5IT+YtSykxhLVekeVJy0NIh9Gp05nTlV7t5tTsA== X-Google-Smtp-Source: AGHT+IFMTefZDZeKpkTWSiY7BVz5VsunwarySGAncEy5TfjP19QUEv01BV1iCS5+/a8SfMh4pzd9Sw== X-Received: by 2002:a2e:9fca:0:b0:2f3:ecdd:2b8d with SMTP id 38308e7fff4ca-2f7cc366476mr41436511fa.16.1727093880229; Mon, 23 Sep 2024 05:18:00 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c5c3d18cb0sm855187a12.77.2024.09.23.05.17.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2024 05:17:59 -0700 (PDT) Message-Id: In-Reply-To: References: From: "blanet via GitGitGadget" Date: Mon, 23 Sep 2024 12:17:53 +0000 Subject: [PATCH v2 0/5] Support server option from configuration Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Brandon Williams , Jonathan Tan , Patrick Steinhardt , blanet 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=