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

Function midx_needs_update

midx-write.c:1147–1229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1145}
1146
1147static bool midx_needs_update(struct multi_pack_index *midx, struct write_midx_context *ctx)
1148{
1149 struct strset packs = STRSET_INIT;
1150 struct strbuf buf = STRBUF_INIT;
1151 bool needed = true;
1152
1153 /*
1154 * Ensure that we have a valid checksum before consulting the
1155 * existing MIDX in order to determine if we can avoid an
1156 * update.
1157 *
1158 * This is necessary because the given MIDX is loaded directly
1159 * from the object store (because we still compare our proposed
1160 * update to any on-disk MIDX regardless of whether or not we
1161 * have assigned "ctx.m") and is thus not guaranteed to have a
1162 * valid checksum.
1163 */
1164 if (!midx_checksum_valid(midx))
1165 goto out;
1166
1167 /*
1168 * If the version differs, we need to update.
1169 */
1170 if (midx->version != ctx->version)
1171 goto out;
1172
1173 /*
1174 * Ignore incremental updates for now. The assumption is that any
1175 * incremental update would be either empty (in which case we will bail
1176 * out later) or it would actually cover at least one new pack.
1177 */
1178 if (ctx->incremental)
1179 goto out;
1180
1181 if (ctx->compact)
1182 goto out; /* Compaction always requires an update. */
1183
1184 /*
1185 * Otherwise, we need to verify that the packs covered by the existing
1186 * MIDX match the packs that we already have. The logic to do so is way
1187 * more complicated than it has any right to be. This is because:
1188 *
1189 * - We cannot assume any ordering.
1190 *
1191 * - The MIDX packs may not be loaded at all, and loading them would
1192 * be wasteful. So we need to use the pack names tracked by the
1193 * MIDX itself.
1194 *
1195 * - The MIDX pack names are tracking the ".idx" files, whereas the
1196 * packs themselves are tracking the ".pack" files. So we need to
1197 * strip suffixes.
1198 */
1199 if (ctx->nr != midx->num_packs + midx->num_packs_in_base)
1200 goto out;
1201
1202 for (uint32_t i = 0; i < ctx->nr; i++) {
1203 strbuf_reset(&buf);
1204 strbuf_addstr(&buf, pack_basename(ctx->info[i].p));

Callers 1

write_midx_internalFunction · 0.85

Calls 9

midx_checksum_validFunction · 0.85
strbuf_addstrFunction · 0.85
pack_basenameFunction · 0.85
strbuf_strip_suffixFunction · 0.85
strset_addFunction · 0.85
strset_containsFunction · 0.85
strset_removeFunction · 0.85
strbuf_releaseFunction · 0.85
strset_clearFunction · 0.85

Tested by

no test coverage detected