Skip to content

Commit 957f724

Browse files
committed
Merge branch 'js/protocol-advertise-multi' into pu
The transport layer has been updated so that the protocol version used can be negotiated between the parties, by the initiator listing the protocol versions it is willing to talk, and the other side choosing from one of them. * js/protocol-advertise-multi: protocol: advertise multiple supported versions
2 parents 50a24b9 + 6da1f1a commit 957f724

20 files changed

+253
-79
lines changed

builtin/archive.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "transport.h"
99
#include "parse-options.h"
1010
#include "pkt-line.h"
11+
#include "protocol.h"
1112
#include "sideband.h"
1213

1314
static void create_output_file(const char *output_file)
@@ -95,6 +96,8 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
9596
OPT_END()
9697
};
9798

99+
register_allowed_protocol_version(protocol_v0);
100+
98101
argc = parse_options(argc, argv, prefix, local_opts, NULL,
99102
PARSE_OPT_KEEP_ALL);
100103

builtin/clone.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
917917

918918
struct argv_array ref_prefixes = ARGV_ARRAY_INIT;
919919

920+
register_allowed_protocol_version(protocol_v2);
921+
register_allowed_protocol_version(protocol_v1);
922+
register_allowed_protocol_version(protocol_v0);
923+
920924
fetch_if_missing = 0;
921925

922926
packet_trace_identity("clone");

builtin/fetch-pack.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
5959

6060
fetch_if_missing = 0;
6161

62+
register_allowed_protocol_version(protocol_v2);
63+
register_allowed_protocol_version(protocol_v1);
64+
register_allowed_protocol_version(protocol_v0);
65+
6266
packet_trace_identity("fetch-pack");
6367

6468
memset(&args, 0, sizeof(args));

builtin/fetch.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "argv-array.h"
2222
#include "utf8.h"
2323
#include "packfile.h"
24+
#include "protocol.h"
2425
#include "list-objects-filter-options.h"
2526
#include "commit-reach.h"
2627

@@ -1582,6 +1583,10 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
15821583
int prune_tags_ok = 1;
15831584
struct argv_array argv_gc_auto = ARGV_ARRAY_INIT;
15841585

1586+
register_allowed_protocol_version(protocol_v2);
1587+
register_allowed_protocol_version(protocol_v1);
1588+
register_allowed_protocol_version(protocol_v0);
1589+
15851590
packet_trace_identity("fetch");
15861591

15871592
fetch_if_missing = 0;

builtin/ls-remote.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "builtin.h"
22
#include "cache.h"
3+
#include "protocol.h"
34
#include "transport.h"
45
#include "ref-filter.h"
56
#include "remote.h"
@@ -79,6 +80,10 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
7980

8081
memset(&ref_array, 0, sizeof(ref_array));
8182

83+
register_allowed_protocol_version(protocol_v2);
84+
register_allowed_protocol_version(protocol_v1);
85+
register_allowed_protocol_version(protocol_v0);
86+
8287
argc = parse_options(argc, argv, prefix, options, ls_remote_usage,
8388
PARSE_OPT_STOP_AT_NON_OPTION);
8489
dest = argv[0];

builtin/pull.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "config.h"
1111
#include "builtin.h"
1212
#include "parse-options.h"
13+
#include "protocol.h"
1314
#include "exec-cmd.h"
1415
#include "run-command.h"
1516
#include "sha1-array.h"
@@ -874,6 +875,10 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
874875
struct object_id rebase_fork_point;
875876
int autostash;
876877

878+
register_allowed_protocol_version(protocol_v2);
879+
register_allowed_protocol_version(protocol_v1);
880+
register_allowed_protocol_version(protocol_v0);
881+
877882
if (!getenv("GIT_REFLOG_ACTION"))
878883
set_reflog_message(argc, argv);
879884

builtin/push.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "remote.h"
1111
#include "transport.h"
1212
#include "parse-options.h"
13+
#include "protocol.h"
1314
#include "submodule.h"
1415
#include "submodule-config.h"
1516
#include "send-pack.h"
@@ -590,6 +591,9 @@ int cmd_push(int argc, const char **argv, const char *prefix)
590591
OPT_END()
591592
};
592593

