mirror of
https://github.com/git/git
synced 2024-08-25 02:35:46 +00:00
http: use new http API in fetch_index()
Signed-off-by: Tay Ray Chuan <rctay89@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
b8caac2b8a
commit
39dc52cf4f
77
http.c
77
http.c
|
@ -798,40 +798,22 @@ static int fetch_pack_index(unsigned char *sha1, const char *base_url)
|
||||||
char *hex = xstrdup(sha1_to_hex(sha1));
|
char *hex = xstrdup(sha1_to_hex(sha1));
|
||||||
char *filename;
|
char *filename;
|
||||||
char *url;
|
char *url;
|
||||||
char tmpfile[PATH_MAX];
|
|
||||||
long prev_posn = 0;
|
|
||||||
char range[RANGE_HEADER_SIZE];
|
|
||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
struct curl_slist *range_header = NULL;
|
|
||||||
|
|
||||||
FILE *indexfile;
|
|
||||||
struct active_request_slot *slot;
|
|
||||||
struct slot_results results;
|
|
||||||
|
|
||||||
/* Don't use the index if the pack isn't there */
|
/* Don't use the index if the pack isn't there */
|
||||||
end_url_with_slash(&buf, base_url);
|
end_url_with_slash(&buf, base_url);
|
||||||
strbuf_addf(&buf, "objects/pack/pack-%s.pack", hex);
|
strbuf_addf(&buf, "objects/pack/pack-%s.pack", hex);
|
||||||
url = strbuf_detach(&buf, 0);
|
url = strbuf_detach(&buf, 0);
|
||||||
|
|
||||||
slot = get_active_slot();
|
if (http_get_strbuf(url, NULL, 0)) {
|
||||||
slot->results = &results;
|
|
||||||
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
|
|
||||||
curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 1);
|
|
||||||
if (start_active_slot(slot)) {
|
|
||||||
run_active_slot(slot);
|
|
||||||
if (results.curl_result != CURLE_OK) {
|
|
||||||
ret = error("Unable to verify pack %s is available",
|
ret = error("Unable to verify pack %s is available",
|
||||||
hex);
|
hex);
|
||||||
goto cleanup_pack;
|
goto cleanup;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ret = error("Unable to start request");
|
|
||||||
goto cleanup_pack;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has_pack_index(sha1)) {
|
if (has_pack_index(sha1)) {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
goto cleanup_pack;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (http_is_verbose)
|
if (http_is_verbose)
|
||||||
|
@ -842,57 +824,10 @@ static int fetch_pack_index(unsigned char *sha1, const char *base_url)
|
||||||
url = strbuf_detach(&buf, NULL);
|
url = strbuf_detach(&buf, NULL);
|
||||||
|
|
||||||
filename = sha1_pack_index_name(sha1);
|
filename = sha1_pack_index_name(sha1);
|
||||||
snprintf(tmpfile, sizeof(tmpfile), "%s.temp", filename);
|
if (http_get_file(url, filename, 0) != HTTP_OK)
|
||||||
indexfile = fopen(tmpfile, "a");
|
ret = error("Unable to get pack index %s\n", url);
|
||||||
if (!indexfile) {
|
|
||||||
ret = error("Unable to open local file %s for pack index",
|
|
||||||
tmpfile);
|
|
||||||
goto cleanup_pack;
|
|
||||||
}
|
|
||||||
|
|
||||||
slot = get_active_slot();
|
cleanup:
|
||||||
slot->results = &results;
|
|
||||||
curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
|
|
||||||
curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
|
|
||||||
curl_easy_setopt(slot->curl, CURLOPT_FILE, indexfile);
|
|
||||||
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite);
|
|
||||||
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
|
|
||||||
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);
|
|
||||||
slot->local = indexfile;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If there is data present from a previous transfer attempt,
|
|
||||||
* resume where it left off
|
|
||||||
*/
|
|
||||||
prev_posn = ftell(indexfile);
|
|
||||||
if (prev_posn>0) {
|
|
||||||
if (http_is_verbose)
|
|
||||||
fprintf(stderr,
|
|
||||||
"Resuming fetch of index for pack %s at byte %ld\n",
|
|
||||||
hex, prev_posn);
|
|
||||||
sprintf(range, "Range: bytes=%ld-", prev_posn);
|
|
||||||
range_header = curl_slist_append(range_header, range);
|
|
||||||
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, range_header);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (start_active_slot(slot)) {
|
|
||||||
run_active_slot(slot);
|
|
||||||
if (results.curl_result != CURLE_OK) {
|
|
||||||
ret = error("Unable to get pack index %s\n%s",
|
|
||||||
url, curl_errorstr);
|
|
||||||
goto cleanup_index;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ret = error("Unable to start request");
|
|
||||||
goto cleanup_index;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = move_temp_to_file(tmpfile, filename);
|
|
||||||
|
|
||||||
cleanup_index:
|
|
||||||
fclose(indexfile);
|
|
||||||
slot->local = NULL;
|
|
||||||
cleanup_pack:
|
|
||||||
free(hex);
|
free(hex);
|
||||||
free(url);
|
free(url);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in a new issue