8 static int max_requests
= -1;
11 #ifndef NO_CURL_EASY_DUPHANDLE
12 static CURL
*curl_default
;
14 char curl_errorstr
[CURL_ERROR_SIZE
];
16 static int curl_ssl_verify
= -1;
17 static const char *ssl_cert
;
18 #if LIBCURL_VERSION_NUM >= 0x070902
19 static const char *ssl_key
;
21 #if LIBCURL_VERSION_NUM >= 0x070908
22 static const char *ssl_capath
;
24 static const char *ssl_cainfo
;
25 static long curl_low_speed_limit
= -1;
26 static long curl_low_speed_time
= -1;
27 static int curl_ftp_no_epsv
;
28 static const char *curl_http_proxy
;
29 static char *user_name
, *user_pass
;
31 static struct curl_slist
*pragma_header
;
33 struct curl_slist
*no_pragma_header
;
35 static struct active_request_slot
*active_queue_head
;
37 size_t fread_buffer(void *ptr
, size_t eltsize
, size_t nmemb
, void *buffer_
)
39 size_t size
= eltsize
* nmemb
;
40 struct buffer
*buffer
= buffer_
;
42 if (size
> buffer
->buf
.len
- buffer
->posn
)
43 size
= buffer
->buf
.len
- buffer
->posn
;
44 memcpy(ptr
, buffer
->buf
.buf
+ buffer
->posn
, size
);
51 curlioerr
ioctl_buffer(CURL
*handle
, int cmd
, void *clientp
)
53 struct buffer
*buffer
= clientp
;
59 case CURLIOCMD_RESTARTREAD
:
64 return CURLIOE_UNKNOWNCMD
;
69 size_t fwrite_buffer(const void *ptr
, size_t eltsize
, size_t nmemb
, void *buffer_
)
71 size_t size
= eltsize
* nmemb
;
72 struct strbuf
*buffer
= buffer_
;
74 strbuf_add(buffer
, ptr
, size
);
79 size_t fwrite_null(const void *ptr
, size_t eltsize
, size_t nmemb
, void *strbuf
)
82 return eltsize
* nmemb
;
85 static void finish_active_slot(struct active_request_slot
*slot
);
88 static void process_curl_messages(void)
91 struct active_request_slot
*slot
;
92 CURLMsg
*curl_message
= curl_multi_info_read(curlm
, &num_messages
);
94 while (curl_message
!= NULL
) {
95 if (curl_message
->msg
== CURLMSG_DONE
) {
96 int curl_result
= curl_message
->data
.result
;
97 slot
= active_queue_head
;
98 while (slot
!= NULL
&&
99 slot
->curl
!= curl_message
->easy_handle
)
102 curl_multi_remove_handle(curlm
, slot
->curl
);
103 slot
->curl_result
= curl_result
;
104 finish_active_slot(slot
);
106 fprintf(stderr
, "Received DONE message for unknown request!\n");
109 fprintf(stderr
, "Unknown CURL message received: %d\n",
110 (int)curl_message
->msg
);
112 curl_message
= curl_multi_info_read(curlm
, &num_messages
);
117 static int http_options(const char *var
, const char *value
, void *cb
)
119 if (!strcmp("http.sslverify", var
)) {
120 curl_ssl_verify
= git_config_bool(var
, value
);
123 if (!strcmp("http.sslcert", var
))
124 return git_config_string(&ssl_cert
, var
, value
);
125 #if LIBCURL_VERSION_NUM >= 0x070902
126 if (!strcmp("http.sslkey", var
))
127 return git_config_string(&ssl_key
, var
, value
);
129 #if LIBCURL_VERSION_NUM >= 0x070908
130 if (!strcmp("http.sslcapath", var
))
131 return git_config_string(&ssl_capath
, var
, value
);
133 if (!strcmp("http.sslcainfo", var
))
134 return git_config_string(&ssl_cainfo
, var
, value
);
135 #ifdef USE_CURL_MULTI
136 if (!strcmp("http.maxrequests", var
)) {
137 max_requests
= git_config_int(var
, value
);
141 if (!strcmp("http.lowspeedlimit", var
)) {
142 curl_low_speed_limit
= (long)git_config_int(var
, value
);
145 if (!strcmp("http.lowspeedtime", var
)) {
146 curl_low_speed_time
= (long)git_config_int(var
, value
);
150 if (!strcmp("http.noepsv", var
)) {
151 curl_ftp_no_epsv
= git_config_bool(var
, value
);
154 if (!strcmp("http.proxy", var
))
155 return git_config_string(&curl_http_proxy
, var
, value
);
157 /* Fall back on the default ones */
158 return git_default_config(var
, value
, cb
);
161 static void init_curl_http_auth(CURL
*result
)
164 struct strbuf up
= STRBUF_INIT
;
166 user_pass
= xstrdup(getpass("Password: "));
167 strbuf_addf(&up
, "%s:%s", user_name
, user_pass
);
168 curl_easy_setopt(result
, CURLOPT_USERPWD
,
169 strbuf_detach(&up
, NULL
));
173 static CURL
*get_curl_handle(void)
175 CURL
*result
= curl_easy_init();
177 if (!curl_ssl_verify
) {
178 curl_easy_setopt(result
, CURLOPT_SSL_VERIFYPEER
, 0);
179 curl_easy_setopt(result
, CURLOPT_SSL_VERIFYHOST
, 0);
181 /* Verify authenticity of the peer's certificate */
182 curl_easy_setopt(result
, CURLOPT_SSL_VERIFYPEER
, 1);
183 /* The name in the cert must match whom we tried to connect */
184 curl_easy_setopt(result
, CURLOPT_SSL_VERIFYHOST
, 2);
187 #if LIBCURL_VERSION_NUM >= 0x070907
188 curl_easy_setopt(result
, CURLOPT_NETRC
, CURL_NETRC_OPTIONAL
);
191 init_curl_http_auth(result
);
193 if (ssl_cert
!= NULL
)
194 curl_easy_setopt(result
, CURLOPT_SSLCERT
, ssl_cert
);
195 #if LIBCURL_VERSION_NUM >= 0x070902
197 curl_easy_setopt(result
, CURLOPT_SSLKEY
, ssl_key
);
199 #if LIBCURL_VERSION_NUM >= 0x070908
200 if (ssl_capath
!= NULL
)
201 curl_easy_setopt(result
, CURLOPT_CAPATH
, ssl_capath
);
203 if (ssl_cainfo
!= NULL
)
204 curl_easy_setopt(result
, CURLOPT_CAINFO
, ssl_cainfo
);
205 curl_easy_setopt(result
, CURLOPT_FAILONERROR
, 1);
207 if (curl_low_speed_limit
> 0 && curl_low_speed_time
> 0) {
208 curl_easy_setopt(result
, CURLOPT_LOW_SPEED_LIMIT
,
209 curl_low_speed_limit
);
210 curl_easy_setopt(result
, CURLOPT_LOW_SPEED_TIME
,
211 curl_low_speed_time
);
214 curl_easy_setopt(result
, CURLOPT_FOLLOWLOCATION
, 1);
216 if (getenv("GIT_CURL_VERBOSE"))
217 curl_easy_setopt(result
, CURLOPT_VERBOSE
, 1);
219 curl_easy_setopt(result
, CURLOPT_USERAGENT
, GIT_USER_AGENT
);
221 if (curl_ftp_no_epsv
)
222 curl_easy_setopt(result
, CURLOPT_FTP_USE_EPSV
, 0);
225 curl_easy_setopt(result
, CURLOPT_PROXY
, curl_http_proxy
);
230 static void http_auth_init(const char *url
)
232 char *at
, *colon
, *cp
, *slash
;
235 cp
= strstr(url
, "://");
240 * Ok, the URL looks like "proto://something". Which one?
241 * "proto://<user>:<pass>@<host>/...",
242 * "proto://<user>@<host>/...", or just
243 * "proto://<host>/..."?
246 at
= strchr(cp
, '@');
247 colon
= strchr(cp
, ':');
248 slash
= strchrnul(cp
, '/');
249 if (!at
|| slash
<= at
)
250 return; /* No credentials */
251 if (!colon
|| at
<= colon
) {
254 user_name
= xmalloc(len
+ 1);
255 memcpy(user_name
, cp
, len
);
256 user_name
[len
] = '\0';
260 user_name
= xmalloc(len
+ 1);
261 memcpy(user_name
, cp
, len
);
262 user_name
[len
] = '\0';
263 len
= at
- (colon
+ 1);
264 user_pass
= xmalloc(len
+ 1);
265 memcpy(user_pass
, colon
+ 1, len
);
266 user_pass
[len
] = '\0';
270 static void set_from_env(const char **var
, const char *envname
)
272 const char *val
= getenv(envname
);
277 void http_init(struct remote
*remote
)
279 char *low_speed_limit
;
280 char *low_speed_time
;
284 git_config(http_options
, NULL
);
286 curl_global_init(CURL_GLOBAL_ALL
);
288 if (remote
&& remote
->http_proxy
)
289 curl_http_proxy
= xstrdup(remote
->http_proxy
);
291 pragma_header
= curl_slist_append(pragma_header
, "Pragma: no-cache");
292 no_pragma_header
= curl_slist_append(no_pragma_header
, "Pragma:");
294 #ifdef USE_CURL_MULTI
296 char *http_max_requests
= getenv("GIT_HTTP_MAX_REQUESTS");
297 if (http_max_requests
!= NULL
)
298 max_requests
= atoi(http_max_requests
);
301 curlm
= curl_multi_init();
303 fprintf(stderr
, "Error creating curl multi handle.\n");
308 if (getenv("GIT_SSL_NO_VERIFY"))
311 set_from_env(&ssl_cert
, "GIT_SSL_CERT");
312 #if LIBCURL_VERSION_NUM >= 0x070902
313 set_from_env(&ssl_key
, "GIT_SSL_KEY");
315 #if LIBCURL_VERSION_NUM >= 0x070908
316 set_from_env(&ssl_capath
, "GIT_SSL_CAPATH");
318 set_from_env(&ssl_cainfo
, "GIT_SSL_CAINFO");
320 low_speed_limit
= getenv("GIT_HTTP_LOW_SPEED_LIMIT");
321 if (low_speed_limit
!= NULL
)
322 curl_low_speed_limit
= strtol(low_speed_limit
, NULL
, 10);
323 low_speed_time
= getenv("GIT_HTTP_LOW_SPEED_TIME");
324 if (low_speed_time
!= NULL
)
325 curl_low_speed_time
= strtol(low_speed_time
, NULL
, 10);
327 if (curl_ssl_verify
== -1)
330 #ifdef USE_CURL_MULTI
331 if (max_requests
< 1)
332 max_requests
= DEFAULT_MAX_REQUESTS
;
335 if (getenv("GIT_CURL_FTP_NO_EPSV"))
336 curl_ftp_no_epsv
= 1;
338 if (remote
&& remote
->url
&& remote
->url
[0])
339 http_auth_init(remote
->url
[0]);
341 #ifndef NO_CURL_EASY_DUPHANDLE
342 curl_default
= get_curl_handle();
346 void http_cleanup(void)
348 struct active_request_slot
*slot
= active_queue_head
;
350 while (slot
!= NULL
) {
351 struct active_request_slot
*next
= slot
->next
;
352 if (slot
->curl
!= NULL
) {
353 #ifdef USE_CURL_MULTI
354 curl_multi_remove_handle(curlm
, slot
->curl
);
356 curl_easy_cleanup(slot
->curl
);
361 active_queue_head
= NULL
;
363 #ifndef NO_CURL_EASY_DUPHANDLE
364 curl_easy_cleanup(curl_default
);
367 #ifdef USE_CURL_MULTI
368 curl_multi_cleanup(curlm
);
370 curl_global_cleanup();
372 curl_slist_free_all(pragma_header
);
373 pragma_header
= NULL
;
375 curl_slist_free_all(no_pragma_header
);
376 no_pragma_header
= NULL
;
378 if (curl_http_proxy
) {
379 free((void *)curl_http_proxy
);
380 curl_http_proxy
= NULL
;
384 struct active_request_slot
*get_active_slot(void)
386 struct active_request_slot
*slot
= active_queue_head
;
387 struct active_request_slot
*newslot
;
389 #ifdef USE_CURL_MULTI
392 /* Wait for a slot to open up if the queue is full */
393 while (active_requests
>= max_requests
) {
394 curl_multi_perform(curlm
, &num_transfers
);
395 if (num_transfers
< active_requests
)
396 process_curl_messages();
400 while (slot
!= NULL
&& slot
->in_use
)
404 newslot
= xmalloc(sizeof(*newslot
));
405 newslot
->curl
= NULL
;
407 newslot
->next
= NULL
;
409 slot
= active_queue_head
;
411 active_queue_head
= newslot
;
413 while (slot
->next
!= NULL
)
415 slot
->next
= newslot
;
420 if (slot
->curl
== NULL
) {
421 #ifdef NO_CURL_EASY_DUPHANDLE
422 slot
->curl
= get_curl_handle();
424 slot
->curl
= curl_easy_duphandle(curl_default
);
431 slot
->results
= NULL
;
432 slot
->finished
= NULL
;
433 slot
->callback_data
= NULL
;
434 slot
->callback_func
= NULL
;
435 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPHEADER
, pragma_header
);
436 curl_easy_setopt(slot
->curl
, CURLOPT_ERRORBUFFER
, curl_errorstr
);
437 curl_easy_setopt(slot
->curl
, CURLOPT_CUSTOMREQUEST
, NULL
);
438 curl_easy_setopt(slot
->curl
, CURLOPT_READFUNCTION
, NULL
);
439 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEFUNCTION
, NULL
);
440 curl_easy_setopt(slot
->curl
, CURLOPT_UPLOAD
, 0);
441 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPGET
, 1);
446 int start_active_slot(struct active_request_slot
*slot
)
448 #ifdef USE_CURL_MULTI
449 CURLMcode curlm_result
= curl_multi_add_handle(curlm
, slot
->curl
);
452 if (curlm_result
!= CURLM_OK
&&
453 curlm_result
!= CURLM_CALL_MULTI_PERFORM
) {
460 * We know there must be something to do, since we just added
463 curl_multi_perform(curlm
, &num_transfers
);
468 #ifdef USE_CURL_MULTI
472 struct fill_chain
*next
;
475 static struct fill_chain
*fill_cfg
;
477 void add_fill_function(void *data
, int (*fill
)(void *))
479 struct fill_chain
*new = xmalloc(sizeof(*new));
480 struct fill_chain
**linkp
= &fill_cfg
;
485 linkp
= &(*linkp
)->next
;
489 void fill_active_slots(void)
491 struct active_request_slot
*slot
= active_queue_head
;
493 while (active_requests
< max_requests
) {
494 struct fill_chain
*fill
;
495 for (fill
= fill_cfg
; fill
; fill
= fill
->next
)
496 if (fill
->fill(fill
->data
))
503 while (slot
!= NULL
) {
504 if (!slot
->in_use
&& slot
->curl
!= NULL
) {
505 curl_easy_cleanup(slot
->curl
);
512 void step_active_slots(void)
515 CURLMcode curlm_result
;
518 curlm_result
= curl_multi_perform(curlm
, &num_transfers
);
519 } while (curlm_result
== CURLM_CALL_MULTI_PERFORM
);
520 if (num_transfers
< active_requests
) {
521 process_curl_messages();
527 void run_active_slot(struct active_request_slot
*slot
)
529 #ifdef USE_CURL_MULTI
536 struct timeval select_timeout
;
539 slot
->finished
= &finished
;
544 if (!data_received
&& slot
->local
!= NULL
) {
545 current_pos
= ftell(slot
->local
);
546 if (current_pos
> last_pos
)
548 last_pos
= current_pos
;
551 if (slot
->in_use
&& !data_received
) {
556 select_timeout
.tv_sec
= 0;
557 select_timeout
.tv_usec
= 50000;
558 select(max_fd
, &readfds
, &writefds
,
559 &excfds
, &select_timeout
);
563 while (slot
->in_use
) {
564 slot
->curl_result
= curl_easy_perform(slot
->curl
);
565 finish_active_slot(slot
);
570 static void closedown_active_slot(struct active_request_slot
*slot
)
576 void release_active_slot(struct active_request_slot
*slot
)
578 closedown_active_slot(slot
);
580 #ifdef USE_CURL_MULTI
581 curl_multi_remove_handle(curlm
, slot
->curl
);
583 curl_easy_cleanup(slot
->curl
);
586 #ifdef USE_CURL_MULTI
591 static void finish_active_slot(struct active_request_slot
*slot
)
593 closedown_active_slot(slot
);
594 curl_easy_getinfo(slot
->curl
, CURLINFO_HTTP_CODE
, &slot
->http_code
);
596 if (slot
->finished
!= NULL
)
597 (*slot
->finished
) = 1;
599 /* Store slot results so they can be read after the slot is reused */
600 if (slot
->results
!= NULL
) {
601 slot
->results
->curl_result
= slot
->curl_result
;
602 slot
->results
->http_code
= slot
->http_code
;
605 /* Run callback if appropriate */
606 if (slot
->callback_func
!= NULL
)
607 slot
->callback_func(slot
->callback_data
);
610 void finish_all_active_slots(void)
612 struct active_request_slot
*slot
= active_queue_head
;
616 run_active_slot(slot
);
617 slot
= active_queue_head
;
623 /* Helpers for modifying and creating URLs */
624 static inline int needs_quote(int ch
)
626 if (((ch
>= 'A') && (ch
<= 'Z'))
627 || ((ch
>= 'a') && (ch
<= 'z'))
628 || ((ch
>= '0') && (ch
<= '9'))
636 static inline int hex(int v
)
644 static void end_url_with_slash(struct strbuf
*buf
, const char *url
)
646 strbuf_addstr(buf
, url
);
647 if (buf
->len
&& buf
->buf
[buf
->len
- 1] != '/')
648 strbuf_addstr(buf
, "/");
651 static char *quote_ref_url(const char *base
, const char *ref
)
653 struct strbuf buf
= STRBUF_INIT
;
657 end_url_with_slash(&buf
, base
);
659 for (cp
= ref
; (ch
= *cp
) != 0; cp
++)
661 strbuf_addf(&buf
, "%%%02x", ch
);
663 strbuf_addch(&buf
, *cp
);
665 return strbuf_detach(&buf
, NULL
);
668 /* http_request() targets */
669 #define HTTP_REQUEST_STRBUF 0
670 #define HTTP_REQUEST_FILE 1
672 static int http_request(const char *url
, void *result
, int target
, int options
)
674 struct active_request_slot
*slot
;
675 struct slot_results results
;
676 struct curl_slist
*headers
= NULL
;
677 struct strbuf buf
= STRBUF_INIT
;
680 slot
= get_active_slot();
681 slot
->results
= &results
;
682 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPGET
, 1);
684 if (result
== NULL
) {
685 curl_easy_setopt(slot
->curl
, CURLOPT_NOBODY
, 1);
687 curl_easy_setopt(slot
->curl
, CURLOPT_NOBODY
, 0);
688 curl_easy_setopt(slot
->curl
, CURLOPT_FILE
, result
);
690 if (target
== HTTP_REQUEST_FILE
) {
691 long posn
= ftell(result
);
692 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEFUNCTION
,
695 strbuf_addf(&buf
, "Range: bytes=%ld-", posn
);
696 headers
= curl_slist_append(headers
, buf
.buf
);
699 slot
->local
= result
;
701 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEFUNCTION
,
705 strbuf_addstr(&buf
, "Pragma:");
706 if (options
& HTTP_NO_CACHE
)
707 strbuf_addstr(&buf
, " no-cache");
709 headers
= curl_slist_append(headers
, buf
.buf
);
711 curl_easy_setopt(slot
->curl
, CURLOPT_URL
, url
);
712 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPHEADER
, headers
);
714 if (start_active_slot(slot
)) {
715 run_active_slot(slot
);
716 if (results
.curl_result
== CURLE_OK
)
718 else if (missing_target(&results
))
719 ret
= HTTP_MISSING_TARGET
;
723 error("Unable to start HTTP request for %s", url
);
724 ret
= HTTP_START_FAILED
;
728 curl_slist_free_all(headers
);
729 strbuf_release(&buf
);
734 int http_get_strbuf(const char *url
, struct strbuf
*result
, int options
)
736 return http_request(url
, result
, HTTP_REQUEST_STRBUF
, options
);
739 int http_get_file(const char *url
, const char *filename
, int options
)
742 struct strbuf tmpfile
= STRBUF_INIT
;
745 strbuf_addf(&tmpfile
, "%s.temp", filename
);
746 result
= fopen(tmpfile
.buf
, "a");
748 error("Unable to open local file %s", tmpfile
.buf
);
753 ret
= http_request(url
, result
, HTTP_REQUEST_FILE
, options
);
756 if ((ret
== HTTP_OK
) && move_temp_to_file(tmpfile
.buf
, filename
))
759 strbuf_release(&tmpfile
);
763 int http_error(const char *url
, int ret
)
765 /* http_request has already handled HTTP_START_FAILED. */
766 if (ret
!= HTTP_START_FAILED
)
767 error("%s while accessing %s\n", curl_errorstr
, url
);
772 int http_fetch_ref(const char *base
, struct ref
*ref
)
775 struct strbuf buffer
= STRBUF_INIT
;
778 url
= quote_ref_url(base
, ref
->name
);
779 if (http_get_strbuf(url
, &buffer
, HTTP_NO_CACHE
) == HTTP_OK
) {
780 strbuf_rtrim(&buffer
);
781 if (buffer
.len
== 40)
782 ret
= get_sha1_hex(buffer
.buf
, ref
->old_sha1
);
783 else if (!prefixcmp(buffer
.buf
, "ref: ")) {
784 ref
->symref
= xstrdup(buffer
.buf
+ 5);
789 strbuf_release(&buffer
);
794 /* Helpers for fetching packs */
795 static int fetch_pack_index(unsigned char *sha1
, const char *base_url
)
798 char *hex
= xstrdup(sha1_to_hex(sha1
));
801 char tmpfile
[PATH_MAX
];
803 char range
[RANGE_HEADER_SIZE
];
804 struct strbuf buf
= STRBUF_INIT
;
805 struct curl_slist
*range_header
= NULL
;
808 struct active_request_slot
*slot
;
809 struct slot_results results
;
811 /* Don't use the index if the pack isn't there */
812 end_url_with_slash(&buf
, base_url
);
813 strbuf_addf(&buf
, "objects/pack/pack-%s.pack", hex
);
814 url
= strbuf_detach(&buf
, 0);
816 slot
= get_active_slot();
817 slot
->results
= &results
;
818 curl_easy_setopt(slot
->curl
, CURLOPT_URL
, url
);
819 curl_easy_setopt(slot
->curl
, CURLOPT_NOBODY
, 1);
820 if (start_active_slot(slot
)) {
821 run_active_slot(slot
);
822 if (results
.curl_result
!= CURLE_OK
) {
823 ret
= error("Unable to verify pack %s is available",
828 ret
= error("Unable to start request");
832 if (has_pack_index(sha1
)) {
838 fprintf(stderr
, "Getting index for pack %s\n", hex
);
840 end_url_with_slash(&buf
, base_url
);
841 strbuf_addf(&buf
, "objects/pack/pack-%s.idx", hex
);
842 url
= strbuf_detach(&buf
, NULL
);
844 filename
= sha1_pack_index_name(sha1
);
845 snprintf(tmpfile
, sizeof(tmpfile
), "%s.temp", filename
);
846 indexfile
= fopen(tmpfile
, "a");
848 ret
= error("Unable to open local file %s for pack index",
853 slot
= get_active_slot();
854 slot
->results
= &results
;
855 curl_easy_setopt(slot
->curl
, CURLOPT_NOBODY
, 0);
856 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPGET
, 1);
857 curl_easy_setopt(slot
->curl
, CURLOPT_FILE
, indexfile
);
858 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEFUNCTION
, fwrite
);
859 curl_easy_setopt(slot
->curl
, CURLOPT_URL
, url
);
860 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPHEADER
, no_pragma_header
);
861 slot
->local
= indexfile
;
864 * If there is data present from a previous transfer attempt,
865 * resume where it left off
867 prev_posn
= ftell(indexfile
);
871 "Resuming fetch of index for pack %s at byte %ld\n",
873 sprintf(range
, "Range: bytes=%ld-", prev_posn
);
874 range_header
= curl_slist_append(range_header
, range
);
875 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPHEADER
, range_header
);
878 if (start_active_slot(slot
)) {
879 run_active_slot(slot
);
880 if (results
.curl_result
!= CURLE_OK
) {
881 ret
= error("Unable to get pack index %s\n%s",
886 ret
= error("Unable to start request");
890 ret
= move_temp_to_file(tmpfile
, filename
);
901 static int fetch_and_setup_pack_index(struct packed_git
**packs_head
,
902 unsigned char *sha1
, const char *base_url
)
904 struct packed_git
*new_pack
;
906 if (fetch_pack_index(sha1
, base_url
))
909 new_pack
= parse_pack_index(sha1
);
911 return -1; /* parse_pack_index() already issued error message */
912 new_pack
->next
= *packs_head
;
913 *packs_head
= new_pack
;
917 int http_get_info_packs(const char *base_url
, struct packed_git
**packs_head
)
921 struct strbuf buf
= STRBUF_INIT
;
922 unsigned char sha1
[20];
924 end_url_with_slash(&buf
, base_url
);
925 strbuf_addstr(&buf
, "objects/info/packs");
926 url
= strbuf_detach(&buf
, NULL
);
928 ret
= http_get_strbuf(url
, &buf
, HTTP_NO_CACHE
);
933 while (i
< buf
.len
) {
937 if (i
+ 52 <= buf
.len
&&
938 !prefixcmp(data
+ i
, " pack-") &&
939 !prefixcmp(data
+ i
+ 46, ".pack\n")) {
940 get_sha1_hex(data
+ i
+ 6, sha1
);
941 fetch_and_setup_pack_index(packs_head
, sha1
,
947 while (i
< buf
.len
&& data
[i
] != '\n')