upload-pack, receive-pack: introduce protocol version 1

Teach upload-pack and receive-pack to understand and respond using protocol version 1, if requested. Protocol version 1 is simply the original and current protocol (what I'm calling version 0) with the addition of a single packet line, which precedes the ref advertisement, indicating the protocol version being spoken. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed Oct 16, 2017 at 10:55 UTC aa9bab29b8b5e70be5c89e375bfba6e0051b3682
2 files changed +36 -1
builtin/receive-pack.c
+17
@@ -24,6 +24,7 @@
24 #include "tmp-objdir.h"
25 #include "oidset.h"
26 #include "packfile.h"
27 +#include "protocol.h"
28
29 static const char * const receive_pack_usage[] = {
30 N_("git receive-pack <git-dir>"),
@@ -1963,6 +1964,22 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
1964 else if (0 <= receive_unpack_limit)
1965 unpack_limit = receive_unpack_limit;
1966
1967 + switch (determine_protocol_version_server()) {
1968 + case protocol_v1:
1969 + /*
1970 + * v1 is just the original protocol with a version string,
1971 + * so just fall through after writing the version string.
1972 + */
1973 + if (advertise_refs || !stateless_rpc)
1974 + packet_write_fmt(1, "version 1\n");
1975 +
1976 + /* fallthrough */
1977 + case protocol_v0:
1978 + break;
1979 + case protocol_unknown_version:
1980 + BUG("unknown protocol version");
1981 + }
1982 +
1983 if (advertise_refs || !stateless_rpc) {
1984 write_head_info();
1985 }
upload-pack.c
+19 -1
@@ -18,6 +18,7 @@
18 #include "parse-options.h"
19 #include "argv-array.h"
20 #include "prio-queue.h"
21 +#include "protocol.h"
22
23 static const char * const upload_pack_usage[] = {
24 N_("git upload-pack [<options>] <dir>"),
@@ -1067,6 +1068,23 @@ int cmd_main(int argc, const char **argv)
1068 die("'%s' does not appear to be a git repository", dir);
1069
1070 git_config(upload_pack_config, NULL);
1070 - upload_pack();
1071 +
1072 + switch (determine_protocol_version_server()) {
1073 + case protocol_v1:
1074 + /*
1075 + * v1 is just the original protocol with a version string,
1076 + * so just fall through after writing the version string.
1077 + */
1078 + if (advertise_refs || !stateless_rpc)
1079 + packet_write_fmt(1, "version 1\n");
1080 +
1081 + /* fallthrough */
1082 + case protocol_v0:
1083 + upload_pack();
1084 + break;
1085 + case protocol_unknown_version:
1086 + BUG("unknown protocol version");
1087 + }
1088 +
1089 return 0;
1090 }