[PATCH] Generic support for pulling refs
[git.git] / ssh-pull.c
bloba426342590c6782792d39b85f266be537d9def76
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 fetch_ref(char *ref, unsigned char *sha1)
44 return -1;
47 int main(int argc, char **argv)
49 char *commit_id;
50 char *url;
51 int arg = 1;
53 while (arg < argc && argv[arg][0] == '-') {
54 if (argv[arg][1] == 't') {
55 get_tree = 1;
56 } else if (argv[arg][1] == 'c') {
57 get_history = 1;
58 } else if (argv[arg][1] == 'd') {
59 get_delta = 0;
60 } else if (!strcmp(argv[arg], "--recover")) {
61 get_delta = 2;
62 } else if (argv[arg][1] == 'a') {
63 get_all = 1;
64 get_tree = 1;
65 get_history = 1;
66 } else if (argv[arg][1] == 'v') {
67 get_verbosely = 1;
69 arg++;
71 if (argc < arg + 2) {
72 usage("git-ssh-pull [-c] [-t] [-a] [-v] [-d] [--recover] commit-id url");
73 return 1;
75 commit_id = argv[arg];
76 url = argv[arg + 1];
78 if (setup_connection(&fd_in, &fd_out, "git-ssh-push", url, arg, argv + 1))
79 return 1;
81 if (get_version())
82 return 1;
84 if (pull(commit_id))
85 return 1;
87 return 0;