Skip to content

Commit aa9bab2

Browse files
bmwillgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dfe422d commit aa9bab2

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

builtin/receive-pack.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "tmp-objdir.h"
2525
#include "oidset.h"
2626
#include "packfile.h"
27+
#include "protocol.h"
2728

2829
static const char * const receive_pack_usage[] = {
2930
N_("git receive-pack <git-dir>"),
@@ -1963,6 +1964,22 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
19631964
else if (0 <= receive_unpack_limit)
19641965
unpack_limit = receive_unpack_limit;
19651966

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+
19661983
if (advertise_refs || !stateless_rpc) {
19671984
write_head_info();
19681985
}

upload-pack.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "parse-options.h"
1919
#include "argv-array.h"
2020
#include "prio-queue.h"
21+
#include "protocol.h"
2122

2223
static const char * const upload_pack_usage[] = {
2324
N_("git upload-pack [<options>] <dir>"),
@@ -1067,6 +1068,23 @@ int cmd_main(int argc, const char **argv)
10671068
die("'%s' does not appear to be a git repository", dir);
10681069

10691070
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+
10711089
return 0;
10721090
}

0 commit comments

Comments
 (0)