| 342 | } |
| 343 | |
| 344 | static void fetch_alternates(struct walker *walker, const char *base) |
| 345 | { |
| 346 | struct strbuf buffer = STRBUF_INIT; |
| 347 | struct strbuf url = STRBUF_INIT; |
| 348 | struct active_request_slot *slot; |
| 349 | struct alternates_request alt_req; |
| 350 | struct walker_data *cdata = walker->data; |
| 351 | |
| 352 | /* |
| 353 | * If another request has already started fetching alternates, |
| 354 | * wait for them to arrive and return to processing this request's |
| 355 | * curl message |
| 356 | */ |
| 357 | while (cdata->got_alternates == 0) { |
| 358 | step_active_slots(); |
| 359 | } |
| 360 | |
| 361 | /* Nothing to do if they've already been fetched */ |
| 362 | if (cdata->got_alternates == 1) |
| 363 | return; |
| 364 | |
| 365 | /* Start the fetch */ |
| 366 | cdata->got_alternates = 0; |
| 367 | |
| 368 | if (walker->get_verbosely) |
| 369 | fprintf(stderr, "Getting alternates list for %s\n", base); |
| 370 | |
| 371 | strbuf_addf(&url, "%s/objects/info/http-alternates", base); |
| 372 | |
| 373 | /* |
| 374 | * Use a callback to process the result, since another request |
| 375 | * may fail and need to have alternates loaded before continuing |
| 376 | */ |
| 377 | slot = get_active_slot(); |
| 378 | slot->callback_func = process_alternates_response; |
| 379 | alt_req.walker = walker; |
| 380 | slot->callback_data = &alt_req; |
| 381 | |
| 382 | curl_easy_setopt(slot->curl, CURLOPT_WRITEDATA, &buffer); |
| 383 | curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer); |
| 384 | curl_easy_setopt(slot->curl, CURLOPT_URL, url.buf); |
| 385 | |
| 386 | alt_req.base = base; |
| 387 | alt_req.url = &url; |
| 388 | alt_req.buffer = &buffer; |
| 389 | alt_req.http_specific = 1; |
| 390 | alt_req.slot = slot; |
| 391 | |
| 392 | if (start_active_slot(slot)) |
| 393 | run_active_slot(slot); |
| 394 | else |
| 395 | cdata->got_alternates = -1; |
| 396 | |
| 397 | strbuf_release(&buffer); |
| 398 | strbuf_release(&url); |
| 399 | } |
| 400 | |
| 401 | static int fetch_indices(struct walker *walker, struct alt_base *repo) |
no test coverage detected