[PATCH] Parallelize the pull algorithm
[alt-git.git] / ssh-pull.c
blob4cf9b6a1677542c74c99e88281417e3cc0d52bb1
1 #include "cache.h"
2 #include "commit.h"
3 #include "rsh.h"
4 #include "pull.h"
5 #include "refs.h"
7 static int fd_in;
8 static int fd_out;
10 static unsigned char remote_version = 0;
11 static unsigned char local_version = 1;
13 void prefetch(unsigned char *sha1)
17 int fetch(unsigned char *sha1)
19 int ret;
20 signed char remote;
21 char type = 'o';
22 if (has_sha1_file(sha1))
23 return 0;
24 write(fd_out, &type, 1);
25 write(fd_out, sha1, 20);
26 if (read(fd_in, &remote, 1) < 1)
27 return -1;
28 if (remote < 0)
29 return remote;
30 ret = write_sha1_from_fd(sha1, fd_in);
31 if (!ret)
32 pull_say("got %s\n", sha1_to_hex(sha1));
33 return ret;
36 static int get_version(void)
38 char type = 'v';
39 write(fd_out, &type, 1);
40 write(fd_out, &local_version, 1);
41 if (read(fd_in, &remote_version, 1) < 1) {
42 return error("Couldn't read version from remote end");
44 return 0;
47 int fetch_ref(char *ref, unsigned char *sha1)
49 signed char remote;
50 char type = 'r';
51 write(fd_out, &type, 1);
52 write(fd_out, ref, strlen(ref) + 1);
53 read(fd_in, &remote, 1);
54 if (remote < 0)
55 return remote;
56 read(fd_in, sha1, 20);
57 return 0;
60 int main(int argc, char **argv)
62 char *commit_id;
63 char *url;
64 int arg = 1;
65 const char *prog = getenv("GIT_SSH_PUSH") ? : "git-ssh-push";
67 while (arg < argc && argv[arg][0] == '-') {
68 if (argv[arg][1] == 't') {
69 get_tree = 1;
70 } else if (argv[arg][1] == 'c') {
71 get_history = 1;
72 } else if (argv[arg][1] == 'a') {
73 get_all = 1;
74 get_tree = 1;
75 get_history = 1;
76 } else if (argv[arg][1] == 'v') {
77 get_verbosely = 1;
78 } else if (argv[arg][1] == 'w') {
79 write_ref = argv[arg + 1];
80 arg++;
82 arg++;
84 if (argc < arg + 2) {
85 usage("git-ssh-pull [-c] [-t] [-a] [-v] [-d] [--recover] [-w ref] commit-id url");
86 return 1;
88 commit_id = argv[arg];
89 url = argv[arg + 1];
91 if (setup_connection(&fd_in, &fd_out, prog, url, arg, argv + 1))
92 return 1;
94 if (get_version())
95 return 1;
97 if (pull(commit_id))
98 return 1;
100 return 0;