blob: 3af4c71bd0fb8370c6f08b0e3d43adc722cac2f4 [file] [log] [blame]
Daniel Barkalow30ae7642007-09-10 23:02:45 -04001#include "cache.h"
Jonathan Niederf01d7492009-11-09 09:05:00 -06002#include "exec_cmd.h"
Tay Ray Chuan888692b2010-03-02 18:49:29 +08003#include "http.h"
Daniel Barkalow30ae7642007-09-10 23:02:45 -04004#include "walker.h"
5
Jonathan Nieder616f86d2009-11-09 09:04:59 -06006static const char http_fetch_usage[] = "git http-fetch "
7"[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url";
8
Linus Torvalds10882612009-08-05 01:01:59 -04009int main(int argc, const char **argv)
Daniel Barkalow30ae7642007-09-10 23:02:45 -040010{
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 Chuan6f5185b2010-11-25 16:21:10 +080016 char *url = NULL;
Daniel Barkalow30ae7642007-09-10 23:02:45 -040017 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
Jonathan Niederf01d7492009-11-09 09:05:00 -060025 git_extract_argv0_path(argv[0]);
Daniel Barkalow30ae7642007-09-10 23:02:45 -040026
27 while (arg < argc && argv[arg][0] == '-') {
28 if (argv[arg][1] == 't') {
29 get_tree = 1;
30 } else if (argv[arg][1] == 'c') {
31 get_history = 1;
32 } else if (argv[arg][1] == 'a') {
33 get_all = 1;
34 get_tree = 1;
35 get_history = 1;
36 } else if (argv[arg][1] == 'v') {
37 get_verbosely = 1;
38 } else if (argv[arg][1] == 'w') {
39 write_ref = &argv[arg + 1];
40 arg++;
Jonathan Nieder616f86d2009-11-09 09:04:59 -060041 } else if (argv[arg][1] == 'h') {
42 usage(http_fetch_usage);
Daniel Barkalow30ae7642007-09-10 23:02:45 -040043 } else if (!strcmp(argv[arg], "--recover")) {
44 get_recover = 1;
45 } else if (!strcmp(argv[arg], "--stdin")) {
46 commits_on_stdin = 1;
47 }
48 arg++;
49 }
Jonathan Nieder616f86d2009-11-09 09:04:59 -060050 if (argc != arg + 2 - commits_on_stdin)
51 usage(http_fetch_usage);
Daniel Barkalow30ae7642007-09-10 23:02:45 -040052 if (commits_on_stdin) {
53 commits = walker_targets_stdin(&commit_id, &write_ref);
54 } else {
55 commit_id = (char **) &argv[arg++];
56 commits = 1;
57 }
Tay Ray Chuan6f5185b2010-11-25 16:21:10 +080058
59 if (argv[arg])
60 str_end_url_with_slash(argv[arg], &url);
Jonathan Nieder616f86d2009-11-09 09:04:59 -060061
Dan McGee13ee1382011-03-27 20:32:19 -050062 setup_git_directory();
Jonathan Nieder616f86d2009-11-09 09:04:59 -060063
64 git_config(git_default_config, NULL);
65
Tay Ray Chuan888692b2010-03-02 18:49:29 +080066 http_init(NULL);
67 walker = get_http_walker(url);
Daniel Barkalow30ae7642007-09-10 23:02:45 -040068 walker->get_tree = get_tree;
69 walker->get_history = get_history;
70 walker->get_all = get_all;
71 walker->get_verbosely = get_verbosely;
72 walker->get_recover = get_recover;
73
74 rc = walker_fetch(walker, commits, commit_id, write_ref, url);
75
76 if (commits_on_stdin)
77 walker_targets_free(commits, commit_id, write_ref);
78
79 if (walker->corrupt_object_found) {
80 fprintf(stderr,
81"Some loose object were found to be corrupt, but they might be just\n"
82"a false '404 Not Found' error message sent with incorrect HTTP\n"
Heikki Orsila05207a22008-09-09 13:28:30 +030083"status code. Suggest running 'git fsck'.\n");
Daniel Barkalow30ae7642007-09-10 23:02:45 -040084 }
85
86 walker_free(walker);
Tay Ray Chuan888692b2010-03-02 18:49:29 +080087 http_cleanup();
Daniel Barkalow30ae7642007-09-10 23:02:45 -040088
Tay Ray Chuan6f5185b2010-11-25 16:21:10 +080089 free(url);
Grégoire Barbier3057ded2008-01-19 16:22:50 +010090
Daniel Barkalow30ae7642007-09-10 23:02:45 -040091 return rc;
92}