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 *pragma_header;
33 static struct curl_slist *no_pragma_header;
34 static struct curl_slist *no_range_header;
35 static char curl_errorstr[CURL_ERROR_SIZE];
41 struct packed_git *packs;
42 struct alt_base *next;
45 static struct alt_base *alt = NULL;
54 struct transfer_request
56 unsigned char sha1[20];
57 struct alt_base *repo;
59 char filename[PATH_MAX];
60 char tmpfile[PATH_MAX];
62 enum transfer_state state;
64 char errorstr[CURL_ERROR_SIZE];
66 unsigned char real_sha1[20];
71 struct active_request_slot *slot;
72 struct transfer_request *next;
75 struct active_request_slot
82 struct active_request_slot *next;
85 static struct transfer_request *request_queue_head = NULL;
86 static struct active_request_slot *active_queue_head = NULL;
88 static int curl_ssl_verify;
89 static char *ssl_cert;
91 static char *ssl_capath;
92 static char *ssl_cainfo;
101 static size_t fwrite_buffer(void *ptr, size_t eltsize, size_t nmemb,
102 struct buffer *buffer)
104 size_t size = eltsize * nmemb;
105 if (size > buffer->size - buffer->posn)
106 size = buffer->size - buffer->posn;
107 memcpy(buffer->buffer + buffer->posn, ptr, size);
108 buffer->posn += size;
113 static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
116 unsigned char expn[4096];
117 size_t size = eltsize * nmemb;
119 struct transfer_request *request = (struct transfer_request *)data;
121 ssize_t retval = write(request->local,
122 ptr + posn, size - posn);
126 } while (posn < size);
128 request->stream.avail_in = size;
129 request->stream.next_in = ptr;
131 request->stream.next_out = expn;
132 request->stream.avail_out = sizeof(expn);
133 request->zret = inflate(&request->stream, Z_SYNC_FLUSH);
134 SHA1_Update(&request->c, expn,
135 sizeof(expn) - request->stream.avail_out);
136 } while (request->stream.avail_in && request->zret == Z_OK);
141 #ifdef USE_CURL_MULTI
142 void process_curl_messages();
143 void process_request_queue();
146 struct active_request_slot *get_active_slot()
148 struct active_request_slot *slot = active_queue_head;
149 struct active_request_slot *newslot;
151 #ifdef USE_CURL_MULTI
154 /* Wait for a slot to open up if the queue is full */
155 while (active_requests >= max_requests) {
156 curl_multi_perform(curlm, &num_transfers);
157 if (num_transfers < active_requests) {
158 process_curl_messages();
163 while (slot != NULL && slot->in_use) {
167 newslot = xmalloc(sizeof(*newslot));
168 newslot->curl = curl_easy_duphandle(curl_default);
170 newslot->next = NULL;
172 slot = active_queue_head;
174 active_queue_head = newslot;
176 while (slot->next != NULL) {
179 slot->next = newslot;
188 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, pragma_header);
189 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_range_header);
190 curl_easy_setopt(slot->curl, CURLOPT_ERRORBUFFER, curl_errorstr);
195 int start_active_slot(struct active_request_slot *slot)
197 #ifdef USE_CURL_MULTI
198 CURLMcode curlm_result = curl_multi_add_handle(curlm, slot->curl);
200 if (curlm_result != CURLM_OK &&
201 curlm_result != CURLM_CALL_MULTI_PERFORM) {
210 void run_active_slot(struct active_request_slot *slot)
212 #ifdef USE_CURL_MULTI
220 struct timeval select_timeout;
221 CURLMcode curlm_result;
223 while (!slot->done) {
226 curlm_result = curl_multi_perform(curlm,
228 } while (curlm_result == CURLM_CALL_MULTI_PERFORM);
229 if (num_transfers < active_requests) {
230 process_curl_messages();
231 process_request_queue();
234 if (!data_received && slot->local != NULL) {
235 current_pos = ftell(slot->local);
236 if (current_pos > last_pos)
238 last_pos = current_pos;
241 if (!slot->done && !data_received) {
246 select_timeout.tv_sec = 0;
247 select_timeout.tv_usec = 50000;
248 select(max_fd, &readfds, &writefds,
249 &excfds, &select_timeout);
253 slot->curl_result = curl_easy_perform(slot->curl);
258 void start_request(struct transfer_request *request)
260 char *hex = sha1_to_hex(request->sha1);
261 char prevfile[PATH_MAX];
265 unsigned char prev_buf[PREV_BUF_SIZE];
266 ssize_t prev_read = 0;
268 char range[RANGE_HEADER_SIZE];
269 struct curl_slist *range_header = NULL;
270 struct active_request_slot *slot;
272 snprintf(prevfile, sizeof(prevfile), "%s.prev", request->filename);
274 rename(request->tmpfile, prevfile);
275 unlink(request->tmpfile);
277 request->local = open(request->tmpfile,
278 O_WRONLY | O_CREAT | O_EXCL, 0666);
279 /* This could have failed due to the "lazy directory creation";
280 * try to mkdir the last path component.
282 if (request->local < 0 && errno == ENOENT) {
283 char *dir = strrchr(request->tmpfile, '/');
286 mkdir(request->tmpfile, 0777);
289 request->local = open(request->tmpfile,
290 O_WRONLY | O_CREAT | O_EXCL, 0666);
293 if (request->local < 0) {
294 request->state = ABORTED;
295 error("Couldn't create temporary file %s for %s: %s\n",
296 request->tmpfile, request->filename, strerror(errno));
300 memset(&request->stream, 0, sizeof(request->stream));
302 inflateInit(&request->stream);
304 SHA1_Init(&request->c);
306 url = xmalloc(strlen(request->repo->base) + 50);
307 request->url = xmalloc(strlen(request->repo->base) + 50);
308 strcpy(url, request->repo->base);
309 posn = url + strlen(request->repo->base);
310 strcpy(posn, "objects/");
312 memcpy(posn, hex, 2);
315 strcpy(posn, hex + 2);
316 strcpy(request->url, url);
318 /* If a previous temp file is present, process what was already
320 prevlocal = open(prevfile, O_RDONLY);
321 if (prevlocal != -1) {
323 prev_read = read(prevlocal, prev_buf, PREV_BUF_SIZE);
325 if (fwrite_sha1_file(prev_buf,
328 request) == prev_read) {
329 prev_posn += prev_read;
334 } while (prev_read > 0);
339 /* Reset inflate/SHA1 if there was an error reading the previous temp
340 file; also rewind to the beginning of the local file. */
341 if (prev_read == -1) {
342 memset(&request->stream, 0, sizeof(request->stream));
343 inflateInit(&request->stream);
344 SHA1_Init(&request->c);
347 lseek(request->local, SEEK_SET, 0);
348 ftruncate(request->local, 0);
352 slot = get_active_slot();
353 curl_easy_setopt(slot->curl, CURLOPT_FILE, request);
354 curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_sha1_file);
355 curl_easy_setopt(slot->curl, CURLOPT_ERRORBUFFER, request->errorstr);
356 curl_easy_setopt(slot->curl, CURLOPT_URL, url);
357 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);
359 /* If we have successfully processed data from a previous fetch
360 attempt, only fetch the data we don't already have. */
364 "Resuming fetch of object %s at byte %ld\n",
366 sprintf(range, "Range: bytes=%ld-", prev_posn);
367 range_header = curl_slist_append(range_header, range);
368 curl_easy_setopt(slot->curl,
369 CURLOPT_HTTPHEADER, range_header);
372 /* Try to get the request started, abort the request on error */
373 if (!start_active_slot(slot)) {
374 request->state = ABORTED;
375 close(request->local);
380 request->slot = slot;
381 request->state = ACTIVE;
384 void finish_request(struct transfer_request *request)
386 fchmod(request->local, 0444);
387 close(request->local);
389 if (request->http_code == 416) {
390 fprintf(stderr, "Warning: requested range invalid; we may already have all the data.\n");
391 } else if (request->curl_result != CURLE_OK) {
395 inflateEnd(&request->stream);
396 SHA1_Final(request->real_sha1, &request->c);
397 if (request->zret != Z_STREAM_END) {
398 unlink(request->tmpfile);
401 if (memcmp(request->sha1, request->real_sha1, 20)) {
402 unlink(request->tmpfile);
406 move_temp_to_file(request->tmpfile, request->filename);
408 if (request->rename == 0)
409 pull_say("got %s\n", sha1_to_hex(request->sha1));
412 void release_request(struct transfer_request *request)
414 struct transfer_request *entry = request_queue_head;
416 if (request == request_queue_head) {
417 request_queue_head = request->next;
419 while (entry->next != NULL && entry->next != request)
421 if (entry->next == request)
422 entry->next = entry->next->next;
429 #ifdef USE_CURL_MULTI
430 void process_curl_messages()
433 struct active_request_slot *slot;
434 struct transfer_request *request = NULL;
435 CURLMsg *curl_message = curl_multi_info_read(curlm, &num_messages);
437 while (curl_message != NULL) {
438 if (curl_message->msg == CURLMSG_DONE) {
439 slot = active_queue_head;
440 while (slot != NULL &&
441 slot->curl != curl_message->easy_handle)
444 curl_multi_remove_handle(curlm, slot->curl);
448 slot->curl_result = curl_message->data.result;
449 request = request_queue_head;
450 while (request != NULL &&
451 request->slot != slot)
452 request = request->next;
454 fprintf(stderr, "Received DONE message for unknown request!\n");
456 if (request != NULL) {
457 request->curl_result =
458 curl_message->data.result;
459 curl_easy_getinfo(slot->curl,
461 &request->http_code);
462 request->slot = NULL;
464 /* Use alternates if necessary */
465 if (request->http_code == 404 &&
466 request->repo->next != NULL) {
467 request->repo = request->repo->next;
468 start_request(request);
470 finish_request(request);
471 request->state = COMPLETE;
475 fprintf(stderr, "Unknown CURL message received: %d\n",
476 (int)curl_message->msg);
478 curl_message = curl_multi_info_read(curlm, &num_messages);
482 void process_request_queue()
484 struct transfer_request *request = request_queue_head;
487 while (active_requests < max_requests && request != NULL) {
488 if (request->state == WAITING) {
489 if (has_sha1_file(request->sha1))
490 release_request(request);
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];
541 char range[RANGE_HEADER_SIZE];
542 struct curl_slist *range_header = NULL;
545 struct active_request_slot *slot;
547 if (has_pack_index(sha1))
551 fprintf(stderr, "Getting index for pack %s\n", hex);
553 url = xmalloc(strlen(repo->base) + 64);
554 sprintf(url, "%s/objects/pack/pack-%s.idx", repo->base, hex);
556 filename = sha1_pack_index_name(sha1);
557 snprintf(tmpfile, sizeof(tmpfile), "%s.temp", filename);
558 indexfile = fopen(tmpfile, "a");
560 return error("Unable to open local file %s for pack index",
563 slot = get_active_slot();
564 curl_easy_setopt(slot->curl, CURLOPT_FILE, indexfile);
565 curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite);
566 curl_easy_setopt(slot->curl, CURLOPT_URL, url);
567 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);
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 return move_temp_to_file(tmpfile, filename);
599 static int setup_index(struct alt_base *repo, unsigned char *sha1)
601 struct packed_git *new_pack;
602 if (has_pack_file(sha1))
603 return 0; // don't list this as something we can get
605 if (fetch_index(repo, sha1))
608 new_pack = parse_pack_index(sha1);
609 new_pack->next = repo->packs;
610 repo->packs = new_pack;
614 static int fetch_alternates(char *base)
617 struct buffer buffer;
621 int http_specific = 1;
622 struct alt_base *tail = alt;
624 struct active_request_slot *slot;
627 data = xmalloc(4096);
630 buffer.buffer = data;
633 fprintf(stderr, "Getting alternates list\n");
635 url = xmalloc(strlen(base) + 31);
636 sprintf(url, "%s/objects/info/http-alternates", base);
638 slot = get_active_slot();
639 curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
640 curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
641 curl_easy_setopt(slot->curl, CURLOPT_URL, url);
642 if (start_active_slot(slot)) {
643 run_active_slot(slot);
644 if (slot->curl_result != CURLE_OK || !buffer.posn) {
647 sprintf(url, "%s/objects/info/alternates", base);
649 slot = get_active_slot();
650 curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
651 curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION,
653 curl_easy_setopt(slot->curl, CURLOPT_URL, url);
654 if (start_active_slot(slot)) {
655 run_active_slot(slot);
656 if (slot->curl_result != CURLE_OK) {
665 data[buffer.posn] = '\0';
667 while (i < buffer.posn) {
669 while (posn < buffer.posn && data[posn] != '\n')
671 if (data[posn] == '\n') {
674 struct alt_base *newalt;
676 if (data[i] == '/') {
677 serverlen = strchr(base + 8, '/') - base;
679 } else if (!memcmp(data + i, "../", 3)) {
681 serverlen = strlen(base);
682 while (i + 2 < posn &&
683 !memcmp(data + i, "../", 3)) {
686 } while (serverlen &&
687 base[serverlen - 1] != '/');
690 // If the server got removed, give up.
691 okay = strchr(base, ':') - base + 3 <
693 } else if (http_specific) {
694 char *colon = strchr(data + i, ':');
695 char *slash = strchr(data + i, '/');
696 if (colon && slash && colon < data + posn &&
697 slash < data + posn && colon < slash) {
701 // skip 'objects' at end
703 target = xmalloc(serverlen + posn - i - 6);
704 strncpy(target, base, serverlen);
705 strncpy(target + serverlen, data + i,
707 target[serverlen + posn - i - 7] = '\0';
710 "Also look at %s\n", target);
711 newalt = xmalloc(sizeof(*newalt));
713 newalt->base = target;
714 newalt->got_indices = 0;
715 newalt->packs = NULL;
716 while (tail->next != NULL)
729 static int fetch_indices(struct alt_base *repo)
731 unsigned char sha1[20];
733 struct buffer buffer;
737 struct active_request_slot *slot;
739 if (repo->got_indices)
742 data = xmalloc(4096);
745 buffer.buffer = data;
748 fprintf(stderr, "Getting pack list\n");
750 url = xmalloc(strlen(repo->base) + 21);
751 sprintf(url, "%s/objects/info/packs", repo->base);
753 slot = get_active_slot();
754 curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
755 curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
756 curl_easy_setopt(slot->curl, CURLOPT_URL, url);
757 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL);
758 if (start_active_slot(slot)) {
759 run_active_slot(slot);
760 if (slot->curl_result != CURLE_OK)
761 return error("%s", curl_errorstr);
763 return error("Unable to start request");
766 while (i < buffer.posn) {
770 if (i + 52 < buffer.posn &&
771 !strncmp(data + i, " pack-", 6) &&
772 !strncmp(data + i + 46, ".pack\n", 6)) {
773 get_sha1_hex(data + i + 6, sha1);
774 setup_index(repo, sha1);
779 while (data[i] != '\n')
785 repo->got_indices = 1;
789 static int fetch_pack(struct alt_base *repo, unsigned char *sha1)
792 struct packed_git *target;
793 struct packed_git **lst;
796 char tmpfile[PATH_MAX];
799 char range[RANGE_HEADER_SIZE];
800 struct curl_slist *range_header = NULL;
802 struct active_request_slot *slot;
804 if (fetch_indices(repo))
806 target = find_sha1_pack(sha1, repo->packs);
811 fprintf(stderr, "Getting pack %s\n",
812 sha1_to_hex(target->sha1));
813 fprintf(stderr, " which contains %s\n",
817 url = xmalloc(strlen(repo->base) + 65);
818 sprintf(url, "%s/objects/pack/pack-%s.pack",
819 repo->base, sha1_to_hex(target->sha1));
821 filename = sha1_pack_name(target->sha1);
822 snprintf(tmpfile, sizeof(tmpfile), "%s.temp", filename);
823 packfile = fopen(tmpfile, "a");
825 return error("Unable to open local file %s for pack",
828 slot = get_active_slot();
829 curl_easy_setopt(slot->curl, CURLOPT_FILE, packfile);
830 curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite);
831 curl_easy_setopt(slot->curl, CURLOPT_URL, url);
832 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);
833 slot->local = packfile;
835 /* If there is data present from a previous transfer attempt,
836 resume where it left off */
837 prev_posn = ftell(packfile);
841 "Resuming fetch of pack %s at byte %ld\n",
842 sha1_to_hex(target->sha1), prev_posn);
843 sprintf(range, "Range: bytes=%ld-", prev_posn);
844 range_header = curl_slist_append(range_header, range);
845 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, range_header);
848 if (start_active_slot(slot)) {
849 run_active_slot(slot);
850 if (slot->curl_result != CURLE_OK) {
852 return error("Unable to get pack file %s\n%s", url,
856 return error("Unable to start request");
861 ret = move_temp_to_file(tmpfile, filename);
866 while (*lst != target)
867 lst = &((*lst)->next);
870 if (verify_pack(target, 0))
872 install_packed_git(target);
877 static int fetch_object(struct alt_base *repo, unsigned char *sha1)
879 char *hex = sha1_to_hex(sha1);
881 struct transfer_request *request = request_queue_head;
883 while (request != NULL && memcmp(request->sha1, sha1, 20))
884 request = request->next;
886 return error("Couldn't find request for %s in the queue", hex);
888 if (has_sha1_file(request->sha1)) {
889 release_request(request);
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 pragma_header = curl_slist_append(pragma_header, "Pragma: no-cache");
1063 no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
1064 no_range_header = curl_slist_append(no_range_header, "Range:");
1066 curl_default = curl_easy_init();
1068 curl_ssl_verify = getenv("GIT_SSL_NO_VERIFY") ? 0 : 1;
1069 curl_easy_setopt(curl_default, CURLOPT_SSL_VERIFYPEER, curl_ssl_verify);
1070 #if LIBCURL_VERSION_NUM >= 0x070907
1071 curl_easy_setopt(curl_default, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
1074 if ((ssl_cert = getenv("GIT_SSL_CERT")) != NULL) {
1075 curl_easy_setopt(curl_default, CURLOPT_SSLCERT, ssl_cert);
1077 #if LIBCURL_VERSION_NUM >= 0x070902
1078 if ((ssl_key = getenv("GIT_SSL_KEY")) != NULL) {
1079 curl_easy_setopt(curl_default, CURLOPT_SSLKEY, ssl_key);
1082 #if LIBCURL_VERSION_NUM >= 0x070908
1083 if ((ssl_capath = getenv("GIT_SSL_CAPATH")) != NULL) {
1084 curl_easy_setopt(curl_default, CURLOPT_CAPATH, ssl_capath);
1087 if ((ssl_cainfo = getenv("GIT_SSL_CAINFO")) != NULL) {
1088 curl_easy_setopt(curl_default, CURLOPT_CAINFO, ssl_cainfo);
1090 curl_easy_setopt(curl_default, CURLOPT_FAILONERROR, 1);
1092 alt = xmalloc(sizeof(*alt));
1094 alt->got_indices = 0;
1097 fetch_alternates(alt->base);
1099 if (pull(commit_id))
1102 curl_slist_free_all(pragma_header);
1103 curl_slist_free_all(no_pragma_header);
1104 curl_slist_free_all(no_range_header);
1105 curl_easy_cleanup(curl_default);
1106 slot = active_queue_head;
1107 while (slot != NULL) {
1108 curl_easy_cleanup(slot->curl);
1111 #ifdef USE_CURL_MULTI
1112 curl_multi_cleanup(curlm);
1114 curl_global_cleanup();