Skip to content

Commit 2609043

Browse files
bmwillgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aa9bab2 commit 2609043

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

connect.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "sha1-array.h"
1313
#include "transport.h"
1414
#include "strbuf.h"
15+
#include "protocol.h"
1516

1617
static char *server_capabilities;
1718
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,
129130
return len;
130131
}
131132

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+
}
135150

136151
static void process_capabilities(int *len)
137152
{
@@ -224,12 +239,19 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
224239
*/
225240
int responded = 0;
226241
int len;
227-
int state = EXPECTING_FIRST_REF;
242+
int state = EXPECTING_PROTOCOL_VERSION;
228243

229244
*list = NULL;
230245

231246
while ((len = read_remote_ref(in, &src_buf, &src_len, &responded))) {
232247
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 */
233255
case EXPECTING_FIRST_REF:
234256
process_capabilities(&len);
235257
if (process_dummy_ref()) {

0 commit comments

Comments
 (0)