9 #if LIBCURL_VERSION_NUM >= 0x070908
10 #define USE_CURL_MULTI
11 #define DEFAULT_MAX_REQUESTS 5
14 #if LIBCURL_VERSION_NUM < 0x070704
15 #define curl_global_cleanup() do { /* nothing */ } while(0)
17 #if LIBCURL_VERSION_NUM < 0x070800
18 #define curl_global_init(a) do { /* nothing */ } while(0)
21 #define PREV_BUF_SIZE 4096
22 #define RANGE_HEADER_SIZE 30
24 static int active_requests = 0;
25 static int data_received;
28 static int max_requests = DEFAULT_MAX_REQUESTS;
31 static CURL *curl_default;
32 static struct curl_slist *no_pragma_header;
33 static struct curl_slist *no_range_header;
34 static char curl_errorstr[CURL_ERROR_SIZE];
40 struct packed_git *packs;
41 struct alt_base *next;
44 static struct alt_base *alt = NULL;
53 struct transfer_request
55 unsigned char sha1[20];
56 struct alt_base *repo;
58 char filename[PATH_MAX];
59 char tmpfile[PATH_MAX];
61 enum transfer_state state;
63 char errorstr[CURL_ERROR_SIZE];
65 unsigned char real_sha1[20];
70 struct active_request_slot *slot;
71 struct transfer_request *next;
74 struct active_request_slot
81 struct active_request_slot *next;
84 static struct transfer_request *request_queue_head = NULL;
85 static struct active_request_slot *active_queue_head = NULL;
87 static int curl_ssl_verify;
88 static char *ssl_cert;
90 static char *ssl_capath;
91 static char *ssl_cainfo;
100 static size_t fwrite_buffer(void *ptr, size_t eltsize, size_t nmemb,
101 struct buffer *buffer)
103 size_t size = eltsize * nmemb;
104 if (size > buffer->size - buffer->posn)
105 size = buffer->size - buffer->posn;
106 memcpy(buffer->buffer + buffer->posn, ptr, size);
107 buffer->posn += size;
112 static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
115 unsigned char expn[4096];
116 size_t size = eltsize * nmemb;
118 struct transfer_request *request = (struct transfer_request *)data;
120 ssize_t retval = write(request->local,
121 ptr + posn, size - posn);
125 } while (posn < size);
127 request->stream.avail_in = size;
128 request->stream.next_in = ptr;
130 request->stream.next_out = expn;
131 request->stream.avail_out = sizeof(expn);
132 request->zret = inflate(&request->stream, Z_SYNC_FLUSH);
133 SHA1_Update(&request->c, expn,
134 sizeof(expn) - request->stream.avail_out);
135 } while (request->stream.avail_in && request->zret == Z_OK);
140 int relink_or_rename(char *old, char *new) {
143 ret = link(old, new);
145 /* Same Coda hack as in write_sha1_file(sha1_file.c) */
147 if (ret == EXDEV && !rename(old, new))
159 #ifdef USE_CURL_MULTI
160 void process_curl_messages();
161 void process_request_queue();
164 struct active_request_slot *get_active_slot()
166 struct active_request_slot *slot = active_queue_head;
167 struct active_request_slot *newslot;
169 #ifdef USE_CURL_MULTI
172 /* Wait for a slot to open up if the queue is full */
173 while (active_requests >= max_requests) {
174 curl_multi_perform(curlm, &num_transfers);
175 if (num_transfers < active_requests) {
176 process_curl_messages();
181 while (slot != NULL && slot->in_use) {
185 newslot = xmalloc(sizeof(*newslot));
186 newslot->curl = curl_easy_duphandle(curl_default);
188 newslot->next = NULL;
190 slot = active_queue_head;
192 active_queue_head = newslot;
194 while (slot->next != NULL) {
197 slot->next = newslot;
206 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);
207 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_range_header);
208 curl_easy_setopt(slot->curl, CURLOPT_ERRORBUFFER, curl_errorstr);
213 int start_active_slot(struct active_request_slot *slot)
215 #ifdef USE_CURL_MULTI
216 CURLMcode curlm_result = curl_multi_add_handle(curlm, slot->curl);
218 if (curlm_result != CURLM_OK &&
219 curlm_result != CURLM_CALL_MULTI_PERFORM) {
228 void run_active_slot(struct active_request_slot *slot)
230 #ifdef USE_CURL_MULTI
238 struct timeval select_timeout;
239 CURLMcode curlm_result;
241 while (!slot->done) {
244 curlm_result = curl_multi_perform(curlm,
246 } while (curlm_result == CURLM_CALL_MULTI_PERFORM);
247 if (num_transfers < active_requests) {
248 process_curl_messages();
249 process_request_queue();
252 if (!data_received && slot->local != NULL) {
253 current_pos = ftell(slot->local);
254 if (current_pos > last_pos)
256 last_pos = current_pos;
259 if (!slot->done && !data_received) {
264 select_timeout.tv_sec = 0;
265 select_timeout.tv_usec = 50000;
266 select(max_fd, &readfds, &writefds,
267 &excfds, &select_timeout);
271 slot->curl_result = curl_easy_perform(slot->curl);
276 void start_request(struct transfer_request *request)
278 char *hex = sha1_to_hex(request->sha1);
279 char prevfile[PATH_MAX];
283 unsigned char prev_buf[PREV_BUF_SIZE];
284 ssize_t prev_read = 0;
286 char range[RANGE_HEADER_SIZE];
287 struct curl_slist *range_header = NULL;
288 struct active_request_slot *slot;
290 snprintf(prevfile, sizeof(prevfile), "%s.prev", request->filename);
292 rename(request->tmpfile, prevfile);
293 unlink(request->tmpfile);
295 request->local = open(request->tmpfile,
296 O_WRONLY | O_CREAT | O_EXCL, 0666);
297 if (request->local < 0) {
298 request->state = ABORTED;
299 error("Couldn't create temporary file %s for %s: %s\n",
300 request->tmpfile, request->filename, strerror(errno));
304 memset(&request->stream, 0, sizeof(request->stream));
306 inflateInit(&request->stream);
308 SHA1_Init(&request->c);
310 url = xmalloc(strlen(request->repo->base) + 50);
311 request->url = xmalloc(strlen(request->repo->base) + 50);
312 strcpy(url, request->repo->base);
313 posn = url + strlen(request->repo->base);
314 strcpy(posn, "objects/");
316 memcpy(posn, hex, 2);
319 strcpy(posn, hex + 2);
320 strcpy(request->url, url);
322 /* If a previous temp file is present, process what was already
324 prevlocal = open(prevfile, O_RDONLY);
325 if (prevlocal != -1) {
327 prev_read = read(prevlocal, prev_buf, PREV_BUF_SIZE);
329 if (fwrite_sha1_file(prev_buf,
332 request) == prev_read) {
333 prev_posn += prev_read;
338 } while (prev_read > 0);
343 /* Reset inflate/SHA1 if there was an error reading the previous temp
344 file; also rewind to the beginning of the local file. */
345 if (prev_read == -1) {
346 memset(&request->stream, 0, sizeof(request->stream));
347 inflateInit(&request->stream);
348 SHA1_Init(&request->c);
351 lseek(request->local, SEEK_SET, 0);
352 ftruncate(request->local, 0);
356 slot = get_active_slot();
357 curl_easy_setopt(slot->curl, CURLOPT_FILE, request);
358 curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_sha1_file);
359 curl_easy_setopt(slot->curl, CURLOPT_ERRORBUFFER, request->errorstr);
360 curl_easy_setopt(slot->curl, CURLOPT_URL, url);
362 /* If we have successfully processed data from a previous fetch
363 attempt, only fetch the data we don't already have. */
367 "Resuming fetch of object %s at byte %ld\n",
369 sprintf(range, "Range: bytes=%ld-", prev_posn);
370 range_header = curl_slist_append(range_header, range);
371 curl_easy_setopt(slot->curl,
372 CURLOPT_HTTPHEADER, range_header);
375 /* Try to get the request started, abort the request on error */
376 if (!start_active_slot(slot)) {
377 request->state = ABORTED;
378 close(request->local);
383 request->slot = slot;
384 request->state = ACTIVE;
387 void finish_request(struct transfer_request *request)
389 fchmod(request->local, 0444);
390 close(request->local);
392 if (request->http_code == 416) {
393 fprintf(stderr, "Warning: requested range invalid; we may already have all the data.\n");
394 } else if (request->curl_result != CURLE_OK) {
398 inflateEnd(&request->stream);
399 SHA1_Final(request->real_sha1, &request->c);
400 if (request->zret != Z_STREAM_END) {
401 unlink(request->tmpfile);
404 if (memcmp(request->sha1, request->real_sha1, 20)) {
405 unlink(request->tmpfile);
409 relink_or_rename(request->tmpfile, request->filename);
411 if (request->rename == 0)
412 pull_say("got %s\n", sha1_to_hex(request->sha1));
415 void release_request(struct transfer_request *request)
417 struct transfer_request *entry = request_queue_head;
419 if (request == request_queue_head) {
420 request_queue_head = request->next;
422 while (entry->next != NULL && entry->next != request)
424 if (entry->next == request)
425 entry->next = entry->next->next;
432 #ifdef USE_CURL_MULTI
433 void process_curl_messages()
436 struct active_request_slot *slot;
437 struct transfer_request *request = NULL;
438 CURLMsg *curl_message = curl_multi_info_read(curlm, &num_messages);
440 while (curl_message != NULL) {
441 if (curl_message->msg == CURLMSG_DONE) {
442 slot = active_queue_head;
443 while (slot != NULL &&
444 slot->curl != curl_message->easy_handle)
447 curl_multi_remove_handle(curlm, slot->curl);
451 slot->curl_result = curl_message->data.result;
452 request = request_queue_head;
453 while (request != NULL &&
454 request->slot != slot)
455 request = request->next;
457 fprintf(stderr, "Received DONE message for unknown request!\n");
459 if (request != NULL) {
460 request->curl_result =
461 curl_message->data.result;
462 curl_easy_getinfo(slot->curl,
464 &request->http_code);
465 request->slot = NULL;
467 /* Use alternates if necessary */
468 if (request->http_code == 404 &&
469 request->repo->next != NULL) {
470 request->repo = request->repo->next;
471 start_request(request);
473 finish_request(request);
474 request->state = COMPLETE;
478 fprintf(stderr, "Unknown CURL message received: %d\n",
479 (int)curl_message->msg);
481 curl_message = curl_multi_info_read(curlm, &num_messages);
485 void process_request_queue()
487 struct transfer_request *request = request_queue_head;
490 while (active_requests < max_requests && request != NULL) {
491 if (request->state == WAITING) {
492 start_request(request);
493 curl_multi_perform(curlm, &num_transfers);
495 request = request->next;
500 void prefetch(unsigned char *sha1)
502 struct transfer_request *newreq;
503 struct transfer_request *tail;
504 char *filename = sha1_file_name(sha1);
506 newreq = xmalloc(sizeof(*newreq));
507 memcpy(newreq->sha1, sha1, 20);
511 newreq->state = WAITING;
512 snprintf(newreq->filename, sizeof(newreq->filename), "%s", filename);
513 snprintf(newreq->tmpfile, sizeof(newreq->tmpfile),
514 "%s.temp", filename);
517 if (request_queue_head == NULL) {
518 request_queue_head = newreq;
520 tail = request_queue_head;
521 while (tail->next != NULL) {
526 #ifdef USE_CURL_MULTI
527 process_request_queue();
528 process_curl_messages();
532 static int got_alternates = 0;
534 static int fetch_index(struct alt_base *repo, unsigned char *sha1)
536 char *hex = sha1_to_hex(sha1);
539 char tmpfile[PATH_MAX];
542 char range[RANGE_HEADER_SIZE];
543 struct curl_slist *range_header = NULL;
546 struct active_request_slot *slot;
548 if (has_pack_index(sha1))
552 fprintf(stderr, "Getting index for pack %s\n", hex);
554 url = xmalloc(strlen(repo->base) + 64);
555 sprintf(url, "%s/objects/pack/pack-%s.idx", repo->base, hex);
557 filename = sha1_pack_index_name(sha1);
558 snprintf(tmpfile, sizeof(tmpfile), "%s.temp", filename);
559 indexfile = fopen(tmpfile, "a");
561 return error("Unable to open local file %s for pack index",
564 slot = get_active_slot();
565 curl_easy_setopt(slot->curl, CURLOPT_FILE, indexfile);
566 curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite);
567 curl_easy_setopt(slot->curl, CURLOPT_URL, url);
568 slot->local = indexfile;
570 /* If there is data present from a previous transfer attempt,
571 resume where it left off */
572 prev_posn = ftell(indexfile);
576 "Resuming fetch of index for pack %s at byte %ld\n",
578 sprintf(range, "Range: bytes=%ld-", prev_posn);
579 range_header = curl_slist_append(range_header, range);
580 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, range_header);
583 if (start_active_slot(slot)) {
584 run_active_slot(slot);
585 if (slot->curl_result != CURLE_OK) {
587 return error("Unable to get pack index %s\n%s", url,
591 return error("Unable to start request");
596 ret = relink_or_rename(tmpfile, filename);
598 return error("unable to write index filename %s: %s",
599 filename, strerror(ret));
604 static int setup_index(struct alt_base *repo, unsigned char *sha1)
606 struct packed_git *new_pack;
607 if (has_pack_file(sha1))
608 return 0; // don't list this as something we can get
610 if (fetch_index(repo, sha1))
613 new_pack = parse_pack_index(sha1);
614 new_pack->next = repo->packs;
615 repo->packs = new_pack;
619 static int fetch_alternates(char *base)
622 struct buffer buffer;
626 int http_specific = 1;
627 struct alt_base *tail = alt;
629 struct active_request_slot *slot;
632 data = xmalloc(4096);
635 buffer.buffer = data;
638 fprintf(stderr, "Getting alternates list\n");
640 url = xmalloc(strlen(base) + 31);
641 sprintf(url, "%s/objects/info/http-alternates", base);
643 slot = get_active_slot();
644 curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
645 curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
646 curl_easy_setopt(slot->curl, CURLOPT_URL, url);
647 if (start_active_slot(slot)) {
648 run_active_slot(slot);
649 if (slot->curl_result != CURLE_OK || !buffer.posn) {
652 sprintf(url, "%s/objects/info/alternates", base);
654 slot = get_active_slot();
655 curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
656 curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION,
658 curl_easy_setopt(slot->curl, CURLOPT_URL, url);
659 if (start_active_slot(slot)) {
660 run_active_slot(slot);
661 if (slot->curl_result != CURLE_OK) {
670 data[buffer.posn] = '\0';
672 while (i < buffer.posn) {
674 while (posn < buffer.posn && data[posn] != '\n')
676 if (data[posn] == '\n') {
679 struct alt_base *newalt;
681 if (data[i] == '/') {
682 serverlen = strchr(base + 8, '/') - base;
684 } else if (!memcmp(data + i, "../", 3)) {
686 serverlen = strlen(base);
687 while (i + 2 < posn &&
688 !memcmp(data + i, "../", 3)) {
691 } while (serverlen &&
692 base[serverlen - 1] != '/');
695 // If the server got removed, give up.
696 okay = strchr(base, ':') - base + 3 <
698 } else if (http_specific) {
699 char *colon = strchr(data + i, ':');
700 char *slash = strchr(data + i, '/');
701 if (colon && slash && colon < data + posn &&
702 slash < data + posn && colon < slash) {
706 // skip 'objects' at end
708 target = xmalloc(serverlen + posn - i - 6);
709 strncpy(target, base, serverlen);
710 strncpy(target + serverlen, data + i,
712 target[serverlen + posn - i - 7] = '\0';
715 "Also look at %s\n", target);
716 newalt = xmalloc(sizeof(*newalt));
718 newalt->base = target;
719 newalt->got_indices = 0;
720 newalt->packs = NULL;
721 while (tail->next != NULL)
734 static int fetch_indices(struct alt_base *repo)
736 unsigned char sha1[20];
738 struct buffer buffer;
742 struct active_request_slot *slot;
744 if (repo->got_indices)
747 data = xmalloc(4096);
750 buffer.buffer = data;
753 fprintf(stderr, "Getting pack list\n");
755 url = xmalloc(strlen(repo->base) + 21);
756 sprintf(url, "%s/objects/info/packs", repo->base);
758 slot = get_active_slot();
759 curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
760 curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
761 curl_easy_setopt(slot->curl, CURLOPT_URL, url);
762 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL);
763 if (start_active_slot(slot)) {
764 run_active_slot(slot);
765 if (slot->curl_result != CURLE_OK)
766 return error("%s", curl_errorstr);
768 return error("Unable to start request");
771 while (i < buffer.posn) {
775 if (i + 52 < buffer.posn &&
776 !strncmp(data + i, " pack-", 6) &&
777 !strncmp(data + i + 46, ".pack\n", 6)) {
778 get_sha1_hex(data + i + 6, sha1);
779 setup_index(repo, sha1);
784 while (data[i] != '\n')
790 repo->got_indices = 1;
794 static int fetch_pack(struct alt_base *repo, unsigned char *sha1)
797 struct packed_git *target;
798 struct packed_git **lst;
801 char tmpfile[PATH_MAX];
804 char range[RANGE_HEADER_SIZE];
805 struct curl_slist *range_header = NULL;
807 struct active_request_slot *slot;
809 if (fetch_indices(repo))
811 target = find_sha1_pack(sha1, repo->packs);
816 fprintf(stderr, "Getting pack %s\n",
817 sha1_to_hex(target->sha1));
818 fprintf(stderr, " which contains %s\n",
822 url = xmalloc(strlen(repo->base) + 65);
823 sprintf(url, "%s/objects/pack/pack-%s.pack",
824 repo->base, sha1_to_hex(target->sha1));
826 filename = sha1_pack_name(target->sha1);
827 snprintf(tmpfile, sizeof(tmpfile), "%s.temp", filename);
828 packfile = fopen(tmpfile, "a");
830 return error("Unable to open local file %s for pack",
833 slot = get_active_slot();
834 curl_easy_setopt(slot->curl, CURLOPT_FILE, packfile);
835 curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite);
836 curl_easy_setopt(slot->curl, CURLOPT_URL, url);
837 slot->local = packfile;
839 /* If there is data present from a previous transfer attempt,
840 resume where it left off */
841 prev_posn = ftell(packfile);
845 "Resuming fetch of pack %s at byte %ld\n",
846 sha1_to_hex(target->sha1), prev_posn);
847 sprintf(range, "Range: bytes=%ld-", prev_posn);
848 range_header = curl_slist_append(range_header, range);
849 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, range_header);
852 if (start_active_slot(slot)) {
853 run_active_slot(slot);
854 if (slot->curl_result != CURLE_OK) {
856 return error("Unable to get pack file %s\n%s", url,
860 return error("Unable to start request");
865 ret = relink_or_rename(tmpfile, filename);
867 return error("unable to write pack filename %s: %s",
868 filename, strerror(ret));
871 while (*lst != target)
872 lst = &((*lst)->next);
875 if (verify_pack(target, 0))
877 install_packed_git(target);
882 static int fetch_object(struct alt_base *repo, unsigned char *sha1)
884 char *hex = sha1_to_hex(sha1);
886 struct transfer_request *request = request_queue_head;
888 while (request != NULL && memcmp(request->sha1, sha1, 20))
889 request = request->next;
891 return error("Couldn't find request for %s in the queue", hex);
893 #ifdef USE_CURL_MULTI
895 while (request->state == WAITING) {
896 curl_multi_perform(curlm, &num_transfers);
897 if (num_transfers < active_requests) {
898 process_curl_messages();
899 process_request_queue();
903 start_request(request);
906 while (request->state == ACTIVE) {
907 run_active_slot(request->slot);
908 #ifndef USE_CURL_MULTI
909 request->curl_result = request->slot->curl_result;
910 curl_easy_getinfo(request->slot->curl,
912 &request->http_code);
913 request->slot = NULL;
915 /* Use alternates if necessary */
916 if (request->http_code == 404 &&
917 request->repo->next != NULL) {
918 request->repo = request->repo->next;
919 start_request(request);
921 finish_request(request);
922 request->state = COMPLETE;
927 if (request->state == ABORTED) {
928 release_request(request);
929 return error("Request for %s aborted", hex);
932 if (request->curl_result != CURLE_OK && request->http_code != 416) {
933 ret = error("%s", request->errorstr);
934 release_request(request);
938 if (request->zret != Z_STREAM_END) {
939 ret = error("File %s (%s) corrupt\n", hex, request->url);
940 release_request(request);
944 if (memcmp(request->sha1, request->real_sha1, 20)) {
945 release_request(request);
946 return error("File %s has bad hash\n", hex);
949 if (request->rename < 0) {
950 ret = error("unable to write sha1 filename %s: %s",
952 strerror(request->rename));
953 release_request(request);
957 release_request(request);
961 int fetch(unsigned char *sha1)
963 struct alt_base *altbase = alt;
965 if (!fetch_object(altbase, sha1))
968 if (!fetch_pack(altbase, sha1))
970 altbase = altbase->next;
972 return error("Unable to find %s under %s\n", sha1_to_hex(sha1),
976 int fetch_ref(char *ref, unsigned char *sha1)
980 struct buffer buffer;
981 char *base = alt->base;
982 struct active_request_slot *slot;
988 url = xmalloc(strlen(base) + 6 + strlen(ref));
990 posn = url + strlen(base);
991 strcpy(posn, "refs/");
995 slot = get_active_slot();
996 curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
997 curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
998 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL);
999 curl_easy_setopt(slot->curl, CURLOPT_URL, url);
1000 if (start_active_slot(slot)) {
1001 run_active_slot(slot);
1002 if (slot->curl_result != CURLE_OK)
1003 return error("Couldn't get %s for %s\n%s",
1004 url, ref, curl_errorstr);
1006 return error("Unable to start request");
1010 get_sha1_hex(hex, sha1);
1014 int main(int argc, char **argv)
1019 struct active_request_slot *slot;
1021 while (arg < argc && argv[arg][0] == '-') {
1022 if (argv[arg][1] == 't') {
1024 } else if (argv[arg][1] == 'c') {
1026 } else if (argv[arg][1] == 'a') {
1030 } else if (argv[arg][1] == 'v') {
1032 } else if (argv[arg][1] == 'w') {
1033 write_ref = argv[arg + 1];
1035 } else if (!strcmp(argv[arg], "--recover")) {
1040 if (argc < arg + 2) {
1041 usage("git-http-fetch [-c] [-t] [-a] [-d] [-v] [--recover] [-w ref] commit-id url");
1044 commit_id = argv[arg];
1045 url = argv[arg + 1];
1047 curl_global_init(CURL_GLOBAL_ALL);
1049 #ifdef USE_CURL_MULTI
1050 char *http_max_requests = getenv("GIT_HTTP_MAX_REQUESTS");
1051 if (http_max_requests != NULL)
1052 max_requests = atoi(http_max_requests);
1053 if (max_requests < 1)
1054 max_requests = DEFAULT_MAX_REQUESTS;
1056 curlm = curl_multi_init();
1057 if (curlm == NULL) {
1058 fprintf(stderr, "Error creating curl multi handle.\n");
1062 no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
1063 no_range_header = curl_slist_append(no_range_header, "Range:");
1065 curl_default = curl_easy_init();
1067 curl_ssl_verify = getenv("GIT_SSL_NO_VERIFY") ? 0 : 1;
1068 curl_easy_setopt(curl_default, CURLOPT_SSL_VERIFYPEER, curl_ssl_verify);
1069 #if LIBCURL_VERSION_NUM >= 0x070907
1070 curl_easy_setopt(curl_default, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
1073 if ((ssl_cert = getenv("GIT_SSL_CERT")) != NULL) {
1074 curl_easy_setopt(curl_default, CURLOPT_SSLCERT, ssl_cert);
1076 #if LIBCURL_VERSION_NUM >= 0x070902
1077 if ((ssl_key = getenv("GIT_SSL_KEY")) != NULL) {
1078 curl_easy_setopt(curl_default, CURLOPT_SSLKEY, ssl_key);
1081 #if LIBCURL_VERSION_NUM >= 0x070908
1082 if ((ssl_capath = getenv("GIT_SSL_CAPATH")) != NULL) {
1083 curl_easy_setopt(curl_default, CURLOPT_CAPATH, ssl_capath);
1086 if ((ssl_cainfo = getenv("GIT_SSL_CAINFO")) != NULL) {
1087 curl_easy_setopt(curl_default, CURLOPT_CAINFO, ssl_cainfo);
1089 curl_easy_setopt(curl_default, CURLOPT_FAILONERROR, 1);
1091 alt = xmalloc(sizeof(*alt));
1093 alt->got_indices = 0;
1096 fetch_alternates(alt->base);
1098 if (pull(commit_id))
1101 curl_slist_free_all(no_pragma_header);
1102 curl_slist_free_all(no_range_header);
1103 curl_easy_cleanup(curl_default);
1104 slot = active_queue_head;
1105 while (slot != NULL) {
1106 curl_easy_cleanup(slot->curl);
1109 #ifdef USE_CURL_MULTI
1110 curl_multi_cleanup(curlm);
1112 curl_global_cleanup();