[PATCH] Documentation: describe git extended diff headers.
[alt-git.git] / rpull.c
bloba332fba23b0eb535ffacbdd68da80e1eebb62824
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 (!strcmp(argv[arg], "--recover")) {
56 get_delta = 2;
57 } else if (argv[arg][1] == 'a') {
58 get_all = 1;
59 get_tree = 1;
60 get_history = 1;
61 } else if (argv[arg][1] == 'v') {
62 get_verbosely = 1;
64 arg++;
66 if (argc < arg + 2) {
67 usage("git-rpull [-c] [-t] [-a] [-v] [-d] [--recover] commit-id url");
68 return 1;
70 commit_id = argv[arg];
71 url = argv[arg + 1];
73 if (setup_connection(&fd_in, &fd_out, "git-rpush", url, arg, argv + 1))
74 return 1;
76 if (get_version())
77 return 1;
79 if (pull(commit_id))
80 return 1;
82 return 0;