| 937 | } |
| 938 | |
| 939 | static 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 |
no test coverage detected