Daniel Barkalow | 6eb7ed5 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 1 | #include "cache.h" |
| 2 | #include "commit.h" |
Daniel Barkalow | 6eb7ed5 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 3 | #include "rsh.h" |
Daniel Barkalow | 4250a5e | 2005-04-30 16:53:56 -0700 | [diff] [blame] | 4 | #include "pull.h" |
Daniel Barkalow | 6eb7ed5 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 5 | |
| 6 | static int fd_in; |
| 7 | static int fd_out; |
| 8 | |
Daniel Barkalow | dba385b | 2005-06-03 17:43:52 -0400 | [diff] [blame] | 9 | static unsigned char remote_version = 0; |
| 10 | static unsigned char local_version = 1; |
| 11 | |
Daniel Barkalow | 4250a5e | 2005-04-30 16:53:56 -0700 | [diff] [blame] | 12 | int fetch(unsigned char *sha1) |
Daniel Barkalow | 6eb7ed5 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 13 | { |
Junio C Hamano | e78d977 | 2005-05-06 01:37:21 -0700 | [diff] [blame] | 14 | int ret; |
Daniel Barkalow | dba385b | 2005-06-03 17:43:52 -0400 | [diff] [blame] | 15 | signed char remote; |
| 16 | char type = 'o'; |
| 17 | if (has_sha1_file(sha1)) |
| 18 | return 0; |
| 19 | write(fd_out, &type, 1); |
Daniel Barkalow | 6eb7ed5 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 20 | write(fd_out, sha1, 20); |
Daniel Barkalow | dba385b | 2005-06-03 17:43:52 -0400 | [diff] [blame] | 21 | if (read(fd_in, &remote, 1) < 1) |
| 22 | return -1; |
| 23 | if (remote < 0) |
| 24 | return remote; |
Junio C Hamano | e78d977 | 2005-05-06 01:37:21 -0700 | [diff] [blame] | 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; |
Daniel Barkalow | 6eb7ed5 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 29 | } |
| 30 | |
Daniel Barkalow | dba385b | 2005-06-03 17:43:52 -0400 | [diff] [blame] | 31 | int get_version(void) |
| 32 | { |
| 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"); |
| 38 | } |
| 39 | return 0; |
| 40 | } |
| 41 | |
Daniel Barkalow | cd541a6 | 2005-06-06 16:38:26 -0400 | [diff] [blame^] | 42 | int fetch_ref(char *ref, unsigned char *sha1) |
| 43 | { |
| 44 | return -1; |
| 45 | } |
| 46 | |
Daniel Barkalow | 6eb7ed5 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 47 | int main(int argc, char **argv) |
| 48 | { |
| 49 | char *commit_id; |
| 50 | char *url; |
| 51 | int arg = 1; |
Daniel Barkalow | 6eb7ed5 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 52 | |
| 53 | while (arg < argc && argv[arg][0] == '-') { |
| 54 | if (argv[arg][1] == 't') { |
Daniel Barkalow | 4250a5e | 2005-04-30 16:53:56 -0700 | [diff] [blame] | 55 | get_tree = 1; |
Daniel Barkalow | 6eb7ed5 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 56 | } else if (argv[arg][1] == 'c') { |
Daniel Barkalow | 4250a5e | 2005-04-30 16:53:56 -0700 | [diff] [blame] | 57 | get_history = 1; |
Junio C Hamano | 4a62b61 | 2005-06-02 15:19:00 -0700 | [diff] [blame] | 58 | } else if (argv[arg][1] == 'd') { |
| 59 | get_delta = 0; |
Junio C Hamano | a48e1d6 | 2005-06-04 23:11:38 -0700 | [diff] [blame] | 60 | } else if (!strcmp(argv[arg], "--recover")) { |
| 61 | get_delta = 2; |
Daniel Barkalow | 6eb7ed5 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 62 | } else if (argv[arg][1] == 'a') { |
Daniel Barkalow | 4250a5e | 2005-04-30 16:53:56 -0700 | [diff] [blame] | 63 | get_all = 1; |
| 64 | get_tree = 1; |
| 65 | get_history = 1; |
Junio C Hamano | e78d977 | 2005-05-06 01:37:21 -0700 | [diff] [blame] | 66 | } else if (argv[arg][1] == 'v') { |
| 67 | get_verbosely = 1; |
Daniel Barkalow | 6eb7ed5 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 68 | } |
| 69 | arg++; |
| 70 | } |
| 71 | if (argc < arg + 2) { |
Junio C Hamano | 418aaf8 | 2005-06-05 15:41:05 -0700 | [diff] [blame] | 72 | usage("git-ssh-pull [-c] [-t] [-a] [-v] [-d] [--recover] commit-id url"); |
Daniel Barkalow | 6eb7ed5 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 73 | return 1; |
| 74 | } |
| 75 | commit_id = argv[arg]; |
| 76 | url = argv[arg + 1]; |
| 77 | |
Junio C Hamano | 418aaf8 | 2005-06-05 15:41:05 -0700 | [diff] [blame] | 78 | if (setup_connection(&fd_in, &fd_out, "git-ssh-push", url, arg, argv + 1)) |
Daniel Barkalow | 6eb7ed5 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 79 | return 1; |
| 80 | |
Daniel Barkalow | dba385b | 2005-06-03 17:43:52 -0400 | [diff] [blame] | 81 | if (get_version()) |
| 82 | return 1; |
| 83 | |
Daniel Barkalow | 4250a5e | 2005-04-30 16:53:56 -0700 | [diff] [blame] | 84 | if (pull(commit_id)) |
Daniel Barkalow | 6eb7ed5 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 85 | return 1; |
| 86 | |
| 87 | return 0; |
| 88 | } |