| 1252 | }; |
| 1253 | |
| 1254 | static int write_midx_internal(struct write_midx_opts *opts) |
| 1255 | { |
| 1256 | struct repository *r = opts->source->odb->repo; |
| 1257 | struct strbuf midx_name = STRBUF_INIT; |
| 1258 | unsigned char midx_hash[GIT_MAX_RAWSZ]; |
| 1259 | uint32_t start_pack; |
| 1260 | struct hashfile *f = NULL; |
| 1261 | struct lock_file lk = LOCK_INIT; |
| 1262 | struct tempfile *incr; |
| 1263 | struct write_midx_context ctx = { |
| 1264 | .preferred_pack_idx = NO_PREFERRED_PACK, |
| 1265 | }; |
| 1266 | struct multi_pack_index *midx_to_free = NULL; |
| 1267 | int bitmapped_packs_concat_len = 0; |
| 1268 | int pack_name_concat_len = 0; |
| 1269 | int dropped_packs = 0; |
| 1270 | int result = -1; |
| 1271 | struct strvec keep_hashes = STRVEC_INIT; |
| 1272 | struct chunkfile *cf; |
| 1273 | |
| 1274 | trace2_region_enter("midx", "write_midx_internal", r); |
| 1275 | |
| 1276 | ctx.repo = r; |
| 1277 | ctx.source = opts->source; |
| 1278 | |
| 1279 | ctx.version = ((opts->flags & MIDX_WRITE_COMPACT) |
| 1280 | ? MIDX_VERSION_V2 |
| 1281 | : MIDX_VERSION_V1); |
| 1282 | repo_config_get_int(ctx.repo, "midx.version", &ctx.version); |
| 1283 | if (ctx.version != MIDX_VERSION_V1 && ctx.version != MIDX_VERSION_V2) |
| 1284 | die(_("unknown MIDX version: %d"), ctx.version); |
| 1285 | |
| 1286 | ctx.incremental = !!(opts->flags & MIDX_WRITE_INCREMENTAL); |
| 1287 | ctx.compact = !!(opts->flags & MIDX_WRITE_COMPACT); |
| 1288 | |
| 1289 | if (ctx.compact) { |
| 1290 | if (ctx.version != MIDX_VERSION_V2) |
| 1291 | die(_("cannot perform MIDX compaction with v1 format")); |
| 1292 | if (!opts->compact_from) |
| 1293 | BUG("expected non-NULL 'from' MIDX during compaction"); |
| 1294 | if (!opts->compact_to) |
| 1295 | BUG("expected non-NULL 'to' MIDX during compaction"); |
| 1296 | |
| 1297 | ctx.compact_from = opts->compact_from; |
| 1298 | ctx.compact_to = opts->compact_to; |
| 1299 | } |
| 1300 | |
| 1301 | if (ctx.incremental) |
| 1302 | strbuf_addf(&midx_name, |
| 1303 | "%s/pack/multi-pack-index.d/tmp_midx_XXXXXX", |
| 1304 | opts->source->path); |
| 1305 | else |
| 1306 | get_midx_filename(opts->source, &midx_name); |
| 1307 | if (safe_create_leading_directories(r, midx_name.buf)) |
| 1308 | die_errno(_("unable to create leading directories of %s"), |
| 1309 | midx_name.buf); |
| 1310 | |
| 1311 | if (!opts->packs_to_include || ctx.incremental) { |
no test coverage detected