X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=connect.c;h=6bf737cbfa1c243b209d90b0198c5e6d37a503c2;hb=f6e1a4d6dc4d1b3d82d5e87fdd817b3994dda5e0;hp=f01b547574636d109f14c791287e6f4e52502de2;hpb=98e031f0bb6e857c684e6db24d03d22cfc1a532a;p=git.git diff --git a/connect.c b/connect.c index f01b5475..6bf737cb 100644 --- a/connect.c +++ b/connect.c @@ -7,6 +7,41 @@ #include #include +/* + * 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];