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

Function write_lookup_table

pack-bitmap-write.c:1289–1345  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1287}
1288
1289static void write_lookup_table(struct bitmap_writer *writer, struct hashfile *f,
1290 off_t *offsets)
1291{
1292 uint32_t i;
1293 uint32_t *table, *table_inv;
1294
1295 ALLOC_ARRAY(table, bitmap_writer_nr_selected_commits(writer));
1296 ALLOC_ARRAY(table_inv, bitmap_writer_nr_selected_commits(writer));
1297
1298 for (i = 0; i < bitmap_writer_nr_selected_commits(writer); i++)
1299 table[i] = i;
1300
1301 /*
1302 * At the end of this sort table[j] = i means that the i'th
1303 * bitmap corresponds to j'th bitmapped commit (among the selected
1304 * commits) in lex order of OIDs.
1305 */
1306 QSORT_S(table, bitmap_writer_nr_selected_commits(writer), table_cmp, writer);
1307
1308 /* table_inv helps us discover that relationship (i'th bitmap
1309 * to j'th commit by j = table_inv[i])
1310 */
1311 for (i = 0; i < bitmap_writer_nr_selected_commits(writer); i++)
1312 table_inv[table[i]] = i;
1313
1314 trace2_region_enter("pack-bitmap-write", "writing_lookup_table", writer->repo);
1315 for (i = 0; i < bitmap_writer_nr_selected_commits(writer); i++) {
1316 struct bitmapped_commit *selected = &writer->selected[table[i]];
1317 uint32_t xor_offset = selected->xor_offset;
1318 uint32_t xor_row;
1319
1320 if (xor_offset) {
1321 /*
1322 * xor_index stores the index (in the bitmap entries)
1323 * of the corresponding xor bitmap. But we need to convert
1324 * this index into lookup table's index. So, table_inv[xor_index]
1325 * gives us the index position w.r.t. the lookup table.
1326 *
1327 * If "k = table[i] - xor_offset" then the xor base is the k'th
1328 * bitmap. `table_inv[k]` gives us the position of that bitmap
1329 * in the lookup table.
1330 */
1331 uint32_t xor_index = table[i] - xor_offset;
1332 xor_row = table_inv[xor_index];
1333 } else {
1334 xor_row = 0xffffffff;
1335 }
1336
1337 hashwrite_be32(f, writer->selected[table[i]].commit_pos);
1338 hashwrite_be64(f, (uint64_t)offsets[table[i]]);
1339 hashwrite_be32(f, xor_row);
1340 }
1341 trace2_region_leave("pack-bitmap-write", "writing_lookup_table", writer->repo);
1342
1343 free(table);
1344 free(table_inv);
1345}
1346

Callers 1

bitmap_writer_finishFunction · 0.85

Calls 3

hashwrite_be32Function · 0.85
hashwrite_be64Function · 0.85

Tested by

no test coverage detected