summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d089391)
raw | patch | inline | side by side (parent: d089391)
author | Linus Torvalds <torvalds@g5.osdl.org> | |
Sat, 16 Jul 2005 20:55:50 +0000 (13:55 -0700) | ||
committer | Linus Torvalds <torvalds@g5.osdl.org> | |
Sat, 16 Jul 2005 20:55:50 +0000 (13:55 -0700) |
It really just boils down to one "get_remote_heads()" function, and a
common "struct ref" structure definition.
common "struct ref" structure definition.
cache.h | patch | blob | history | |
clone-pack.c | patch | blob | history | |
connect.c | patch | blob | history | |
fetch-pack.c | patch | blob | history | |
send-pack.c | patch | blob | history |
index 73e05dcd8b1445e650f0628768242f10b8dabd24..150e144c5e12fc0a13e480958d91247a83d13f88 100644 (file)
--- a/cache.h
+++ b/cache.h
struct packed_git *p;
};
+struct ref {
+ struct ref *next;
+ unsigned char old_sha1[20];
+ unsigned char new_sha1[20];
+ char name[0];
+};
+
extern int git_connect(int fd[2], char *url, const char *prog);
extern int finish_connect(pid_t pid);
extern int path_match(const char *path, int nr, char **match);
extern int get_ack(int fd, unsigned char *result_sha1);
+extern struct ref **get_remote_heads(int in, struct ref **list, int nr_match, char **match);
extern void prepare_packed_git(void);
extern int use_packed_git(struct packed_git *);
diff --git a/clone-pack.c b/clone-pack.c
index 2aa522089e94f9c2e3b8887efb769f654a34ebde..e9c20dee71ac18cdc4ff06d78e5a9345a347914d 100644 (file)
--- a/clone-pack.c
+++ b/clone-pack.c
static const char clone_pack_usage[] = "git-clone-pack [-q] [--exec=<git-upload-pack>] [<host>:]<directory> [<heads>]*";
static const char *exec = "git-upload-pack";
-struct ref {
- struct ref *next;
- unsigned char sha1[20];
- char name[0];
-};
-
-static struct ref *get_remote_refs(int fd, int nr_match, char **match)
-{
- struct ref *ref_list = NULL, **next_ref = &ref_list;
-
- for (;;) {
- static char line[1000];
- unsigned char sha1[20];
- struct ref *ref;
- char *refname;
- int len;
-
- len = packet_read_line(fd, line, sizeof(line));
- if (!len)
- break;
- if (line[len-1] == '\n')
- line[--len] = 0;
- if (len < 42 || get_sha1_hex(line, sha1))
- die("git-clone-pack: protocol error - expected ref descriptor, got '%s'", line);
- refname = line+41;
- len = len-40;
- if (nr_match && !path_match(refname, nr_match, match))
- continue;
- ref = xmalloc(sizeof(struct ref) + len);
- ref->next = NULL;
- memcpy(ref->sha1, sha1, 20);
- memcpy(ref->name, refname, len);
- *next_ref = ref;
- next_ref = &ref->next;
- }
- return ref_list;
-}
-
static void clone_handshake(int fd[2], struct ref *ref)
{
unsigned char sha1[20];
while (ref) {
- packet_write(fd[1], "want %s\n", sha1_to_hex(ref->sha1));
+ packet_write(fd[1], "want %s\n", sha1_to_hex(ref->old_sha1));
ref = ref->next;
}
packet_flush(fd[1]);
fd = open(path, O_CREAT | O_EXCL | O_WRONLY, 0666);
if (fd < 0)
die("unable to create ref %s", ref->name);
- hex = sha1_to_hex(ref->sha1);
+ hex = sha1_to_hex(ref->old_sha1);
hex[40] = '\n';
if (write(fd, hex, 41) != 41)
die("unable to write ref %s", ref->name);
while (ref) {
if (is_master(ref))
master_ref = ref;
- if (head && !memcmp(ref->sha1, head->sha1, 20)) {
+ if (head && !memcmp(ref->old_sha1, head->old_sha1, 20)) {
if (!head_ptr || ref == master_ref)
head_ptr = ref;
}
int status;
pid_t pid;
- refs = get_remote_refs(fd[0], nr_match, match);
+ get_remote_heads(fd[0], &refs, nr_match, match);
if (!refs) {
packet_flush(fd[1]);
die("no matching remote head");
diff --git a/connect.c b/connect.c
index f01b547574636d109f14c791287e6f4e52502de2..6bf737cbfa1c243b209d90b0198c5e6d37a503c2 100644 (file)
--- a/connect.c
+++ b/connect.c
#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];
diff --git a/fetch-pack.c b/fetch-pack.c
index 9b1bc52244b390e3b046ae5e4b7889f8936a5510..65e007639ac744c3f354f71c157a85c5d6477d49 100644 (file)
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -53,44 +53,28 @@ static int find_common(int fd[2], unsigned char *result_sha1, unsigned char *rem
return retval;
}
-static int get_remote_heads(int fd, int nr_match, char **match, unsigned char *result)
-{
- int count = 0;
-
- for (;;) {
- static char line[1000];
- unsigned char sha1[20];
- char *refname;
- int len;
-
- len = packet_read_line(fd, line, sizeof(line));
- if (!len)
- break;
- if (line[len-1] == '\n')
- line[--len] = 0;
- if (len < 42 || get_sha1_hex(line, sha1))
- die("git-fetch-pack: protocol error - expected ref descriptor, got '%s'", line);
- refname = line+41;
- if (nr_match && !path_match(refname, nr_match, match))
- continue;
- count++;
- memcpy(result, sha1, 20);
- }
- return count;
-}
-
+/*
+ * Eventually we'll want to be able to fetch multiple heads.
+ *
+ * Right now we'll just require a single match.
+ */
static int fetch_pack(int fd[2], int nr_match, char **match)
{
- unsigned char sha1[20], remote[20];
- int heads, status;
+ struct ref *ref;
+ unsigned char sha1[20];
+ int status;
pid_t pid;
- heads = get_remote_heads(fd[0], nr_match, match, remote);
- if (heads != 1) {
+ get_remote_heads(fd[0], &ref, nr_match, match);
+ if (!ref) {
+ packet_flush(fd[1]);
+ die("no matching remote head");
+ }
+ if (ref->next) {
packet_flush(fd[1]);
- die(heads ? "multiple remote heads" : "no matching remote head");
+ die("multiple remote heads");
}
- if (find_common(fd, sha1, remote) < 0)
+ if (find_common(fd, sha1, ref->old_sha1) < 0)
die("git-fetch-pack: no common commits");
pid = fork();
if (pid < 0)
int code = WEXITSTATUS(status);
if (code)
die("git-unpack-objects died with error code %d", code);
- puts(sha1_to_hex(remote));
+ puts(sha1_to_hex(ref->old_sha1));
return 0;
}
if (WIFSIGNALED(status)) {
diff --git a/send-pack.c b/send-pack.c
index abc4d1f0007591d8e64792da9098c7042da3bbab..2994df401ab1b23674b1347cf6b3e5570dcffa21 100644 (file)
--- a/send-pack.c
+++ b/send-pack.c
static const char *exec = "git-receive-pack";
static int send_all = 0;
-struct ref {
- struct ref *next;
- unsigned char old_sha1[20];
- unsigned char new_sha1[20];
- char name[0];
-};
-
static int is_zero_sha1(const unsigned char *sha1)
{
int i;
static int send_pack(int in, int out, int nr_match, char **match)
{
- struct ref *ref_list = NULL, **last_ref = &ref_list;
+ struct ref *ref_list, **last_ref;
struct ref *ref;
int new_refs;
- /*
- * Read all the refs from the other end
- */
- for (;;) {
- 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;
- 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;
- *last_ref = ref;
- last_ref = &ref->next;
- }
+ /* First we get all heads, whether matching or not.. */
+ last_ref = get_remote_heads(in, &ref_list, 0, NULL);
/*
* Go through the refs, see if we want to update