MCPcopy Create free account
hub / github.com/git/git / unbundle_from_file

Function unbundle_from_file

bundle-uri.c:402–463  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

400}
401
402static int unbundle_from_file(struct repository *r, const char *file)
403{
404 int result = 0;
405 int bundle_fd;
406 struct bundle_header header = BUNDLE_HEADER_INIT;
407 struct string_list_item *refname;
408 struct strbuf bundle_ref = STRBUF_INIT;
409 size_t bundle_prefix_len;
410 struct unbundle_opts opts = {
411 .flags = VERIFY_BUNDLE_QUIET |
412 (fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0),
413 };
414
415 bundle_fd = read_bundle_header(file, &header);
416 if (bundle_fd < 0) {
417 result = 1;
418 goto cleanup;
419 }
420
421 /*
422 * Skip the reachability walk here, since we will be adding
423 * a reachable ref pointing to the new tips, which will reach
424 * the prerequisite commits.
425 */
426 result = unbundle(r, &header, bundle_fd, NULL, &opts);
427 if (result) {
428 result = 1;
429 goto cleanup;
430 }
431
432 /*
433 * Convert all refs/heads/ from the bundle into refs/bundles/
434 * in the local repository.
435 */
436 strbuf_addstr(&bundle_ref, "refs/bundles/");
437 bundle_prefix_len = bundle_ref.len;
438
439 for_each_string_list_item(refname, &header.references) {
440 struct object_id *oid = refname->util;
441 struct object_id old_oid;
442 const char *branch_name;
443 int has_old;
444
445 if (!skip_prefix(refname->string, "refs/", &branch_name))
446 continue;
447
448 strbuf_setlen(&bundle_ref, bundle_prefix_len);
449 strbuf_addstr(&bundle_ref, branch_name);
450
451 has_old = !refs_read_ref(get_main_ref_store(the_repository),
452 bundle_ref.buf, &old_oid);
453 refs_update_ref(get_main_ref_store(the_repository),
454 "fetched bundle", bundle_ref.buf, oid,
455 has_old ? &old_oid : NULL,
456 0, UPDATE_REFS_MSG_ON_ERR);
457 }
458
459cleanup:

Callers 2

fetch_bundles_by_tokenFunction · 0.85
attempt_unbundleFunction · 0.85

Calls 10

fetch_pack_fsck_objectsFunction · 0.85
read_bundle_headerFunction · 0.85
unbundleFunction · 0.85
strbuf_addstrFunction · 0.85
strbuf_setlenFunction · 0.85
refs_read_refFunction · 0.85
get_main_ref_storeFunction · 0.85
refs_update_refFunction · 0.85
strbuf_releaseFunction · 0.85
bundle_header_releaseFunction · 0.85

Tested by

no test coverage detected