Skip to content

Commit 5e3548e

Browse files
bmwillgitster
authored andcommitted
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>
1 parent ff47322 commit 5e3548e

File tree

6 files changed

+38
-0
lines changed

6 files changed

+38
-0
lines changed

Documentation/fetch-options.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ endif::git-pull[]
188188
is specified. This flag forces progress status even if the
189189
standard error stream is not directed to a terminal.
190190

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+
191199
-4::
192200
--ipv4::
193201
Use IPv4 addresses only, ignoring IPv6 addresses.

builtin/fetch.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ static int shown_url = 0;
6262
static int refmap_alloc, refmap_nr;
6363
static const char **refmap_array;
6464
static struct list_objects_filter_options filter_options;
65+
static struct string_list server_options = STRING_LIST_INIT_DUP;
6566

6667
static int git_fetch_config(const char *k, const char *v, void *cb)
6768
{
@@ -170,6 +171,7 @@ static struct option builtin_fetch_options[] = {
170171
N_("accept refs that update .git/shallow")),
171172
{ OPTION_CALLBACK, 0, "refmap", NULL, N_("refmap"),
172173
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")),
173175
OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
174176
TRANSPORT_FAMILY_IPV4),
175177
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
14171419
}
14181420
}
14191421

1422+
if (server_options.nr)
1423+
gtransport->server_options = &server_options;
1424+
14201425
sigchain_push_common(unlock_pack_on_signal);
14211426
atexit(unlock_pack);
14221427
refspec = parse_fetch_refspec(ref_nr, refs);

fetch-pack.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,13 @@ static int send_fetch_request(int fd_out, const struct fetch_pack_args *args,
11741174
packet_buf_write(&req_buf, "command=fetch");
11751175
if (server_supports_v2("agent", 0))
11761176
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+
}
11771184

11781185
packet_buf_delim(&req_buf);
11791186
if (args->use_thin_pack)

fetch-pack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct fetch_pack_args {
1515
const char *deepen_since;
1616
const struct string_list *deepen_not;
1717
struct list_objects_filter_options filter_options;
18+
const struct string_list *server_options;
1819
unsigned deepen_relative:1;
1920
unsigned quiet:1;
2021
unsigned keep_pack:1;

t/t5702-protocol-v2.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,22 @@ test_expect_success 'ref advertisment is filtered during fetch using protocol v2
217217
! grep "refs/tags/three" log
218218
'
219219

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+
220236
# Test protocol v2 with 'http://' transport
221237
#
222238
. "$TEST_DIRECTORY"/lib-httpd.sh

transport.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ static int fetch_refs_via_pack(struct transport *transport,
266266
args.no_dependents = data->options.no_dependents;
267267
args.filter_options = data->options.filter_options;
268268
args.stateless_rpc = transport->stateless_rpc;
269+
args.server_options = transport->server_options;
269270

270271
if (!data->got_remote_heads)
271272
refs_tmp = get_refs_via_connect(transport, 0, NULL);

0 commit comments

Comments
 (0)