12 static const char http_fetch_usage
[] = "git http-fetch "
13 "[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin | --packfile=hash | commit-id] url";
15 static int fetch_using_walker(const char *raw_url
, int get_verbosely
,
16 int get_recover
, int commits
, char **commit_id
,
17 const char **write_ref
, int commits_on_stdin
)
20 struct walker
*walker
;
23 str_end_url_with_slash(raw_url
, &url
);
25 http_init(NULL
, url
, 0);
27 walker
= get_http_walker(url
);
28 walker
->get_verbosely
= get_verbosely
;
29 walker
->get_recover
= get_recover
;
30 walker
->get_progress
= 0;
32 rc
= walker_fetch(walker
, commits
, commit_id
, write_ref
, url
);
35 walker_targets_free(commits
, commit_id
, write_ref
);
37 if (walker
->corrupt_object_found
) {
39 "Some loose object were found to be corrupt, but they might be just\n"
40 "a false '404 Not Found' error message sent with incorrect HTTP\n"
41 "status code. Suggest running 'git fsck'.\n");
51 static void fetch_single_packfile(struct object_id
*packfile_hash
,
53 const char **index_pack_args
) {
54 struct http_pack_request
*preq
;
55 struct slot_results results
;
58 http_init(NULL
, url
, 0);
60 preq
= new_direct_http_pack_request(packfile_hash
->hash
, xstrdup(url
));
62 die("couldn't create http pack request");
63 preq
->slot
->results
= &results
;
64 preq
->index_pack_args
= index_pack_args
;
65 preq
->preserve_index_pack_stdout
= 1;
67 if (start_active_slot(preq
->slot
)) {
68 run_active_slot(preq
->slot
);
69 if (results
.curl_result
!= CURLE_OK
) {
71 char *nurl
= url_normalize(preq
->url
, &url
);
72 if (!nurl
|| !git_env_bool("GIT_TRACE_REDACT", 1)) {
73 die("unable to get pack file '%s'\n%s", preq
->url
,
76 die("failed to get '%.*s' url from '%.*s' "
77 "(full URL redacted due to GIT_TRACE_REDACT setting)\n%s",
78 (int)url
.scheme_len
, url
.url
,
79 (int)url
.host_len
, &url
.url
[url
.host_off
], curl_errorstr
);
83 die("Unable to start request");
86 if ((ret
= finish_http_pack_request(preq
)))
87 die("finish_http_pack_request gave result %d", ret
);
89 release_http_pack_request(preq
);
93 int cmd_main(int argc
, const char **argv
)
95 int commits_on_stdin
= 0;
97 const char **write_ref
= NULL
;
100 int get_verbosely
= 0;
104 struct object_id packfile_hash
;
105 struct strvec index_pack_args
= STRVEC_INIT
;
107 setup_git_directory_gently(&nongit
);
109 while (arg
< argc
&& argv
[arg
][0] == '-') {
112 if (argv
[arg
][1] == 't') {
113 } else if (argv
[arg
][1] == 'c') {
114 } else if (argv
[arg
][1] == 'a') {
115 } else if (argv
[arg
][1] == 'v') {
117 } else if (argv
[arg
][1] == 'w') {
118 write_ref
= &argv
[arg
+ 1];
120 } else if (argv
[arg
][1] == 'h') {
121 usage(http_fetch_usage
);
122 } else if (!strcmp(argv
[arg
], "--recover")) {
124 } else if (!strcmp(argv
[arg
], "--stdin")) {
125 commits_on_stdin
= 1;
126 } else if (skip_prefix(argv
[arg
], "--packfile=", &p
)) {
130 if (parse_oid_hex(p
, &packfile_hash
, &end
) || *end
)
131 die(_("argument to --packfile must be a valid hash (got '%s')"), p
);
132 } else if (skip_prefix(argv
[arg
], "--index-pack-arg=", &p
)) {
133 strvec_push(&index_pack_args
, p
);
137 if (argc
!= arg
+ 2 - (commits_on_stdin
|| packfile
))
138 usage(http_fetch_usage
);
141 die(_("not a git repository"));
143 trace2_cmd_name("http-fetch");
145 git_config(git_default_config
, NULL
);
148 if (!index_pack_args
.nr
)
149 die(_("the option '%s' requires '%s'"), "--packfile", "--index-pack-args");
151 fetch_single_packfile(&packfile_hash
, argv
[arg
],
157 if (index_pack_args
.nr
)
158 die(_("the option '%s' requires '%s'"), "--index-pack-args", "--packfile");
160 if (commits_on_stdin
) {
161 commits
= walker_targets_stdin(&commit_id
, &write_ref
);
163 commit_id
= (char **) &argv
[arg
++];
166 return fetch_using_walker(argv
[arg
], get_verbosely
, get_recover
,
167 commits
, commit_id
, write_ref
,