]> git.ipfire.org Git - thirdparty/git.git/blame - ssh-pull.c
[PATCH] Use ntohs instead of htons to convert ce_flags to host byte order
[thirdparty/git.git] / ssh-pull.c
CommitLineData
6eb7ed54
DB
1#include "cache.h"
2#include "commit.h"
6eb7ed54 3#include "rsh.h"
4250a5e5 4#include "pull.h"
c7c4bbe6 5#include "refs.h"
6eb7ed54
DB
6
7static int fd_in;
8static int fd_out;
9
dba385bb
DB
10static unsigned char remote_version = 0;
11static unsigned char local_version = 1;
12
4250a5e5 13int fetch(unsigned char *sha1)
6eb7ed54 14{
e78d9772 15 int ret;
dba385bb
DB
16 signed char remote;
17 char type = 'o';
18 if (has_sha1_file(sha1))
19 return 0;
20 write(fd_out, &type, 1);
6eb7ed54 21 write(fd_out, sha1, 20);
dba385bb
DB
22 if (read(fd_in, &remote, 1) < 1)
23 return -1;
24 if (remote < 0)
25 return remote;
e78d9772
JH
26 ret = write_sha1_from_fd(sha1, fd_in);
27 if (!ret)
28 pull_say("got %s\n", sha1_to_hex(sha1));
29 return ret;
6eb7ed54
DB
30}
31
dba385bb
DB
32int get_version(void)
33{
34 char type = 'v';
35 write(fd_out, &type, 1);
36 write(fd_out, &local_version, 1);
37 if (read(fd_in, &remote_version, 1) < 1) {
38 return error("Couldn't read version from remote end");
39 }
40 return 0;
41}
42
cd541a68
DB
43int fetch_ref(char *ref, unsigned char *sha1)
44{
c7c4bbe6
DB
45 signed char remote;
46 char type = 'r';
47 write(fd_out, &type, 1);
48 write(fd_out, ref, strlen(ref) + 1);
49 read(fd_in, &remote, 1);
50 if (remote < 0)
51 return remote;
52 read(fd_in, sha1, 20);
53 return 0;
cd541a68
DB
54}
55
6eb7ed54
DB
56int main(int argc, char **argv)
57{
58 char *commit_id;
59 char *url;
60 int arg = 1;
6eb7ed54
DB
61
62 while (arg < argc && argv[arg][0] == '-') {
63 if (argv[arg][1] == 't') {
4250a5e5 64 get_tree = 1;
6eb7ed54 65 } else if (argv[arg][1] == 'c') {
4250a5e5 66 get_history = 1;
4a62b619
JH
67 } else if (argv[arg][1] == 'd') {
68 get_delta = 0;
a48e1d67
JH
69 } else if (!strcmp(argv[arg], "--recover")) {
70 get_delta = 2;
6eb7ed54 71 } else if (argv[arg][1] == 'a') {
4250a5e5
DB
72 get_all = 1;
73 get_tree = 1;
74 get_history = 1;
e78d9772
JH
75 } else if (argv[arg][1] == 'v') {
76 get_verbosely = 1;
c7c4bbe6
DB
77 } else if (argv[arg][1] == 'w') {
78 write_ref = argv[arg + 1];
79 arg++;
6eb7ed54
DB
80 }
81 arg++;
82 }
83 if (argc < arg + 2) {
c7c4bbe6 84 usage("git-ssh-pull [-c] [-t] [-a] [-v] [-d] [--recover] [-w ref] commit-id url");
6eb7ed54
DB
85 return 1;
86 }
87 commit_id = argv[arg];
88 url = argv[arg + 1];
89
418aaf84 90 if (setup_connection(&fd_in, &fd_out, "git-ssh-push", url, arg, argv + 1))
6eb7ed54
DB
91 return 1;
92
dba385bb
DB
93 if (get_version())
94 return 1;
95
4250a5e5 96 if (pull(commit_id))
6eb7ed54
DB
97 return 1;
98
99 return 0;
100}