aboutsummaryrefslogtreecommitdiff
path: root/connect.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@g5.osdl.org>2005-07-16 13:55:50 -0700
committerLinus Torvalds <torvalds@g5.osdl.org>2005-07-16 13:55:50 -0700
commitd1c133f5d48a45ad8ba29c4cb2c2a824f4f600fa (patch)
treef0d17f0d1dd6c7c194ecb32a27f36aea1546ce1f /connect.c
parentd089391c0058f500768bb68f3bee7af78975de58 (diff)
downloadgit-d1c133f5d48a45ad8ba29c4cb2c2a824f4f600fa.tar.gz
git-d1c133f5d48a45ad8ba29c4cb2c2a824f4f600fa.tar.xz
Merge three separate "fetch refs" functions
It really just boils down to one "get_remote_heads()" function, and a common "struct ref" structure definition.
Diffstat (limited to 'connect.c')
-rw-r--r--connect.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/connect.c b/connect.c
index f01b54757..6bf737cbf 100644
--- a/connect.c
+++ b/connect.c
@@ -7,6 +7,41 @@
#include <arpa/inet.h>
#include <netdb.h>
+/*
+ * Read all the refs from the other end
+ */
+struct ref **get_remote_heads(int in, struct ref **list, int nr_match, char **match)
+{
+ *list = NULL;
+ for (;;) {
+ struct ref *ref;
+ unsigned char old_sha1[20];
+ static char buffer[1000];
+ char *name;
+ int len;
+
+ len = packet_read_line(in, buffer, sizeof(buffer));
+ if (!len)
+ break;
+ if (buffer[len-1] == '\n')
+ buffer[--len] = 0;
+
+ if (len < 42 || get_sha1_hex(buffer, old_sha1) || buffer[40] != ' ')
+ die("protocol error: expected sha/ref, got '%s'", buffer);
+ name = buffer + 41;
+ if (nr_match && !path_match(name, nr_match, match))
+ continue;
+ ref = xmalloc(sizeof(*ref) + len - 40);
+ memcpy(ref->old_sha1, old_sha1, 20);
+ memset(ref->new_sha1, 0, 20);
+ memcpy(ref->name, buffer + 41, len - 40);
+ ref->next = NULL;
+ *list = ref;
+ list = &ref->next;
+ }
+ return list;
+}
+
int get_ack(int fd, unsigned char *result_sha1)
{
static char line[1000];