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>
Brandon Williams committed
Oct 16, 2017 at 10:55 UTC
2609043da00ea0db411c44179136b07bf210bf75
1 file changed
+26
-4
connect.c
+26
-4
@@ -12,6 +12,7 @@
12
#include "sha1-array.h"
13
#include "transport.h"
14
#include "strbuf.h"
15
+#include "protocol.h"
16
17
static char *server_capabilities;
18
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,
130
return len;
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
+}
150
151
static void process_capabilities(int *len)
152
{
@@ -224,12 +239,19 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
239
*/
240
int responded = 0;
241
int len;
227
- int state = EXPECTING_FIRST_REF;
242
+ int state = EXPECTING_PROTOCOL_VERSION;
243
244
*list = NULL;
245
246
while ((len = read_remote_ref(in, &src_buf, &src_len, &responded))) {
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 */
255
case EXPECTING_FIRST_REF:
256
process_capabilities(&len);
257
if (process_dummy_ref()) {