]>
git.ipfire.org Git - thirdparty/git.git/blob - http-fetch.c
7 static const char http_fetch_usage
[] = "git http-fetch "
8 "[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin | --packfile=hash | commit-id] url";
10 static int fetch_using_walker(const char *raw_url
, int get_verbosely
,
11 int get_recover
, int commits
, char **commit_id
,
12 const char **write_ref
, int commits_on_stdin
)
15 struct walker
*walker
;
18 str_end_url_with_slash(raw_url
, &url
);
20 http_init(NULL
, url
, 0);
22 walker
= get_http_walker(url
);
23 walker
->get_verbosely
= get_verbosely
;
24 walker
->get_recover
= get_recover
;
25 walker
->get_progress
= 0;
27 rc
= walker_fetch(walker
, commits
, commit_id
, write_ref
, url
);
30 walker_targets_free(commits
, commit_id
, write_ref
);
32 if (walker
->corrupt_object_found
) {
34 "Some loose object were found to be corrupt, but they might be just\n"
35 "a false '404 Not Found' error message sent with incorrect HTTP\n"
36 "status code. Suggest running 'git fsck'.\n");
46 static void fetch_single_packfile(struct object_id
*packfile_hash
,
48 struct http_pack_request
*preq
;
49 struct slot_results results
;
52 http_init(NULL
, url
, 0);
54 preq
= new_direct_http_pack_request(packfile_hash
->hash
, xstrdup(url
));
56 die("couldn't create http pack request");
57 preq
->slot
->results
= &results
;
58 preq
->generate_keep
= 1;
60 if (start_active_slot(preq
->slot
)) {
61 run_active_slot(preq
->slot
);
62 if (results
.curl_result
!= CURLE_OK
) {
63 die("Unable to get pack file %s\n%s", preq
->url
,
67 die("Unable to start request");
70 if ((ret
= finish_http_pack_request(preq
)))
71 die("finish_http_pack_request gave result %d", ret
);
73 release_http_pack_request(preq
);
77 int cmd_main(int argc
, const char **argv
)
79 int commits_on_stdin
= 0;
81 const char **write_ref
= NULL
;
84 int get_verbosely
= 0;
88 struct object_id packfile_hash
;
90 setup_git_directory_gently(&nongit
);
92 while (arg
< argc
&& argv
[arg
][0] == '-') {
95 if (argv
[arg
][1] == 't') {
96 } else if (argv
[arg
][1] == 'c') {
97 } else if (argv
[arg
][1] == 'a') {
98 } else if (argv
[arg
][1] == 'v') {
100 } else if (argv
[arg
][1] == 'w') {
101 write_ref
= &argv
[arg
+ 1];
103 } else if (argv
[arg
][1] == 'h') {
104 usage(http_fetch_usage
);
105 } else if (!strcmp(argv
[arg
], "--recover")) {
107 } else if (!strcmp(argv
[arg
], "--stdin")) {
108 commits_on_stdin
= 1;
109 } else if (skip_prefix(argv
[arg
], "--packfile=", &p
)) {
113 if (parse_oid_hex(p
, &packfile_hash
, &end
) || *end
)
114 die(_("argument to --packfile must be a valid hash (got '%s')"), p
);
118 if (argc
!= arg
+ 2 - (commits_on_stdin
|| packfile
))
119 usage(http_fetch_usage
);
122 die(_("not a git repository"));
124 git_config(git_default_config
, NULL
);
127 fetch_single_packfile(&packfile_hash
, argv
[arg
]);
131 if (commits_on_stdin
) {
132 commits
= walker_targets_stdin(&commit_id
, &write_ref
);
134 commit_id
= (char **) &argv
[arg
++];
137 return fetch_using_walker(argv
[arg
], get_verbosely
, get_recover
,
138 commits
, commit_id
, write_ref
,