|
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,9 +130,23 @@ static int read_remote_ref(int in, char **src_buf, size_t *src_len,
|
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,12 +239,19 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
|
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()) {
|
|
0 commit comments