1#include "cache.h"
2#include "commit.h"
3#include "rsh.h"
4#include "pull.h"
5#include "refs.h"
67
static int fd_in;
8static int fd_out;
910
static unsigned char remote_version = 0;
11static unsigned char local_version = 1;
1213
int fetch(unsigned char *sha1)
14{
15int ret;
16signed char remote;
17char type = 'o';
18if (has_sha1_file(sha1))
19return 0;
20write(fd_out, &type, 1);
21write(fd_out, sha1, 20);
22if (read(fd_in, &remote, 1) < 1)
23return -1;
24if (remote < 0)
25return remote;
26ret = write_sha1_from_fd(sha1, fd_in);
27if (!ret)
28pull_say("got %s\n", sha1_to_hex(sha1));
29return ret;
30}
3132
int get_version(void)
33{
34char type = 'v';
35write(fd_out, &type, 1);
36write(fd_out, &local_version, 1);
37if (read(fd_in, &remote_version, 1) < 1) {
38return error("Couldn't read version from remote end");
39}
40return 0;
41}
4243
int fetch_ref(char *ref, unsigned char *sha1)
44{
45signed char remote;
46char type = 'r';
47write(fd_out, &type, 1);
48write(fd_out, ref, strlen(ref) + 1);
49read(fd_in, &remote, 1);
50if (remote < 0)
51return remote;
52read(fd_in, sha1, 20);
53return 0;
54}
5556
int main(int argc, char **argv)
57{
58char *commit_id;
59char *url;
60int arg = 1;
6162
while (arg < argc && argv[arg][0] == '-') {
63if (argv[arg][1] == 't') {
64get_tree = 1;
65} else if (argv[arg][1] == 'c') {
66get_history = 1;
67} else if (argv[arg][1] == 'd') {
68get_delta = 0;
69} else if (!strcmp(argv[arg], "--recover")) {
70get_delta = 2;
71} else if (argv[arg][1] == 'a') {
72get_all = 1;
73get_tree = 1;
74get_history = 1;
75} else if (argv[arg][1] == 'v') {
76get_verbosely = 1;
77} else if (argv[arg][1] == 'w') {
78write_ref = argv[arg + 1];
79arg++;
80}
81arg++;
82}
83if (argc < arg + 2) {
84usage("git-ssh-pull [-c] [-t] [-a] [-v] [-d] [--recover] [-w ref] commit-id url");
85return 1;
86}
87commit_id = argv[arg];
88url = argv[arg + 1];
8990
if (setup_connection(&fd_in, &fd_out, "git-ssh-push", url, arg, argv + 1))
91return 1;
9293
if (get_version())
94return 1;
9596
if (pull(commit_id))
97return 1;
9899
return 0;
100}