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>
This commit is contained in:
Brandon Williams 2017-10-16 10:55:26 -07:00 committed by Junio C Hamano
parent dfe422d04d
commit aa9bab29b8
2 changed files with 36 additions and 1 deletions

View File

@ -24,6 +24,7 @@
#include "tmp-objdir.h" #include "tmp-objdir.h"
#include "oidset.h" #include "oidset.h"
#include "packfile.h" #include "packfile.h"
#include "protocol.h"
static const char * const receive_pack_usage[] = { static const char * const receive_pack_usage[] = {
N_("git receive-pack <git-dir>"), N_("git receive-pack <git-dir>"),
@ -1963,6 +1964,22 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
else if (0 <= receive_unpack_limit) else if (0 <= receive_unpack_limit)
unpack_limit = receive_unpack_limit; unpack_limit = receive_unpack_limit;
switch (determine_protocol_version_server()) {
case protocol_v1:
/*
* v1 is just the original protocol with a version string,
* so just fall through after writing the version string.
*/
if (advertise_refs || !stateless_rpc)
packet_write_fmt(1, "version 1\n");
/* fallthrough */
case protocol_v0:
break;
case protocol_unknown_version:
BUG("unknown protocol version");
}
if (advertise_refs || !stateless_rpc) { if (advertise_refs || !stateless_rpc) {
write_head_info(); write_head_info();
} }

View File

@ -18,6 +18,7 @@
#include "parse-options.h" #include "parse-options.h"
#include "argv-array.h" #include "argv-array.h"
#include "prio-queue.h" #include "prio-queue.h"
#include "protocol.h"
static const char * const upload_pack_usage[] = { static const char * const upload_pack_usage[] = {
N_("git upload-pack [<options>] <dir>"), N_("git upload-pack [<options>] <dir>"),
@ -1067,6 +1068,23 @@ int cmd_main(int argc, const char **argv)
die("'%s' does not appear to be a git repository", dir); die("'%s' does not appear to be a git repository", dir);
git_config(upload_pack_config, NULL); git_config(upload_pack_config, NULL);
upload_pack();
switch (determine_protocol_version_server()) {
case protocol_v1:
/*
* v1 is just the original protocol with a version string,
* so just fall through after writing the version string.
*/
if (advertise_refs || !stateless_rpc)
packet_write_fmt(1, "version 1\n");
/* fallthrough */
case protocol_v0:
upload_pack();
break;
case protocol_unknown_version:
BUG("unknown protocol version");
}
return 0; return 0;
} }