* This writes the specified object to a packfile. Objects written here * during the same transaction are written to the same packfile. The * packfile is not flushed until the transaction is flushed. The caller * is expected to ensure a valid transaction is setup for objects to be * recorded to. * * This also bypasses the usual "convert-to-git" dance, and that is on * purpose. We could write
| 1297 | * callers should avoid this code path when filters are requested. |
| 1298 | */ |
| 1299 | static int odb_transaction_files_write_object_stream(struct odb_transaction *base, |
| 1300 | struct odb_write_stream *stream, |
| 1301 | size_t size, |
| 1302 | struct object_id *result_oid) |
| 1303 | { |
| 1304 | struct odb_transaction_files *transaction = container_of(base, |
| 1305 | struct odb_transaction_files, |
| 1306 | base); |
| 1307 | struct transaction_packfile *state = &transaction->packfile; |
| 1308 | struct git_hash_ctx ctx; |
| 1309 | unsigned char obuf[16384]; |
| 1310 | unsigned header_len; |
| 1311 | struct hashfile_checkpoint checkpoint; |
| 1312 | struct pack_idx_entry *idx; |
| 1313 | |
| 1314 | header_len = format_object_header((char *)obuf, sizeof(obuf), |
| 1315 | OBJ_BLOB, size); |
| 1316 | transaction->base.source->odb->repo->hash_algo->init_fn(&ctx); |
| 1317 | git_hash_update(&ctx, obuf, header_len); |
| 1318 | |
| 1319 | /* |
| 1320 | * If writing another object to the packfile could result in it |
| 1321 | * exceeding the configured size limit, flush the current packfile |
| 1322 | * transaction. |
| 1323 | * |
| 1324 | * Note that this uses the inflated object size as an approximation. |
| 1325 | * Blob objects written in this manner are not delta-compressed, so |
| 1326 | * the difference between the inflated and on-disk size is limited |
| 1327 | * to zlib compression and is sufficient for this check. |
| 1328 | */ |
| 1329 | if (state->nr_written && pack_size_limit_cfg && |
| 1330 | pack_size_limit_cfg < state->offset + size) |
| 1331 | flush_packfile_transaction(transaction); |
| 1332 | |
| 1333 | CALLOC_ARRAY(idx, 1); |
| 1334 | prepare_packfile_transaction(transaction); |
| 1335 | hashfile_checkpoint_init(state->f, &checkpoint); |
| 1336 | |
| 1337 | hashfile_checkpoint(state->f, &checkpoint); |
| 1338 | idx->offset = state->offset; |
| 1339 | crc32_begin(state->f); |
| 1340 | stream_blob_to_pack(state, &ctx, size, stream); |
| 1341 | git_hash_final_oid(result_oid, &ctx); |
| 1342 | |
| 1343 | idx->crc32 = crc32_end(state->f); |
| 1344 | if (already_written(transaction, result_oid)) { |
| 1345 | hashfile_truncate(state->f, &checkpoint); |
| 1346 | state->offset = checkpoint.offset; |
| 1347 | free(idx); |
| 1348 | } else { |
| 1349 | oidcpy(&idx->oid, result_oid); |
| 1350 | ALLOC_GROW(state->written, |
| 1351 | state->nr_written + 1, |
| 1352 | state->alloc_written); |
| 1353 | state->written[state->nr_written++] = idx; |
| 1354 | } |
| 1355 | return 0; |
| 1356 | } |
nothing calls this directly
no test coverage detected