Merge 'poll-busy-wait' into HEAD
[git/mingw/4msysgit.git] / http-fetch.c
blob51b26d7af866658cfd847286c32cd4613992c215
1 #include "cache.h"
2 #include "exec_cmd.h"
3 #include "http.h"
4 #include "walker.h"
6 static const char http_fetch_usage[] = "git http-fetch "
7 "[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url";
9 int main(int argc, char **av)
11 struct walker *walker;
12 int commits_on_stdin = 0;
13 int commits;
14 const char **argv = (const char **)av;
15 const char **write_ref = NULL;
16 char **commit_id;
17 char *url = NULL;
18 int arg = 1;
19 int rc = 0;
20 int get_tree = 0;
21 int get_history = 0;
22 int get_all = 0;
23 int get_verbosely = 0;
24 int get_recover = 0;
26 git_setup_gettext();
28 git_extract_argv0_path(argv[0]);
30 while (arg < argc && argv[arg][0] == '-') {
31 if (argv[arg][1] == 't') {
32 get_tree = 1;
33 } else if (argv[arg][1] == 'c') {
34 get_history = 1;
35 } else if (argv[arg][1] == 'a') {
36 get_all = 1;
37 get_tree = 1;
38 get_history = 1;
39 } else if (argv[arg][1] == 'v') {
40 get_verbosely = 1;
41 } else if (argv[arg][1] == 'w') {
42 write_ref = &argv[arg + 1];
43 arg++;
44 } else if (argv[arg][1] == 'h') {
45 usage(http_fetch_usage);
46 } else if (!strcmp(argv[arg], "--recover")) {
47 get_recover = 1;
48 } else if (!strcmp(argv[arg], "--stdin")) {
49 commits_on_stdin = 1;
51 arg++;
53 if (argc != arg + 2 - commits_on_stdin)
54 usage(http_fetch_usage);
55 if (commits_on_stdin) {
56 commits = walker_targets_stdin(&commit_id, &write_ref);
57 } else {
58 commit_id = (char **) &argv[arg++];
59 commits = 1;
62 if (get_all == 0)
63 warning("http-fetch: use without -a is deprecated.\n"
64 "In a future release, -a will become the default.");
66 if (argv[arg])
67 str_end_url_with_slash(argv[arg], &url);
69 setup_git_directory();
71 git_config(git_default_config, NULL);
73 http_init(NULL, url, 0);
74 walker = get_http_walker(url);
75 walker->get_tree = get_tree;
76 walker->get_history = get_history;
77 walker->get_all = get_all;
78 walker->get_verbosely = get_verbosely;
79 walker->get_recover = get_recover;
81 rc = walker_fetch(walker, commits, commit_id, write_ref, url);
83 if (commits_on_stdin)
84 walker_targets_free(commits, commit_id, write_ref);
86 if (walker->corrupt_object_found) {
87 fprintf(stderr,
88 "Some loose object were found to be corrupt, but they might be just\n"
89 "a false '404 Not Found' error message sent with incorrect HTTP\n"
90 "status code. Suggest running 'git fsck'.\n");
93 walker_free(walker);
94 http_cleanup();
96 free(url);
98 return rc;