Daniel Barkalow | 30ae764 | 2007-09-10 23:02:45 -0400 | [diff] [blame] | 1 | #include "cache.h" |
Jonathan Nieder | f01d749 | 2009-11-09 09:05:00 -0600 | [diff] [blame] | 2 | #include "exec_cmd.h" |
Tay Ray Chuan | 888692b | 2010-03-02 18:49:29 +0800 | [diff] [blame] | 3 | #include "http.h" |
Daniel Barkalow | 30ae764 | 2007-09-10 23:02:45 -0400 | [diff] [blame] | 4 | #include "walker.h" |
| 5 | |
Jonathan Nieder | 616f86d | 2009-11-09 09:04:59 -0600 | [diff] [blame] | 6 | static const char http_fetch_usage[] = "git http-fetch " |
| 7 | "[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url"; |
| 8 | |
Linus Torvalds | 1088261 | 2009-08-05 01:01:59 -0400 | [diff] [blame] | 9 | int main(int argc, const char **argv) |
Daniel Barkalow | 30ae764 | 2007-09-10 23:02:45 -0400 | [diff] [blame] | 10 | { |
| 11 | struct walker *walker; |
| 12 | int commits_on_stdin = 0; |
| 13 | int commits; |
| 14 | const char **write_ref = NULL; |
| 15 | char **commit_id; |
Tay Ray Chuan | 6f5185b | 2010-11-25 16:21:10 +0800 | [diff] [blame] | 16 | char *url = NULL; |
Daniel Barkalow | 30ae764 | 2007-09-10 23:02:45 -0400 | [diff] [blame] | 17 | int arg = 1; |
| 18 | int rc = 0; |
| 19 | int get_tree = 0; |
| 20 | int get_history = 0; |
| 21 | int get_all = 0; |
| 22 | int get_verbosely = 0; |
| 23 | int get_recover = 0; |
| 24 | |
Ævar Arnfjörð Bjarmason | 5e9637c | 2011-11-18 00:14:42 +0100 | [diff] [blame] | 25 | git_setup_gettext(); |
| 26 | |
Jonathan Nieder | f01d749 | 2009-11-09 09:05:00 -0600 | [diff] [blame] | 27 | git_extract_argv0_path(argv[0]); |
Daniel Barkalow | 30ae764 | 2007-09-10 23:02:45 -0400 | [diff] [blame] | 28 | |
| 29 | while (arg < argc && argv[arg][0] == '-') { |
| 30 | if (argv[arg][1] == 't') { |
| 31 | get_tree = 1; |
| 32 | } else if (argv[arg][1] == 'c') { |
| 33 | get_history = 1; |
| 34 | } else if (argv[arg][1] == 'a') { |
| 35 | get_all = 1; |
| 36 | get_tree = 1; |
| 37 | get_history = 1; |
| 38 | } else if (argv[arg][1] == 'v') { |
| 39 | get_verbosely = 1; |
| 40 | } else if (argv[arg][1] == 'w') { |
| 41 | write_ref = &argv[arg + 1]; |
| 42 | arg++; |
Jonathan Nieder | 616f86d | 2009-11-09 09:04:59 -0600 | [diff] [blame] | 43 | } else if (argv[arg][1] == 'h') { |
| 44 | usage(http_fetch_usage); |
Daniel Barkalow | 30ae764 | 2007-09-10 23:02:45 -0400 | [diff] [blame] | 45 | } else if (!strcmp(argv[arg], "--recover")) { |
| 46 | get_recover = 1; |
| 47 | } else if (!strcmp(argv[arg], "--stdin")) { |
| 48 | commits_on_stdin = 1; |
| 49 | } |
| 50 | arg++; |
| 51 | } |
Jonathan Nieder | 616f86d | 2009-11-09 09:04:59 -0600 | [diff] [blame] | 52 | if (argc != arg + 2 - commits_on_stdin) |
| 53 | usage(http_fetch_usage); |
Daniel Barkalow | 30ae764 | 2007-09-10 23:02:45 -0400 | [diff] [blame] | 54 | if (commits_on_stdin) { |
| 55 | commits = walker_targets_stdin(&commit_id, &write_ref); |
| 56 | } else { |
| 57 | commit_id = (char **) &argv[arg++]; |
| 58 | commits = 1; |
| 59 | } |
Tay Ray Chuan | 6f5185b | 2010-11-25 16:21:10 +0800 | [diff] [blame] | 60 | |
Ben Walton | a6c786f | 2011-08-23 20:29:51 -0400 | [diff] [blame] | 61 | if (get_all == 0) |
| 62 | warning("http-fetch: use without -a is deprecated.\n" |
| 63 | "In a future release, -a will become the default."); |
| 64 | |
Tay Ray Chuan | 6f5185b | 2010-11-25 16:21:10 +0800 | [diff] [blame] | 65 | if (argv[arg]) |
| 66 | str_end_url_with_slash(argv[arg], &url); |
Jonathan Nieder | 616f86d | 2009-11-09 09:04:59 -0600 | [diff] [blame] | 67 | |
Dan McGee | 13ee138 | 2011-03-27 20:32:19 -0500 | [diff] [blame] | 68 | setup_git_directory(); |
Jonathan Nieder | 616f86d | 2009-11-09 09:04:59 -0600 | [diff] [blame] | 69 | |
| 70 | git_config(git_default_config, NULL); |
| 71 | |
Jeff King | a4ddbc3 | 2011-12-13 19:11:56 -0500 | [diff] [blame] | 72 | http_init(NULL, url, 0); |
Tay Ray Chuan | 888692b | 2010-03-02 18:49:29 +0800 | [diff] [blame] | 73 | walker = get_http_walker(url); |
Daniel Barkalow | 30ae764 | 2007-09-10 23:02:45 -0400 | [diff] [blame] | 74 | walker->get_tree = get_tree; |
| 75 | walker->get_history = get_history; |
| 76 | walker->get_all = get_all; |
| 77 | walker->get_verbosely = get_verbosely; |
| 78 | walker->get_recover = get_recover; |
| 79 | |
| 80 | rc = walker_fetch(walker, commits, commit_id, write_ref, url); |
| 81 | |
| 82 | if (commits_on_stdin) |
| 83 | walker_targets_free(commits, commit_id, write_ref); |
| 84 | |
| 85 | if (walker->corrupt_object_found) { |
| 86 | fprintf(stderr, |
| 87 | "Some loose object were found to be corrupt, but they might be just\n" |
| 88 | "a false '404 Not Found' error message sent with incorrect HTTP\n" |
Heikki Orsila | 05207a2 | 2008-09-09 13:28:30 +0300 | [diff] [blame] | 89 | "status code. Suggest running 'git fsck'.\n"); |
Daniel Barkalow | 30ae764 | 2007-09-10 23:02:45 -0400 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | walker_free(walker); |
Tay Ray Chuan | 888692b | 2010-03-02 18:49:29 +0800 | [diff] [blame] | 93 | http_cleanup(); |
Daniel Barkalow | 30ae764 | 2007-09-10 23:02:45 -0400 | [diff] [blame] | 94 | |
Tay Ray Chuan | 6f5185b | 2010-11-25 16:21:10 +0800 | [diff] [blame] | 95 | free(url); |
Grégoire Barbier | 3057ded | 2008-01-19 16:22:50 +0100 | [diff] [blame] | 96 | |
Daniel Barkalow | 30ae764 | 2007-09-10 23:02:45 -0400 | [diff] [blame] | 97 | return rc; |
| 98 | } |