Skip to content

Commit 41267e9

Browse files
committed
Merge branch 'bw/server-options'
The transport protocol v2 is getting updated further. * bw/server-options: fetch: send server options when using protocol v2 ls-remote: send server options when using protocol v2 serve: introduce the server-option capability
2 parents 30b015b + 5e3548e commit 41267e9

File tree

14 files changed

+116
-3
lines changed

14 files changed

+116
-3
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.

Documentation/git-ls-remote.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ OPTIONS
7070
themselves will not work for refs whose objects have not yet been
7171
fetched from the remote, and will give a `missing object` error.
7272

73+
-o <option>::
74+
--server-option=<option>::
75+
Transmit the given string to the server when communicating using
76+
protocol version 2. The given string must not contain a NUL or LF
77+
character.
78+
When multiple `--server-option=<option>` are given, they are all
79+
sent to the other side in the order listed on the command line.
80+
7381
<repository>::
7482
The "remote" repository to query. This parameter can be
7583
either a URL or the name of a remote (see the GIT URLS and

Documentation/technical/protocol-v2.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,3 +393,13 @@ header.
393393
1 - pack data
394394
2 - progress messages
395395
3 - fatal error message just before stream aborts
396+
397+
server-option
398+
~~~~~~~~~~~~~~~
399+
400+
If advertised, indicates that any number of server specific options can be
401+
included in a request. This is done by sending each option as a
402+
"server-option=<option>" capability line in the capability-list section of
403+
a request.
404+
405+
The provided options must not contain a NUL or LF character.

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);

builtin/ls-remote.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
4747
const char **pattern = NULL;
4848
struct argv_array ref_prefixes = ARGV_ARRAY_INIT;
4949
int i;
50+
struct string_list server_options = STRING_LIST_INIT_DUP;
5051

5152
struct remote *remote;
5253
struct transport *transport;
@@ -73,6 +74,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
7374
2, PARSE_OPT_NOCOMPLETE),
7475
OPT_BOOL(0, "symref", &show_symref_target,
7576
N_("show underlying ref in addition to the object pointed by it")),
77+
OPT_STRING_LIST('o', "server-option", &server_options, N_("server-specific"), N_("option to transmit")),
7678
OPT_END()
7779
};
7880

@@ -116,6 +118,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
116118
transport = transport_get(remote, NULL);
117119
if (uploadpack != NULL)
118120
transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
121+
if (server_options.nr)
122+
transport->server_options = &server_options;
119123

120124
ref = transport_get_remote_refs(transport, &ref_prefixes);
121125
if (transport_disconnect(transport)) {

connect.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,8 @@ static int process_ref_v2(const char *line, struct ref ***list)
408408

409409
struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,
410410
struct ref **list, int for_push,
411-
const struct argv_array *ref_prefixes)
411+
const struct argv_array *ref_prefixes,
412+
const struct string_list *server_options)
412413
{
413414
int i;
414415
*list = NULL;
@@ -419,6 +420,12 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,
419420
if (server_supports_v2("agent", 0))
420421
packet_write_fmt(fd_out, "agent=%s", git_user_agent_sanitized());
421422

423+
if (server_options && server_options->nr &&
424+
server_supports_v2("server-option", 1))
425+
for (i = 0; i < server_options->nr; i++)
426+
packet_write_fmt(fd_out, "server-option=%s",
427+
server_options->items[i].string);
428+
422429
packet_delim(fd_out);
423430
/* When pushing we don't want to request the peeled tags */
424431
if (!for_push)

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;

remote.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ void free_refs(struct ref *ref);
153153
struct oid_array;
154154
struct packet_reader;
155155
struct argv_array;
156+
struct string_list;
156157
extern struct ref **get_remote_heads(struct packet_reader *reader,
157158
struct ref **list, unsigned int flags,
158159
struct oid_array *extra_have,
@@ -161,7 +162,8 @@ extern struct ref **get_remote_heads(struct packet_reader *reader,
161162
/* Used for protocol v2 in order to retrieve refs from a remote */
162163
extern struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,
163164
struct ref **list, int for_push,
164-
const struct argv_array *ref_prefixes);
165+
const struct argv_array *ref_prefixes,
166+
const struct string_list *server_options);
165167

166168
int resolve_remote_symref(struct ref *ref, struct ref *list);
167169
int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid);

serve.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ static struct protocol_capability capabilities[] = {
5656
{ "agent", agent_advertise, NULL },
5757
{ "ls-refs", always_advertise, ls_refs },
5858
{ "fetch", upload_pack_advertise, upload_pack_v2 },
59+
{ "server-option", always_advertise, NULL },
5960
};
6061

6162
static void advertise_capabilities(void)

0 commit comments

Comments
 (0)