Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon Williams <bmwill@google.com>2018-03-14 21:31:45 +0300
committerJunio C Hamano <gitster@pobox.com>2018-03-15 00:15:06 +0300
commitad6ac1244fd175d08bcee62060a9a0b7975930fb (patch)
tree01a554d284a1f0b8bbba8733e053f43d7739416b /connect.c
parent7e3e479b90fd618fb8eb8222738f7cc53ab288fa (diff)
connect: discover protocol version outside of get_remote_heads
In order to prepare for the addition of protocol_v2 push the protocol version discovery outside of 'get_remote_heads()'. This will allow for keeping the logic for processing the reference advertisement for protocol_v1 and protocol_v0 separate from the logic for protocol_v2. 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.c27
1 files changed, 10 insertions, 17 deletions
diff --git a/connect.c b/connect.c
index c82c90b7c3..0b111e62d7 100644
--- a/connect.c
+++ b/connect.c
@@ -62,7 +62,7 @@ static void die_initial_contact(int unexpected)
"and the repository exists."));
}
-static enum protocol_version discover_version(struct packet_reader *reader)
+enum protocol_version discover_version(struct packet_reader *reader)
{
enum protocol_version version = protocol_unknown_version;
@@ -233,7 +233,7 @@ enum get_remote_heads_state {
/*
* Read all the refs from the other end
*/
-struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
+struct ref **get_remote_heads(struct packet_reader *reader,
struct ref **list, unsigned int flags,
struct oid_array *extra_have,
struct oid_array *shallow_points)
@@ -241,24 +241,17 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
struct ref **orig_list = list;
int len = 0;
enum get_remote_heads_state state = EXPECTING_FIRST_REF;
- struct packet_reader reader;
const char *arg;
- packet_reader_init(&reader, in, src_buf, src_len,
- PACKET_READ_CHOMP_NEWLINE |
- PACKET_READ_GENTLE_ON_EOF);
-
- discover_version(&reader);
-
*list = NULL;
while (state != EXPECTING_DONE) {
- switch (packet_reader_read(&reader)) {
+ switch (packet_reader_read(reader)) {
case PACKET_READ_EOF:
die_initial_contact(1);
case PACKET_READ_NORMAL:
- len = reader.pktlen;
- if (len > 4 && skip_prefix(reader.line, "ERR ", &arg))
+ len = reader->pktlen;
+ if (len > 4 && skip_prefix(reader->line, "ERR ", &arg))
die("remote error: %s", arg);
break;
case PACKET_READ_FLUSH:
@@ -270,22 +263,22 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
switch (state) {
case EXPECTING_FIRST_REF:
- process_capabilities(reader.line, &len);
- if (process_dummy_ref(reader.line)) {
+ process_capabilities(reader->line, &len);
+ if (process_dummy_ref(reader->line)) {
state = EXPECTING_SHALLOW;
break;
}
state = EXPECTING_REF;
/* fallthrough */
case EXPECTING_REF:
- if (process_ref(reader.line, len, &list, flags, extra_have))
+ if (process_ref(reader->line, len, &list, flags, extra_have))
break;
state = EXPECTING_SHALLOW;
/* fallthrough */
case EXPECTING_SHALLOW:
- if (process_shallow(reader.line, len, shallow_points))
+ if (process_shallow(reader->line, len, shallow_points))
break;
- die("protocol error: unexpected '%s'", reader.line);
+ die("protocol error: unexpected '%s'", reader->line);
case EXPECTING_DONE:
break;
}