[PATCH] diff.c: locate_size_cache() fix.
[alt-git.git] / rpull.c
blobf4ab89836455a40aaab3ff4114396185f6d5655a
1 #include "cache.h"
2 #include "commit.h"
3 #include "rsh.h"
4 #include "pull.h"
6 static int fd_in;
7 static int fd_out;
9 static unsigned char remote_version = 0;
10 static unsigned char local_version = 1;
12 int fetch(unsigned char *sha1)
14 int ret;
15 signed char remote;
16 char type = 'o';
17 if (has_sha1_file(sha1))
18 return 0;
19 write(fd_out, &type, 1);
20 write(fd_out, sha1, 20);
21 if (read(fd_in, &remote, 1) < 1)
22 return -1;
23 if (remote < 0)
24 return remote;
25 ret = write_sha1_from_fd(sha1, fd_in);
26 if (!ret)
27 pull_say("got %s\n", sha1_to_hex(sha1));
28 return ret;
31 int get_version(void)
33 char type = 'v';
34 write(fd_out, &type, 1);
35 write(fd_out, &local_version, 1);
36 if (read(fd_in, &remote_version, 1) < 1) {
37 return error("Couldn't read version from remote end");
39 return 0;
42 int main(int argc, char **argv)
44 char *commit_id;
45 char *url;
46 int arg = 1;
48 while (arg < argc && argv[arg][0] == '-') {
49 if (argv[arg][1] == 't') {
50 get_tree = 1;
51 } else if (argv[arg][1] == 'c') {
52 get_history = 1;
53 } else if (argv[arg][1] == 'd') {
54 get_delta = 0;
55 } else if (argv[arg][1] == 'a') {
56 get_all = 1;
57 get_tree = 1;
58 get_history = 1;
59 } else if (argv[arg][1] == 'v') {
60 get_verbosely = 1;
62 arg++;
64 if (argc < arg + 2) {
65 usage("git-rpull [-c] [-t] [-a] [-v] [-d] commit-id url");
66 return 1;
68 commit_id = argv[arg];
69 url = argv[arg + 1];
71 if (setup_connection(&fd_in, &fd_out, "git-rpush", url, arg, argv + 1))
72 return 1;
74 if (get_version())
75 return 1;
77 if (pull(commit_id))
78 return 1;
80 return 0;