aboutsummaryrefslogtreecommitdiff
path: root/connect.c
diff options
context:
space:
mode:
authorBrandon Williams <bmwill@google.com>2017-10-16 10:55:27 -0700
committerJunio C Hamano <gitster@pobox.com>2017-10-17 10:51:29 +0900
commit2609043da00ea0db411c44179136b07bf210bf75 (patch)
treef8a501be93ed1651e583c44b546847aa0a55017a /connect.c
parentaa9bab29b8b5e70be5c89e375bfba6e0051b3682 (diff)
downloadgit-2609043da00ea0db411c44179136b07bf210bf75.tar.gz
git-2609043da00ea0db411c44179136b07bf210bf75.tar.xz
connect: teach client to recognize v1 server response
Teach a client to recognize that a server understands protocol v1 by looking at the first pkt-line the server sends in response. This is done by looking for the response "version 1" send by upload-pack or receive-pack. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'connect.c')
-rw-r--r--connect.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/connect.c b/connect.c
index 8e2e276b6..a5e708a61 100644
--- a/connect.c
+++ b/connect.c
@@ -12,6 +12,7 @@
#include "sha1-array.h"
#include "transport.h"
#include "strbuf.h"
+#include "protocol.h"
static char *server_capabilities;
static const char *parse_feature_value(const char *, const char *, int *);
@@ -129,9 +130,23 @@ static int read_remote_ref(int in, char **src_buf, size_t *src_len,
return len;
}
-#define EXPECTING_FIRST_REF 0
-#define EXPECTING_REF 1
-#define EXPECTING_SHALLOW 2
+#define EXPECTING_PROTOCOL_VERSION 0
+#define EXPECTING_FIRST_REF 1
+#define EXPECTING_REF 2
+#define EXPECTING_SHALLOW 3
+
+/* Returns 1 if packet_buffer is a protocol version pkt-line, 0 otherwise. */
+static int process_protocol_version(void)
+{
+ switch (determine_protocol_version_client(packet_buffer)) {
+ case protocol_v1:
+ return 1;
+ case protocol_v0:
+ return 0;
+ default:
+ die("server is speaking an unknown protocol");
+ }
+}
static void process_capabilities(int *len)
{
@@ -224,12 +239,19 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
*/
int responded = 0;
int len;
- int state = EXPECTING_FIRST_REF;
+ int state = EXPECTING_PROTOCOL_VERSION;
*list = NULL;
while ((len = read_remote_ref(in, &src_buf, &src_len, &responded))) {
switch (state) {
+ case EXPECTING_PROTOCOL_VERSION:
+ if (process_protocol_version()) {
+ state = EXPECTING_FIRST_REF;
+ break;
+ }
+ state = EXPECTING_FIRST_REF;
+ /* fallthrough */
case EXPECTING_FIRST_REF:
process_capabilities(&len);
if (process_dummy_ref()) {