fetch: send server options when using protocol v2
Teach fetch to optionally accept server options by specifying them on the cmdline via '-o' or '--server-option'. These server options are sent to the remote end when performing a fetch communicating using protocol version 2. If communicating using a protocol other than v2 the provided options are ignored and not sent to the remote end. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brandon Williams committed
Apr 23, 2018 at 15:46 UTC
5e3548ef161d4d284e35cf5f5d6a181ba4fe707b
6 files changed
+38
Documentation/fetch-options.txt
+8
@@ -188,6 +188,14 @@ endif::git-pull[]
188
is specified. This flag forces progress status even if the
189
standard error stream is not directed to a terminal.
190
191
+-o <option>::
192
+--server-option=<option>::
193
+ Transmit the given string to the server when communicating using
194
+ protocol version 2. The given string must not contain a NUL or LF
195
+ character.
196
+ When multiple `--server-option=<option>` are given, they are all
197
+ sent to the other side in the order listed on the command line.
198
+
199
-4::
200
--ipv4::
201
Use IPv4 addresses only, ignoring IPv6 addresses.
builtin/fetch.c
+5
@@ -62,6 +62,7 @@ static int shown_url = 0;
62
static int refmap_alloc, refmap_nr;
63
static const char **refmap_array;
64
static struct list_objects_filter_options filter_options;
65
+static struct string_list server_options = STRING_LIST_INIT_DUP;
66
67
static int git_fetch_config(const char *k, const char *v, void *cb)
68
{
@@ -170,6 +171,7 @@ static struct option builtin_fetch_options[] = {
171
N_("accept refs that update .git/shallow")),
172
{ OPTION_CALLBACK, 0, "refmap", NULL, N_("refmap"),
173
N_("specify fetch refmap"), PARSE_OPT_NONEG, parse_refmap_arg },
174
+ OPT_STRING_LIST('o', "server-option", &server_options, N_("server-specific"), N_("option to transmit")),
175
OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
176
TRANSPORT_FAMILY_IPV4),
177
OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
@@ -1417,6 +1419,9 @@ static int fetch_one(struct remote *remote, int argc, const char **argv, int pru
1419
}
1420
}
1421
1422
+ if (server_options.nr)
1423
+ gtransport->server_options = &server_options;
1424
+
1425
sigchain_push_common(unlock_pack_on_signal);
1426
atexit(unlock_pack);
1427
refspec = parse_fetch_refspec(ref_nr, refs);
fetch-pack.c
+7
@@ -1174,6 +1174,13 @@ static int send_fetch_request(int fd_out, const struct fetch_pack_args *args,
1174
packet_buf_write(&req_buf, "command=fetch");
1175
if (server_supports_v2("agent", 0))
1176
packet_buf_write(&req_buf, "agent=%s", git_user_agent_sanitized());
1177
+ if (args->server_options && args->server_options->nr &&
1178
+ server_supports_v2("server-option", 1)) {
1179
+ int i;
1180
+ for (i = 0; i < args->server_options->nr; i++)
1181
+ packet_write_fmt(fd_out, "server-option=%s",
1182
+ args->server_options->items[i].string);
1183
+ }
1184
1185
packet_buf_delim(&req_buf);
1186
if (args->use_thin_pack)
fetch-pack.h
+1
@@ -15,6 +15,7 @@ struct fetch_pack_args {
15
const char *deepen_since;
16
const struct string_list *deepen_not;
17
struct list_objects_filter_options filter_options;
18
+ const struct string_list *server_options;
19
unsigned deepen_relative:1;
20
unsigned quiet:1;
21
unsigned keep_pack:1;
t/t5702-protocol-v2.sh
+16
@@ -217,6 +217,22 @@ test_expect_success 'ref advertisment is filtered during fetch using protocol v2
217
! grep "refs/tags/three" log
218
'
219
220
+test_expect_success 'server-options are sent when fetching' '
221
+ test_when_finished "rm -f log" &&
222
+
223
+ test_commit -C file_parent four &&
224
+
225
+ GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \
226
+ fetch -o hello -o world origin master &&
227
+
228
+ git -C file_child log -1 --format=%s origin/master >actual &&
229
+ git -C file_parent log -1 --format=%s >expect &&
230
+ test_cmp expect actual &&
231
+
232
+ grep "server-option=hello" log &&
233
+ grep "server-option=world" log
234
+'
235
+
236
# Test protocol v2 with 'http://' transport
237
#
238
. "$TEST_DIRECTORY"/lib-httpd.sh
transport.c
+1
@@ -266,6 +266,7 @@ static int fetch_refs_via_pack(struct transport *transport,
266
args.no_dependents = data->options.no_dependents;
267
args.filter_options = data->options.filter_options;
268
args.stateless_rpc = transport->stateless_rpc;
269
+ args.server_options = transport->server_options;
270
271
if (!data->got_remote_heads)
272
refs_tmp = get_refs_via_connect(transport, 0, NULL);