Git fork

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>

authored by

Brandon Williams and committed by
Junio C Hamano
2609043d aa9bab29

+26 -4
+26 -4
connect.c
··· 12 12 #include "sha1-array.h" 13 13 #include "transport.h" 14 14 #include "strbuf.h" 15 + #include "protocol.h" 15 16 16 17 static char *server_capabilities; 17 18 static const char *parse_feature_value(const char *, const char *, int *); ··· 129 130 return len; 130 131 } 131 132 132 - #define EXPECTING_FIRST_REF 0 133 - #define EXPECTING_REF 1 134 - #define EXPECTING_SHALLOW 2 133 + #define EXPECTING_PROTOCOL_VERSION 0 134 + #define EXPECTING_FIRST_REF 1 135 + #define EXPECTING_REF 2 136 + #define EXPECTING_SHALLOW 3 137 + 138 + /* Returns 1 if packet_buffer is a protocol version pkt-line, 0 otherwise. */ 139 + static int process_protocol_version(void) 140 + { 141 + switch (determine_protocol_version_client(packet_buffer)) { 142 + case protocol_v1: 143 + return 1; 144 + case protocol_v0: 145 + return 0; 146 + default: 147 + die("server is speaking an unknown protocol"); 148 + } 149 + } 135 150 136 151 static void process_capabilities(int *len) 137 152 { ··· 224 239 */ 225 240 int responded = 0; 226 241 int len; 227 - int state = EXPECTING_FIRST_REF; 242 + int state = EXPECTING_PROTOCOL_VERSION; 228 243 229 244 *list = NULL; 230 245 231 246 while ((len = read_remote_ref(in, &src_buf, &src_len, &responded))) { 232 247 switch (state) { 248 + case EXPECTING_PROTOCOL_VERSION: 249 + if (process_protocol_version()) { 250 + state = EXPECTING_FIRST_REF; 251 + break; 252 + } 253 + state = EXPECTING_FIRST_REF; 254 + /* fallthrough */ 233 255 case EXPECTING_FIRST_REF: 234 256 process_capabilities(&len); 235 257 if (process_dummy_ref()) {