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

Function write_midx_incremental

repack-midx.c:939–1008  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

937}
938
939static int write_midx_incremental(struct repack_write_midx_opts *opts)
940{
941 struct midx_compaction_step *steps = NULL;
942 struct strbuf lock_name = STRBUF_INIT;
943 struct lock_file lf;
944 struct strvec keep_hashes = STRVEC_INIT;
945 size_t steps_nr = 0;
946 size_t i;
947 int ret = 0;
948
949 get_midx_chain_filename(opts->existing->source, &lock_name);
950 if (safe_create_leading_directories(opts->existing->repo,
951 lock_name.buf))
952 die_errno(_("unable to create leading directories of %s"),
953 lock_name.buf);
954 hold_lock_file_for_update(&lf, lock_name.buf, LOCK_DIE_ON_ERROR);
955
956 if (!fdopen_lock_file(&lf, "w")) {
957 ret = error_errno(_("unable to open multi-pack-index chain file"));
958 goto done;
959 }
960
961 if (opts->geometry->split_factor) {
962 if (repack_make_midx_compaction_plan(opts, &steps, &steps_nr) < 0) {
963 ret = error(_("unable to generate compaction plan"));
964 goto done;
965 }
966 } else {
967 repack_make_midx_append_plan(opts, &steps, &steps_nr);
968 }
969
970 for (i = 0; i < steps_nr; i++) {
971 struct midx_compaction_step *step = &steps[i];
972 char *base = NULL;
973
974 if (i + 1 < steps_nr)
975 base = xstrdup(midx_compaction_step_base(&steps[i + 1]));
976
977 if (midx_compaction_step_exec(step, opts, base) < 0) {
978 ret = error(_("unable to execute compaction step %"PRIuMAX),
979 (uintmax_t)i);
980 free(base);
981 goto done;
982 }
983
984 free(base);
985 }
986
987 i = steps_nr;
988 while (i--) {
989 struct midx_compaction_step *step = &steps[i];
990 if (!step->csum)
991 BUG("missing result for compaction step %"PRIuMAX,
992 (uintmax_t)i);
993 fprintf(get_lock_file_fp(&lf), "%s\n", step->csum);
994 strvec_push(&keep_hashes, step->csum);
995 }
996

Callers 1

repack_write_midxFunction · 0.85

Calls 15

get_midx_chain_filenameFunction · 0.85
die_errnoFunction · 0.85
fdopen_lock_fileFunction · 0.85
error_errnoFunction · 0.85
errorFunction · 0.85
xstrdupFunction · 0.85

Tested by

no test coverage detected