8 static const char http_fetch_usage[] = "git http-fetch "
9 "[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin | --packfile=hash | commit-id] url";
11 static int fetch_using_walker(const char *raw_url, int get_verbosely,
12 int get_recover, int commits, char **commit_id,
13 const char **write_ref, int commits_on_stdin)
16 struct walker *walker;
19 str_end_url_with_slash(raw_url, &url);
21 http_init(NULL, url, 0);
23 walker = get_http_walker(url);
24 walker->get_verbosely = get_verbosely;
25 walker->get_recover = get_recover;
26 walker->get_progress = 0;
28 rc = walker_fetch(walker, commits, commit_id, write_ref, url);
31 walker_targets_free(commits, commit_id, write_ref);
33 if (walker->corrupt_object_found) {
35 "Some loose object were found to be corrupt, but they might be just\n"
36 "a false '404 Not Found' error message sent with incorrect HTTP\n"
37 "status code. Suggest running 'git fsck'.\n");
47 static void fetch_single_packfile(struct object_id *packfile_hash,
49 const char **index_pack_args) {
50 struct http_pack_request *preq;
51 struct slot_results results;
54 http_init(NULL, url, 0);
56 preq = new_direct_http_pack_request(packfile_hash->hash, xstrdup(url));
58 die("couldn't create http pack request");
59 preq->slot->results = &results;
60 preq->index_pack_args = index_pack_args;
61 preq->preserve_index_pack_stdout = 1;
63 if (start_active_slot(preq->slot)) {
64 run_active_slot(preq->slot);
65 if (results.curl_result != CURLE_OK) {
66 die("Unable to get pack file %s\n%s", preq->url,
70 die("Unable to start request");
73 if ((ret = finish_http_pack_request(preq)))
74 die("finish_http_pack_request gave result %d", ret);
76 release_http_pack_request(preq);
80 int cmd_main(int argc, const char **argv)
82 int commits_on_stdin = 0;
84 const char **write_ref = NULL;
87 int get_verbosely = 0;
91 struct object_id packfile_hash;
92 struct strvec index_pack_args = STRVEC_INIT;
94 setup_git_directory_gently(&nongit);
96 while (arg < argc && argv[arg][0] == '-') {
99 if (argv[arg][1] == 't') {
100 } else if (argv[arg][1] == 'c') {
101 } else if (argv[arg][1] == 'a') {
102 } else if (argv[arg][1] == 'v') {
104 } else if (argv[arg][1] == 'w') {
105 write_ref = &argv[arg + 1];
107 } else if (argv[arg][1] == 'h') {
108 usage(http_fetch_usage);
109 } else if (!strcmp(argv[arg], "--recover")) {
111 } else if (!strcmp(argv[arg], "--stdin")) {
112 commits_on_stdin = 1;
113 } else if (skip_prefix(argv[arg], "--packfile=", &p)) {
117 if (parse_oid_hex(p, &packfile_hash, &end) || *end)
118 die(_("argument to --packfile must be a valid hash (got '%s')"), p);
119 } else if (skip_prefix(argv[arg], "--index-pack-arg=", &p)) {
120 strvec_push(&index_pack_args, p);
124 if (argc != arg + 2 - (commits_on_stdin || packfile))
125 usage(http_fetch_usage);
128 die(_("not a git repository"));
130 git_config(git_default_config, NULL);
133 if (!index_pack_args.nr)
134 die(_("--packfile requires --index-pack-args"));
136 fetch_single_packfile(&packfile_hash, argv[arg],
142 if (index_pack_args.nr)
143 die(_("--index-pack-args can only be used with --packfile"));
145 if (commits_on_stdin) {
146 commits = walker_targets_stdin(&commit_id, &write_ref);
148 commit_id = (char **) &argv[arg++];
151 return fetch_using_walker(argv[arg], get_verbosely, get_recover,
152 commits, commit_id, write_ref,