1 #ifndef COUNTERPART_ENV_NAME
2 #define COUNTERPART_ENV_NAME "GIT_SSH_UPLOAD"
4 #ifndef COUNTERPART_PROGRAM_NAME
5 #define COUNTERPART_PROGRAM_NAME "git-ssh-upload"
7 #ifndef MY_PROGRAM_NAME
8 #define MY_PROGRAM_NAME "git-ssh-fetch"
20 static unsigned char remote_version = 0;
21 static unsigned char local_version = 1;
23 static ssize_t force_write(int fd, void *buffer, size_t length)
26 while (ret < length) {
27 ssize_t size = write(fd, buffer + ret, length - ret);
39 void prefetch(unsigned char *sha1)
42 force_write(fd_out, &type, 1);
43 force_write(fd_out, sha1, 20);
44 //memcpy(requested + 20 * prefetches++, sha1, 20);
47 static char conn_buf[4096];
48 static size_t conn_buf_posn = 0;
50 int fetch(unsigned char *sha1)
57 memmove(conn_buf, conn_buf + 1, --conn_buf_posn);
59 if (read(fd_in, &remote, 1) < 1)
62 //fprintf(stderr, "Got %d\n", remote);
65 ret = write_sha1_from_fd(sha1, fd_in, conn_buf, 4096, &conn_buf_posn);
67 pull_say("got %s\n", sha1_to_hex(sha1));
71 static int get_version(void)
74 write(fd_out, &type, 1);
75 write(fd_out, &local_version, 1);
76 if (read(fd_in, &remote_version, 1) < 1) {
77 return error("Couldn't read version from remote end");
82 int fetch_ref(char *ref, unsigned char *sha1)
86 write(fd_out, &type, 1);
87 write(fd_out, ref, strlen(ref) + 1);
88 read(fd_in, &remote, 1);
91 read(fd_in, sha1, 20);
95 static const char ssh_fetch_usage[] =
97 " [-c] [-t] [-a] [-v] [-d] [--recover] [-w ref] commit-id url";
98 int main(int argc, char **argv)
105 prog = getenv("GIT_SSH_PUSH");
106 if (!prog) prog = "git-ssh-upload";
108 while (arg < argc && argv[arg][0] == '-') {
109 if (argv[arg][1] == 't') {
111 } else if (argv[arg][1] == 'c') {
113 } else if (argv[arg][1] == 'a') {
117 } else if (argv[arg][1] == 'v') {
119 } else if (argv[arg][1] == 'w') {
120 write_ref = argv[arg + 1];
125 if (argc < arg + 2) {
126 usage(ssh_fetch_usage);
129 commit_id = argv[arg];
132 if (setup_connection(&fd_in, &fd_out, prog, url, arg, argv + 1))