2023-04-11 10:41:48 +03:00
|
|
|
#include "git-compat-util.h"
|
2017-10-16 20:55:24 +03:00
|
|
|
#include "config.h"
|
2023-03-21 09:26:03 +03:00
|
|
|
#include "environment.h"
|
2017-10-16 20:55:24 +03:00
|
|
|
#include "protocol.h"
|
2023-04-11 06:00:38 +03:00
|
|
|
#include "trace2.h"
|
2017-10-16 20:55:24 +03:00
|
|
|
|
|
|
|
static enum protocol_version parse_protocol_version(const char *value)
|
|
|
|
{
|
|
|
|
if (!strcmp(value, "0"))
|
|
|
|
return protocol_v0;
|
|
|
|
else if (!strcmp(value, "1"))
|
|
|
|
return protocol_v1;
|
2018-03-14 21:31:47 +03:00
|
|
|
else if (!strcmp(value, "2"))
|
|
|
|
return protocol_v2;
|
2017-10-16 20:55:24 +03:00
|
|
|
else
|
|
|
|
return protocol_unknown_version;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum protocol_version get_protocol_version_config(void)
|
|
|
|
{
|
|
|
|
const char *value;
|
2019-02-26 00:54:06 +03:00
|
|
|
const char *git_test_k = "GIT_TEST_PROTOCOL_VERSION";
|
2019-12-24 04:02:28 +03:00
|
|
|
const char *git_test_v;
|
2019-02-26 00:54:06 +03:00
|
|
|
|
2020-08-14 19:17:36 +03:00
|
|
|
if (!git_config_get_string_tmp("protocol.version", &value)) {
|
2017-10-16 20:55:24 +03:00
|
|
|
enum protocol_version version = parse_protocol_version(value);
|
|
|
|
|
|
|
|
if (version == protocol_unknown_version)
|
|
|
|
die("unknown value for config 'protocol.version': %s",
|
|
|
|
value);
|
|
|
|
|
2019-12-24 04:02:28 +03:00
|
|
|
return version;
|
2019-02-26 00:54:06 +03:00
|
|
|
}
|
|
|
|
|
2019-12-24 04:02:28 +03:00
|
|
|
git_test_v = getenv(git_test_k);
|
2019-02-26 00:54:06 +03:00
|
|
|
if (git_test_v && *git_test_v) {
|
|
|
|
enum protocol_version env = parse_protocol_version(git_test_v);
|
|
|
|
|
|
|
|
if (env == protocol_unknown_version)
|
|
|
|
die("unknown value for %s: %s", git_test_k, git_test_v);
|
2019-12-24 04:02:28 +03:00
|
|
|
return env;
|
2017-10-16 20:55:24 +03:00
|
|
|
}
|
|
|
|
|
protocol: re-enable v2 protocol by default
Protocol v2 became the default in v2.26.0 via 684ceae32d (fetch: default
to protocol version 2, 2019-12-23). More widespread use turned up a
regression in negotiation. That was fixed in v2.27.0 via 4fa3f00abb
(fetch-pack: in protocol v2, in_vain only after ACK, 2020-04-27), but we
also reverted the default to v0 as a precuation in 11c7f2a30b (Revert
"fetch: default to protocol version 2", 2020-04-22).
In v2.28.0, we re-enabled it for experimental users with 3697caf4b9
(config: let feature.experimental imply protocol.version=2, 2020-05-20)
and haven't heard any complaints. v2.28 has only been out for 2 months,
but I'd generally expect people turning on feature.experimental to also
stay pretty up-to-date. So we're not likely to collect much more data by
waiting. In addition, we have no further reports from people running
v2.26.0, and of course some people have been setting protocol.version
manually for ages.
Let's move forward with v2 as the default again. It's possible there are
still lurking bugs, but we won't know until it gets more widespread use.
And we can find and squash them just like any other bug at this point.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-09-25 21:34:36 +03:00
|
|
|
return protocol_v2;
|
2017-10-16 20:55:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
enum protocol_version determine_protocol_version_server(void)
|
|
|
|
{
|
|
|
|
const char *git_protocol = getenv(GIT_PROTOCOL_ENVIRONMENT);
|
|
|
|
enum protocol_version version = protocol_v0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine which protocol version the client has requested. Since
|
|
|
|
* multiple 'version' keys can be sent by the client, indicating that
|
|
|
|
* the client is okay to speak any of them, select the greatest version
|
|
|
|
* that the client has requested. This is due to the assumption that
|
|
|
|
* the most recent protocol version will be the most state-of-the-art.
|
|
|
|
*/
|
|
|
|
if (git_protocol) {
|
|
|
|
struct string_list list = STRING_LIST_INIT_DUP;
|
|
|
|
const struct string_list_item *item;
|
|
|
|
string_list_split(&list, git_protocol, ':', -1);
|
|
|
|
|
|
|
|
for_each_string_list_item(item, &list) {
|
|
|
|
const char *value;
|
|
|
|
enum protocol_version v;
|
|
|
|
|
|
|
|
if (skip_prefix(item->string, "version=", &value)) {
|
|
|
|
v = parse_protocol_version(value);
|
|
|
|
if (v > version)
|
|
|
|
version = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
string_list_clear(&list, 0);
|
|
|
|
}
|
|
|
|
|
2021-08-10 20:20:39 +03:00
|
|
|
trace2_data_intmax("transfer", NULL, "negotiated-version", version);
|
|
|
|
|
2017-10-16 20:55:24 +03:00
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum protocol_version determine_protocol_version_client(const char *server_response)
|
|
|
|
{
|
|
|
|
enum protocol_version version = protocol_v0;
|
|
|
|
|
|
|
|
if (skip_prefix(server_response, "version ", &server_response)) {
|
|
|
|
version = parse_protocol_version(server_response);
|
|
|
|
|
|
|
|
if (version == protocol_unknown_version)
|
|
|
|
die("server is speaking an unknown protocol");
|
|
|
|
if (version == protocol_v0)
|
|
|
|
die("protocol error: server explicitly said version 0");
|
|
|
|
}
|
|
|
|
|
|
|
|
return version;
|
|
|
|
}
|