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

Function write_midx_internal

midx-write.c:1254–1848  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1252};
1253
1254static 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) {

Callers 5

write_midx_fileFunction · 0.85
write_midx_file_onlyFunction · 0.85
write_midx_file_compactFunction · 0.85
expire_midx_packsFunction · 0.85
midx_repackFunction · 0.85

Calls 15

repo_config_get_intFunction · 0.85
strbuf_addfFunction · 0.85
get_midx_filenameFunction · 0.85
die_errnoFunction · 0.85
get_multi_pack_indexFunction · 0.85
midx_checksum_validFunction · 0.85
warningFunction · 0.85
midx_get_checksum_hexFunction · 0.85
errorFunction · 0.85
load_midx_revindexFunction · 0.85
fill_packs_from_midxFunction · 0.85

Tested by

no test coverage detected