10 static unsigned char remote_version = 0;
11 static unsigned char local_version = 1;
13 static ssize_t force_write(int fd, void *buffer, size_t length)
16 while (ret < length) {
17 ssize_t size = write(fd, buffer + ret, length - ret);
29 void prefetch(unsigned char *sha1)
32 force_write(fd_out, &type, 1);
33 force_write(fd_out, sha1, 20);
34 //memcpy(requested + 20 * prefetches++, sha1, 20);
37 static char conn_buf[4096];
38 static size_t conn_buf_posn = 0;
40 int fetch(unsigned char *sha1)
47 memmove(conn_buf, conn_buf + 1, --conn_buf_posn);
49 if (read(fd_in, &remote, 1) < 1)
52 //fprintf(stderr, "Got %d\n", remote);
55 ret = write_sha1_from_fd(sha1, fd_in, conn_buf, 4096, &conn_buf_posn);
57 pull_say("got %s\n", sha1_to_hex(sha1));
61 static int get_version(void)
64 write(fd_out, &type, 1);
65 write(fd_out, &local_version, 1);
66 if (read(fd_in, &remote_version, 1) < 1) {
67 return error("Couldn't read version from remote end");
72 int fetch_ref(char *ref, unsigned char *sha1)
76 write(fd_out, &type, 1);
77 write(fd_out, ref, strlen(ref) + 1);
78 read(fd_in, &remote, 1);
81 read(fd_in, sha1, 20);
85 int main(int argc, char **argv)
90 const char *prog = getenv("GIT_SSH_PUSH") ? : "git-ssh-push";
92 while (arg < argc && argv[arg][0] == '-') {
93 if (argv[arg][1] == 't') {
95 } else if (argv[arg][1] == 'c') {
97 } else if (argv[arg][1] == 'a') {
101 } else if (argv[arg][1] == 'v') {
103 } else if (argv[arg][1] == 'w') {
104 write_ref = argv[arg + 1];
109 if (argc < arg + 2) {
110 usage("git-ssh-pull [-c] [-t] [-a] [-v] [-d] [--recover] [-w ref] commit-id url");
113 commit_id = argv[arg];
116 if (setup_connection(&fd_in, &fd_out, prog, url, arg, argv + 1))