From: "Xing Xin via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Brandon Williams <bmwill@google.com>,
Jonathan Tan <jonathantanmy@google.com>,
blanet <bupt_xingxin@163.com>,
Xing Xin <xingxin.xx@bytedance.com>
Subject: [PATCH 4/4] builtin/ls-remote.c: recognize fetch.serverOption configuration
Date: Mon, 02 Sep 2024 12:13:56 +0000 [thread overview]
Message-ID: <8962031f9997c4030cf32652908fc431f3bf9976.1725279236.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1776.git.git.1725279236.gitgitgadget@gmail.com>
From: Xing Xin <xingxin.xx@bytedance.com>
Teach git-ls-remote 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.
Tests and documentation have been updated accordingly.
Signed-off-by: Xing Xin <xingxin.xx@bytedance.com>
---
Documentation/git-ls-remote.txt | 3 +++
builtin/ls-remote.c | 32 ++++++++++++++++++++++++++++----
t/t5702-protocol-v2.sh | 29 ++++++++++++++++++++++++-----
3 files changed, 55 insertions(+), 9 deletions(-)
diff --git a/Documentation/git-ls-remote.txt b/Documentation/git-ls-remote.txt
index 76c86c3ce4f..fc9930193f8 100644
--- a/Documentation/git-ls-remote.txt
+++ b/Documentation/git-ls-remote.txt
@@ -81,6 +81,9 @@ OPTIONS
character.
When multiple `--server-option=<option>` are given, they are all
sent to the other side in the order listed on the command line.
+ When no `--server-option=<option>` is given from the command
+ line, the values of configuration variable `fetch.serverOption`
+ are used instead.
<repository>::
The "remote" repository to query. This parameter can be
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 0a491595ca8..87afd69828c 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
#include "gettext.h"
#include "hex.h"
#include "transport.h"
@@ -8,6 +9,8 @@
#include "parse-options.h"
#include "wildmatch.h"
+static struct string_list config_server_options = STRING_LIST_INIT_DUP;
+
static const char * const ls_remote_usage[] = {
N_("git ls-remote [--branches] [--tags] [--refs] [--upload-pack=<exec>]\n"
" [-q | --quiet] [--exit-code] [--get-url] [--sort=<key>]\n"
@@ -37,6 +40,18 @@ static int tail_match(const struct strvec *pattern, const char *path)
return 0;
}
+static int git_ls_remote_config(const char *k, const char *v,
+ const struct config_context *ctx, void *cb)
+{
+ if (!strcmp(k, "fetch.serveroption")) {
+ if (!v)
+ return config_error_nonbool(k);
+ parse_transport_option(v, &config_server_options);
+ return 0;
+ }
+ return git_default_config(k, v, ctx, cb);
+}
+
int cmd_ls_remote(int argc, const char **argv, const char *prefix)
{
const char *dest = NULL;
@@ -49,8 +64,9 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
struct strvec pattern = STRVEC_INIT;
struct transport_ls_refs_options transport_options =
TRANSPORT_LS_REFS_OPTIONS_INIT;
+ struct string_list option_server_options = STRING_LIST_INIT_DUP;
+ struct string_list *server_options = NULL;
int i;
- struct string_list server_options = STRING_LIST_INIT_DUP;
struct remote *remote;
struct transport *transport;
@@ -80,16 +96,23 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
2, PARSE_OPT_NOCOMPLETE),
OPT_BOOL(0, "symref", &show_symref_target,
N_("show underlying ref in addition to the object pointed by it")),
- OPT_STRING_LIST('o', "server-option", &server_options, N_("server-specific"), N_("option to transmit")),
+ OPT_STRING_LIST('o', "server-option", &option_server_options,
+ N_("server-specific"),
+ N_("option to transmit")),
OPT_END()
};
+ git_config(git_ls_remote_config, NULL);
+
memset(&ref_array, 0, sizeof(ref_array));
argc = parse_options(argc, argv, prefix, options, ls_remote_usage,
PARSE_OPT_STOP_AT_NON_OPTION);
dest = argv[0];
+ server_options = option_server_options.nr ?
+ &option_server_options : &config_server_options;
+
/*
* TODO: This is buggy, but required for transport helpers. When a
* transport helper advertises a "refspec", then we'd add that to a
@@ -130,8 +153,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
transport = transport_get(remote, NULL);
if (uploadpack)
transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
- if (server_options.nr)
- transport->server_options = &server_options;
+ if (server_options && server_options->nr)
+ transport->server_options = server_options;
ref = transport_get_remote_refs(transport, &transport_options);
if (ref) {
@@ -169,5 +192,6 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
transport_ls_refs_options_release(&transport_options);
strvec_clear(&pattern);
+ string_list_clear(&option_server_options, 0);
return status;
}
diff --git a/t/t5702-protocol-v2.sh b/t/t5702-protocol-v2.sh
index 3bf31fb570d..da6241afa22 100755
--- a/t/t5702-protocol-v2.sh
+++ b/t/t5702-protocol-v2.sh
@@ -173,16 +173,35 @@ test_expect_success 'ref advertisement is filtered with ls-remote using protocol
test_expect_success 'server-options are sent when using ls-remote' '
test_when_finished "rm -f log" &&
- GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
- ls-remote -o hello -o world "file://$(pwd)/file_parent" main >actual &&
-
cat >expect <<-EOF &&
$(git -C file_parent rev-parse refs/heads/main)$(printf "\t")refs/heads/main
EOF
+ # Specify server options from command line
+ GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
+ ls-remote -o hello -o world "file://$(pwd)/file_parent" main >actual &&
+ test_cmp expect actual &&
+ test_grep "server-option=hello" log &&
+ test_grep "server-option=world" log &&
+ rm -f log &&
+
+ # Specify server options from fetch.serverOption config
+ GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
+ -c fetch.serverOption=hello -c fetch.serverOption=world \
+ ls-remote "file://$(pwd)/file_parent" main >actual &&
+ test_cmp expect actual &&
+ test_grep "server-option=hello" log &&
+ test_grep "server-option=world" log &&
+ rm -f log &&
+
+ # Cmdline server options take a higher priority
+ GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
+ -c fetch.serverOption=hello -c fetch.serverOption=world \
+ ls-remote -o foo=bar "file://$(pwd)/file_parent" main >actual &&
test_cmp expect actual &&
- grep "server-option=hello" log &&
- grep "server-option=world" log
+ test_grep ! "server-option=hello" log &&
+ test_grep ! "server-option=world" log &&
+ test_grep "server-option=foo=bar" log
'
test_expect_success 'warn if using server-option with ls-remote with legacy protocol' '
--
gitgitgadget
next prev parent reply other threads:[~2024-09-02 12:14 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-02 12:13 [PATCH 0/4] Support server option from configuration blanet via GitGitGadget
2024-09-02 12:13 ` [PATCH 1/4] transport: add parse_transport_option() method Xing Xin via GitGitGadget
2024-09-02 12:13 ` [PATCH 2/4] builtin/fetch.c: add fetch.serverOption configuration Xing Xin via GitGitGadget
2024-09-03 10:09 ` Patrick Steinhardt
2024-09-02 12:13 ` [PATCH 3/4] builtin/clone.c: recognize " Xing Xin via GitGitGadget
2024-09-03 10:09 ` Patrick Steinhardt
2024-09-04 7:49 ` Xing Xin
2024-09-05 11:05 ` Patrick Steinhardt
2024-09-05 12:12 ` Xing Xin
2024-09-05 13:44 ` Patrick Steinhardt
2024-09-05 17:50 ` Junio C Hamano
2024-09-09 2:50 ` Re:Re: Re: " Xing Xin
2024-09-09 11:49 ` Patrick Steinhardt
2024-09-23 13:04 ` Xing Xin
2024-09-09 15:44 ` Junio C Hamano
2024-09-02 12:13 ` Xing Xin via GitGitGadget [this message]
2024-09-03 10:09 ` [PATCH 4/4] builtin/ls-remote.c: " Patrick Steinhardt
2024-09-03 10:09 ` [PATCH 0/4] Support server option from configuration Patrick Steinhardt
2024-09-23 12:17 ` [PATCH v2 0/5] " blanet via GitGitGadget
2024-09-23 12:17 ` [PATCH v2 1/5] transport: introduce parse_transport_option() method Xing Xin via GitGitGadget
2024-09-23 12:17 ` [PATCH v2 2/5] remote: introduce remote.<name>.serverOption configuration Xing Xin via GitGitGadget
2024-10-07 8:22 ` Patrick Steinhardt
2024-10-08 3:38 ` Xing Xin
2024-09-23 12:17 ` [PATCH v2 3/5] transport.c::handshake: make use of server options from remote Xing Xin via GitGitGadget
2024-09-23 12:17 ` [PATCH v2 4/5] fetch: respect --server-option when fetching multiple remotes Xing Xin via GitGitGadget
2024-10-07 8:22 ` Patrick Steinhardt
2024-09-23 12:17 ` [PATCH v2 5/5] ls-remote: leakfix for not clearing server_options Xing Xin via GitGitGadget
2024-10-07 8:22 ` Patrick Steinhardt
2024-10-07 8:23 ` [PATCH v2 0/5] Support server option from configuration Patrick Steinhardt
2024-10-08 3:42 ` Xing Xin
2024-10-08 3:38 ` [PATCH v3 " blanet via GitGitGadget
2024-10-08 3:38 ` [PATCH v3 1/5] transport: introduce parse_transport_option() method Xing Xin via GitGitGadget
2024-10-08 3:38 ` [PATCH v3 2/5] remote: introduce remote.<name>.serverOption configuration Xing Xin via GitGitGadget
2024-10-08 3:38 ` [PATCH v3 3/5] transport.c::handshake: make use of server options from remote Xing Xin via GitGitGadget
2024-10-08 3:38 ` [PATCH v3 4/5] fetch: respect --server-option when fetching multiple remotes Xing Xin via GitGitGadget
2024-10-08 17:57 ` Junio C Hamano
2024-10-08 3:38 ` [PATCH v3 5/5] ls-remote: leakfix for not clearing server_options Xing Xin via GitGitGadget
2024-10-08 4:00 ` [PATCH v3 0/5] Support server option from configuration Patrick Steinhardt
2024-10-08 17:23 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8962031f9997c4030cf32652908fc431f3bf9976.1725279236.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=bmwill@google.com \
--cc=bupt_xingxin@163.com \
--cc=git@vger.kernel.org \
--cc=jonathantanmy@google.com \
--cc=xingxin.xx@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).