MCPcopy Index your code
hub / github.com/git/git / fetch_pack_index

Function fetch_pack_index

http.c:2551–2589  ·  view source on GitHub ↗

Helpers for fetching packs */

Source from the content-addressed store, hash-verified

2549
2550/* Helpers for fetching packs */
2551static char *fetch_pack_index(unsigned char *hash, const char *base_url)
2552{
2553 char *url, *tmp;
2554 struct strbuf buf = STRBUF_INIT;
2555
2556 if (http_is_verbose)
2557 fprintf(stderr, "Getting index for pack %s\n", hash_to_hex(hash));
2558
2559 end_url_with_slash(&buf, base_url);
2560 strbuf_addf(&buf, "objects/pack/pack-%s.idx", hash_to_hex(hash));
2561 url = strbuf_detach(&buf, NULL);
2562
2563 /*
2564 * Don't put this into packs/, since it's just temporary and we don't
2565 * want to confuse it with our local .idx files. We'll generate our
2566 * own index if we choose to download the matching packfile.
2567 *
2568 * It's tempting to use xmks_tempfile() here, but it's important that
2569 * the file not exist, otherwise http_get_file() complains. So we
2570 * create a filename that should be unique, and then just register it
2571 * as a tempfile so that it will get cleaned up on exit.
2572 *
2573 * In theory we could hold on to the tempfile and delete these as soon
2574 * as we download the matching pack, but it would take a bit of
2575 * refactoring. Leaving them until the process ends is probably OK.
2576 */
2577 tmp = xstrfmt("%s/tmp_pack_%s.idx",
2578 repo_get_object_directory(the_repository),
2579 hash_to_hex(hash));
2580 register_tempfile(tmp);
2581
2582 if (http_get_file(url, tmp, NULL) != HTTP_OK) {
2583 error("Unable to get pack index %s", url);
2584 FREE_AND_NULL(tmp);
2585 }
2586
2587 free(url);
2588 return tmp;
2589}
2590
2591static int fetch_and_setup_pack_index(struct packfile_list *packs,
2592 unsigned char *sha1,

Callers 1

Calls 9

hash_to_hexFunction · 0.85
end_url_with_slashFunction · 0.85
strbuf_addfFunction · 0.85
strbuf_detachFunction · 0.85
xstrfmtFunction · 0.85
register_tempfileFunction · 0.85
http_get_fileFunction · 0.85
errorFunction · 0.85

Tested by

no test coverage detected