From: Tay Ray Chuan <rctay89@gmail.com>
To: Git Mailing List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Mike Hommey <mh@glandium.org>
Subject: [PATCH 21/23] http: use new http API in fetch_index()
Date: Sat, 6 Jun 2009 16:44:00 +0800 [thread overview]
Message-ID: <20090606164400.c923729b.rctay89@gmail.com> (raw)
In-Reply-To: <cover.1244277116.git.rctay89@gmail.com>
Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
---
http.c | 81 ++++++---------------------------------------------------------
1 files changed, 8 insertions(+), 73 deletions(-)
diff --git a/http.c b/http.c
index 96d83d5..0701a6f 100644
--- a/http.c
+++ b/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 *filename;
char *url;
- char tmpfile[PATH_MAX];
- long prev_posn = 0;
- char range[RANGE_HEADER_SIZE];
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 */
end_url_with_slash(&buf, base_url);
strbuf_addf(&buf, "objects/pack/pack-%s.pack", hex);
url = strbuf_detach(&buf, 0);
- slot = get_active_slot();
- 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",
- hex);
- goto cleanup_pack;
- }
- } else {
- ret = error("Unable to start request");
- goto cleanup_pack;
+ if (http_get_strbuf(url, NULL, 0)) {
+ ret = error("Unable to verify pack %s is available",
+ hex);
+ goto cleanup;
}
if (has_pack_index(sha1)) {
ret = 0;
- goto cleanup_pack;
+ goto cleanup;
}
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);
filename = sha1_pack_index_name(sha1);
- snprintf(tmpfile, sizeof(tmpfile), "%s.temp", filename);
- indexfile = fopen(tmpfile, "a");
- if (!indexfile) {
- ret = error("Unable to open local file %s for pack index",
- tmpfile);
- goto cleanup_pack;
- }
+ if (http_get_file(url, filename, 0) != HTTP_OK)
+ ret = error("Unable to get pack index %s\n", url);
- slot = get_active_slot();
- 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:
+cleanup:
free(hex);
free(url);
return ret;
--
1.6.3.1
next prev parent reply other threads:[~2009-06-06 8:51 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1244277116.git.rctay89@gmail.com>
2009-06-06 8:43 ` [PATCH 01/23] t5540-http-push: test fetching of loose objects Tay Ray Chuan
2009-06-06 8:43 ` [PATCH 02/23] t5540-http-push: test fetching of packed objects Tay Ray Chuan
2009-06-06 8:43 ` [PATCH 03/23] http*: cleanup slot->local after fclose Tay Ray Chuan
2009-06-06 8:43 ` [PATCH 04/23] http-push: send out fetch requests on queue Tay Ray Chuan
2009-06-06 8:43 ` [PATCH 05/23] http-push: fix missing "#ifdef USE_CURL_MULTI" around "is_running_queue" Tay Ray Chuan
2009-06-06 8:43 ` [PATCH 06/23] t5550-http-fetch: test fetching of packed objects Tay Ray Chuan
2009-06-06 8:43 ` [PATCH 07/23] http-push, http-walker: style fixes Tay Ray Chuan
2009-06-06 8:43 ` [PATCH 08/23] http-walker: verify remote packs Tay Ray Chuan
2009-06-06 8:43 ` [PATCH 09/23] http*: copy string returned by sha1_to_hex Tay Ray Chuan
2009-06-06 8:43 ` [PATCH 10/23] http-push: do not SEGV after fetching a bad pack idx file Tay Ray Chuan
2009-06-06 8:43 ` [PATCH 11/23] Don't expect verify_pack() callers to set pack_size Tay Ray Chuan
2009-06-06 8:43 ` [PATCH 12/23] transport.c::get_refs_via_curl(): do not leak refs_url Tay Ray Chuan
2009-06-06 8:43 ` [PATCH 13/23] http*: move common variables and macros to http.[ch] Tay Ray Chuan
2009-06-06 8:43 ` [PATCH 14/23] http: create function end_url_with_slash Tay Ray Chuan
2009-06-06 8:43 ` [PATCH 15/23] http.c: new functions for the http API Tay Ray Chuan
2009-06-06 8:43 ` [PATCH 16/23] transport.c::get_refs_via_curl(): use the new " Tay Ray Chuan
2009-06-06 8:43 ` [PATCH 17/23] http.c::http_fetch_ref(): " Tay Ray Chuan
2009-06-06 8:43 ` [PATCH 18/23] http-push.c::remote_exists(): " Tay Ray Chuan
2009-06-06 8:43 ` [PATCH 19/23] http-push.c::fetch_symref(): " Tay Ray Chuan
2009-06-06 8:43 ` [PATCH 20/23] http*: add http_get_info_packs Tay Ray Chuan
2009-06-06 8:44 ` Tay Ray Chuan [this message]
2009-06-06 8:44 ` [PATCH 22/23] http*: add helper methods for fetching packs Tay Ray Chuan
2009-06-06 8:44 ` [PATCH 23/23] http*: add helper methods for fetching objects (loose) Tay Ray Chuan
2009-06-05 16:06 [PATCH 21/23] http: use new http API in fetch_index() Tay Ray Chuan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090606164400.c923729b.rctay89@gmail.com \
--to=rctay89@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mh@glandium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).