{"thread":{"id":"19699","subject":"[PATCH 21/23] http: use new http API in fetch_index()","startedAt":"2009-06-05T16:06:22Z","lastAt":"2009-06-05T16:06:22Z","messageCount":1,"participants":["Tay Ray Chuan"],"isPatch":true,"patchVersion":1,"patchTotal":23},"messages":[{"id":"115535","messageId":"20090606000622.4d28adf6.rctay89@gmail.com","threadId":"19699","inReplyTo":null,"subject":"[PATCH 21/23] http: use new http API in fetch_index()","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2009-06-05T16:06:22Z","receivedAt":"2009-06-05T16:06:22Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"\nSigned-off-by: Tay Ray Chuan <rctay89@gmail.com>\n---\n http.c |   81 ++++++---------------------------------------------------------\n 1 files changed, 8 insertions(+), 73 deletions(-)\n\ndiff --git a/http.c b/http.c\nindex 96d83d5..0701a6f 100644\n--- a/http.c\n+++ b/http.c\n@@ -798,40 +798,22 @@ static int fetch_pack_index(unsigned char *sha1, const char *base_url)\n \tchar *hex = xstrdup(sha1_to_hex(sha1));\n \tchar *filename;\n \tchar *url;\n-\tchar tmpfile[PATH_MAX];\n-\tlong prev_posn = 0;\n-\tchar range[RANGE_HEADER_SIZE];\n \tstruct strbuf buf = STRBUF_INIT;\n-\tstruct curl_slist *range_header = NULL;\n-\n-\tFILE *indexfile;\n-\tstruct active_request_slot *slot;\n-\tstruct slot_results results;\n\n \t/* Don't use the index if the pack isn't there */\n \tend_url_with_slash(&buf, base_url);\n \tstrbuf_addf(&buf, \"objects/pack/pack-%s.pack\", hex);\n \turl = strbuf_detach(&buf, 0);\n\n-\tslot = get_active_slot();\n-\tslot->results = &results;\n-\tcurl_easy_setopt(slot->curl, CURLOPT_URL, url);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_NOBODY, 1);\n-\tif (start_active_slot(slot)) {\n-\t\trun_active_slot(slot);\n-\t\tif (results.curl_result != CURLE_OK) {\n-\t\t\tret = error(\"Unable to verify pack %s is available\",\n-\t\t\t\t    hex);\n-\t\t\tgoto cleanup_pack;\n-\t\t}\n-\t} else {\n-\t\tret = error(\"Unable to start request\");\n-\t\tgoto cleanup_pack;\n+\tif (http_get_strbuf(url, NULL, 0)) {\n+\t\tret = error(\"Unable to verify pack %s is available\",\n+\t\t\t    hex);\n+\t\tgoto cleanup;\n \t}\n\n \tif (has_pack_index(sha1)) {\n \t\tret = 0;\n-\t\tgoto cleanup_pack;\n+\t\tgoto cleanup;\n \t}\n\n \tif (http_is_verbose)\n@@ -842,57 +824,10 @@ static int fetch_pack_index(unsigned char *sha1, const char *base_url)\n \turl = strbuf_detach(&buf, NULL);\n\n \tfilename = sha1_pack_index_name(sha1);\n-\tsnprintf(tmpfile, sizeof(tmpfile), \"%s.temp\", filename);\n-\tindexfile = fopen(tmpfile, \"a\");\n-\tif (!indexfile) {\n-\t\tret = error(\"Unable to open local file %s for pack index\",\n-\t\t\t    tmpfile);\n-\t\tgoto cleanup_pack;\n-\t}\n+\tif (http_get_file(url, filename, 0) != HTTP_OK)\n+\t\tret = error(\"Unable to get pack index %s\\n\", url);\n\n-\tslot = get_active_slot();\n-\tslot->results = &results;\n-\tcurl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_FILE, indexfile);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_URL, url);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);\n-\tslot->local = indexfile;\n-\n-\t/*\n-\t * If there is data present from a previous transfer attempt,\n-\t * resume where it left off\n-\t */\n-\tprev_posn = ftell(indexfile);\n-\tif (prev_posn>0) {\n-\t\tif (http_is_verbose)\n-\t\t\tfprintf(stderr,\n-\t\t\t\t\"Resuming fetch of index for pack %s at byte %ld\\n\",\n-\t\t\t\thex, prev_posn);\n-\t\tsprintf(range, \"Range: bytes=%ld-\", prev_posn);\n-\t\trange_header = curl_slist_append(range_header, range);\n-\t\tcurl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, range_header);\n-\t}\n-\n-\tif (start_active_slot(slot)) {\n-\t\trun_active_slot(slot);\n-\t\tif (results.curl_result != CURLE_OK) {\n-\t\t\tret = error(\"Unable to get pack index %s\\n%s\",\n-\t\t\t\t    url, curl_errorstr);\n-\t\t\tgoto cleanup_index;\n-\t\t}\n-\t} else {\n-\t\tret = error(\"Unable to start request\");\n-\t\tgoto cleanup_index;\n-\t}\n-\n-\tret = move_temp_to_file(tmpfile, filename);\n-\n-cleanup_index:\n-\tfclose(indexfile);\n-\tslot->local = NULL;\n-cleanup_pack:\n+cleanup:\n \tfree(hex);\n \tfree(url);\n \treturn ret;\n--\n1.6.3.1\n"}]}