594+
register_allowed_protocol_version(protocol_v1);
595+
register_allowed_protocol_version(protocol_v0);
596+
593597
packet_trace_identity("push");
594598
git_config(git_push_config, &flags);
595599
argc = parse_options(argc, argv, prefix, options, push_usage, 0);

builtin/receive-pack.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,6 +1945,9 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
19451945

19461946
packet_trace_identity("receive-pack");
19471947

1948+
register_allowed_protocol_version(protocol_v1);
1949+
register_allowed_protocol_version(protocol_v0);
1950+
19481951
argc = parse_options(argc, argv, prefix, options, receive_pack_usage, 0);
19491952

19501953
if (argc > 1)

builtin/send-pack.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
184184
OPT_END()
185185
};
186186

187+
register_allowed_protocol_version(protocol_v1);
188+
register_allowed_protocol_version(protocol_v0);
189+
187190
git_config(send_pack_config, NULL);
188191
argc = parse_options(argc, argv, prefix, options, send_pack_usage, 0);
189192
if (argc > 0) {

builtin/upload-archive.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "builtin.h"
66
#include "archive.h"
77
#include "pkt-line.h"
8+
#include "protocol.h"
89
#include "sideband.h"
910
#include "run-command.h"
1011
#include "argv-array.h"
@@ -82,6 +83,8 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
8283
if (argc == 2 && !strcmp(argv[1], "-h"))
8384
usage(upload_archive_usage);
8485

86+
register_allowed_protocol_version(protocol_v0);
87+
8588
/*
8689
* Set up sideband subprocess.
8790
*

builtin/upload-pack.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ int cmd_upload_pack(int argc, const char **argv, const char *prefix)
3333
packet_trace_identity("upload-pack");
3434
read_replace_refs = 0;
3535

36+
register_allowed_protocol_version(protocol_v2);
37+
register_allowed_protocol_version(protocol_v1);
38+
register_allowed_protocol_version(protocol_v0);
39+
3640
argc = parse_options(argc, argv, prefix, options, upload_pack_usage, 0);
3741

3842
if (argc != 1)

connect.c

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ static enum ssh_variant determine_ssh_variant(const char *ssh_command,
10431043
*/
10441044
static struct child_process *git_connect_git(int fd[2], char *hostandport,
10451045
const char *path, const char *prog,
1046-
enum protocol_version version,
1046+
const struct strbuf *version_advert,
10471047
int flags)
10481048
{
10491049
struct child_process *conn;
@@ -1081,12 +1081,9 @@ static struct child_process *git_connect_git(int fd[2], char *hostandport,
10811081
prog, path, 0,
10821082
target_host, 0);
10831083

1084-
/* If using a new version put that stuff here after a second null byte */
1085-
if (version > 0) {
1086-
strbuf_addch(&request, '\0');
1087-
strbuf_addf(&request, "version=%d%c",
1088-
version, '\0');
1089-
}
1084+
/* Add version fields after a second null byte */
1085+
strbuf_addch(&request, '\0');
1086+
strbuf_addf(&request, "%s%c", version_advert->buf, '\0');
10901087

10911088
packet_write(fd[1], request.buf, request.len);
10921089

@@ -1101,14 +1098,13 @@ static struct child_process *git_connect_git(int fd[2], char *hostandport,
11011098
*/
11021099
static void push_ssh_options(struct argv_array *args, struct argv_array *env,
11031100
enum ssh_variant variant, const char *port,
1104-
enum protocol_version version, int flags)
1101+
const struct strbuf *version_advert, int flags)
11051102
{
1106-
if (variant == VARIANT_SSH &&
1107-
version > 0) {
1103+
if (variant == VARIANT_SSH) {
11081104
argv_array_push(args, "-o");
11091105
argv_array_push(args, "SendEnv=" GIT_PROTOCOL_ENVIRONMENT);
1110-
argv_array_pushf(env, GIT_PROTOCOL_ENVIRONMENT "=version=%d",
1111-
version);
1106+
argv_array_pushf(env, GIT_PROTOCOL_ENVIRONMENT "=%s",
1107+
version_advert->buf);
11121108
}
11131109

11141110
if (flags & CONNECT_IPV4) {
@@ -1161,7 +1157,7 @@ static void push_ssh_options(struct argv_array *args, struct argv_array *env,
11611157

11621158
/* Prepare a child_process for use by Git's SSH-tunneled transport. */
11631159
static void fill_ssh_args(struct child_process *conn, const char *ssh_host,
1164-
const char *port, enum protocol_version version,
1160+
const char *port, const struct strbuf *version_advert,
11651161
int flags)
11661162
{
11671163
const char *ssh;
@@ -1195,15 +1191,16 @@ static void fill_ssh_args(struct child_process *conn, const char *ssh_host,
11951191

11961192
argv_array_push(&detect.args, ssh);
11971193
argv_array_push(&detect.args, "-G");
1198-
push_ssh_options(&detect.args, &detect.env_array,
1199-
VARIANT_SSH, port, version, flags);
1194+
push_ssh_options(&detect.args, &detect.env_array, VARIANT_SSH,
1195+
port, version_advert, flags);
12001196
argv_array_push(&detect.args, ssh_host);
12011197

12021198
variant = run_command(&detect) ? VARIANT_SIMPLE : VARIANT_SSH;
12031199
}
12041200

12051201
argv_array_push(&conn->args, ssh);
1206-
push_ssh_options(&conn->args, &conn->env_array, variant, port, version, flags);
1202+
push_ssh_options(&conn->args, &conn->env_array, variant, port,
1203+
version_advert, flags);
12071204
argv_array_push(&conn->args, ssh_host);
12081205
}
12091206

@@ -1223,16 +1220,10 @@ struct child_process *git_connect(int fd[2], const char *url,
12231220
{
12241221
char *hostandport, *path;
12251222
struct child_process *conn;
1223+
struct strbuf version_advert = STRBUF_INIT;
12261224
enum protocol protocol;
1227-
enum protocol_version version = get_protocol_version_config();
12281225

1229-
/*
1230-
* NEEDSWORK: If we are trying to use protocol v2 and we are planning
1231-
* to perform a push, then fallback to v0 since the client doesn't know
1232-
* how to push yet using v2.
1233-
*/
1234-
if (version == protocol_v2 && !strcmp("git-receive-pack", prog))
1235-
version = protocol_v0;
1226+
get_client_protocol_version_advertisement(&version_advert);
12361227

12371228
/* Without this we cannot rely on waitpid() to tell
12381229
* what happened to our children.
@@ -1247,7 +1238,8 @@ struct child_process *git_connect(int fd[2], const char *url,
12471238
printf("Diag: path=%s\n", path ? path : "NULL");
12481239
conn = NULL;
12491240
} else if (protocol == PROTO_GIT) {
1250-
conn = git_connect_git(fd, hostandport, path, prog, version, flags);
1241+
conn = git_connect_git(fd, hostandport, path, prog,
1242+
&version_advert, flags);
12511243
conn->trace2_child_class = "transport/git";
12521244
} else {
12531245
struct strbuf cmd = STRBUF_INIT;
@@ -1292,14 +1284,14 @@ struct child_process *git_connect(int fd[2], const char *url,
12921284
return NULL;
12931285
}
12941286
conn->trace2_child_class = "transport/ssh";
1295-
fill_ssh_args(conn, ssh_host, port, version, flags);
1287+
fill_ssh_args(conn, ssh_host, port, &version_advert,
1288+
flags);
12961289
} else {
12971290
transport_check_allowed("file");
12981291
conn->trace2_child_class = "transport/file";
1299-
if (version > 0) {
1300-
argv_array_pushf(&conn->env_array, GIT_PROTOCOL_ENVIRONMENT "=version=%d",
1301-
version);
1302-
}
1292+
argv_array_pushf(&conn->env_array,
1293+
GIT_PROTOCOL_ENVIRONMENT "=%s",
1294+
version_advert.buf);
13031295
}
13041296
argv_array_push(&conn->args, cmd.buf);
13051297

0 commit comments

Comments
 (0)