9 static const char http_fetch_usage
[] = "git http-fetch "
10 "[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin | --packfile=hash | commit-id] url";
12 static int fetch_using_walker(const char *raw_url
, int get_verbosely
,
13 int get_recover
, int commits
, char **commit_id
,
14 const char **write_ref
, int commits_on_stdin
)
17 struct walker
*walker
;
20 str_end_url_with_slash(raw_url
, &url
);
22 http_init(NULL
, url
, 0);
24 walker
= get_http_walker(url
);
25 walker
->get_verbosely
= get_verbosely
;
26 walker
->get_recover
= get_recover
;
27 walker
->get_progress
= 0;
29 rc
= walker_fetch(walker
, commits
, commit_id
, write_ref
, url
);
32 walker_targets_free(commits
, commit_id
, write_ref
);
34 if (walker
->corrupt_object_found
) {
36 "Some loose object were found to be corrupt, but they might be just\n"
37 "a false '404 Not Found' error message sent with incorrect HTTP\n"
38 "status code. Suggest running 'git fsck'.\n");
48 static void fetch_single_packfile(struct object_id
*packfile_hash
,
50 const char **index_pack_args
) {
51 struct http_pack_request
*preq
;
52 struct slot_results results
;
55 http_init(NULL
, url
, 0);
57 preq
= new_direct_http_pack_request(packfile_hash
->hash
, xstrdup(url
));
59 die("couldn't create http pack request");
60 preq
->slot
->results
= &results
;
61 preq
->index_pack_args
= index_pack_args
;
62 preq
->preserve_index_pack_stdout
= 1;
64 if (start_active_slot(preq
->slot
)) {
65 run_active_slot(preq
->slot
);
66 if (results
.curl_result
!= CURLE_OK
) {
68 char *nurl
= url_normalize(preq
->url
, &url
);
69 if (!nurl
|| !git_env_bool("GIT_TRACE_REDACT", 1)) {
70 die("unable to get pack file '%s'\n%s", preq
->url
,
73 die("failed to get '%.*s' url from '%.*s' "
74 "(full URL redacted due to GIT_TRACE_REDACT setting)\n%s",
75 (int)url
.scheme_len
, url
.url
,
76 (int)url
.host_len
, &url
.url
[url
.host_off
], curl_errorstr
);
80 die("Unable to start request");
83 if ((ret
= finish_http_pack_request(preq
)))
84 die("finish_http_pack_request gave result %d", ret
);
86 release_http_pack_request(preq
);
90 int cmd_main(int argc
, const char **argv
)
92 int commits_on_stdin
= 0;
94 const char **write_ref
= NULL
;
97 int get_verbosely
= 0;
101 struct object_id packfile_hash
;
102 struct strvec index_pack_args
= STRVEC_INIT
;
104 setup_git_directory_gently(&nongit
);
106 while (arg
< argc
&& argv
[arg
][0] == '-') {
109 if (argv
[arg
][1] == 't') {
110 } else if (argv
[arg
][1] == 'c') {
111 } else if (argv
[arg
][1] == 'a') {
112 } else if (argv
[arg
][1] == 'v') {
114 } else if (argv
[arg
][1] == 'w') {
115 write_ref
= &argv
[arg
+ 1];
117 } else if (argv
[arg
][1] == 'h') {
118 usage(http_fetch_usage
);
119 } else if (!strcmp(argv
[arg
], "--recover")) {
121 } else if (!strcmp(argv
[arg
], "--stdin")) {
122 commits_on_stdin
= 1;
123 } else if (skip_prefix(argv
[arg
], "--packfile=", &p
)) {
127 if (parse_oid_hex(p
, &packfile_hash
, &end
) || *end
)
128 die(_("argument to --packfile must be a valid hash (got '%s')"), p
);
129 } else if (skip_prefix(argv
[arg
], "--index-pack-arg=", &p
)) {
130 strvec_push(&index_pack_args
, p
);
134 if (argc
!= arg
+ 2 - (commits_on_stdin
|| packfile
))
135 usage(http_fetch_usage
);
138 die(_("not a git repository"));
140 git_config(git_default_config
, NULL
);
143 if (!index_pack_args
.nr
)
144 die(_("the option '%s' requires '%s'"), "--packfile", "--index-pack-args");
146 fetch_single_packfile(&packfile_hash
, argv
[arg
],
152 if (index_pack_args
.nr
)
153 die(_("the option '%s' requires '%s'"), "--index-pack-args", "--packfile");
155 if (commits_on_stdin
) {
156 commits
= walker_targets_stdin(&commit_id
, &write_ref
);
158 commit_id
= (char **) &argv
[arg
++];
161 return fetch_using_walker(argv
[arg
], get_verbosely
, get_recover
,
162 commits
, commit_id
, write_ref
,