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

Function flush_packfile_transaction

object-file.c:1231–1279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1229}
1230
1231static void flush_packfile_transaction(struct odb_transaction_files *transaction)
1232{
1233 struct transaction_packfile *state = &transaction->packfile;
1234 struct repository *repo = transaction->base.source->odb->repo;
1235 unsigned char hash[GIT_MAX_RAWSZ];
1236 struct strbuf packname = STRBUF_INIT;
1237 char *idx_tmp_name = NULL;
1238
1239 if (!state->f)
1240 return;
1241
1242 if (state->nr_written == 0) {
1243 close(state->f->fd);
1244 free_hashfile(state->f);
1245 unlink(state->pack_tmp_name);
1246 goto clear_exit;
1247 } else if (state->nr_written == 1) {
1248 finalize_hashfile(state->f, hash, FSYNC_COMPONENT_PACK,
1249 CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE);
1250 } else {
1251 int fd = finalize_hashfile(state->f, hash, FSYNC_COMPONENT_PACK, 0);
1252 fixup_pack_header_footer(repo->hash_algo, fd, hash, state->pack_tmp_name,
1253 state->nr_written, hash,
1254 state->offset);
1255 close(fd);
1256 }
1257
1258 strbuf_addf(&packname, "%s/pack/pack-%s.",
1259 repo_get_object_directory(transaction->base.source->odb->repo),
1260 hash_to_hex_algop(hash, repo->hash_algo));
1261
1262 stage_tmp_packfiles(repo, &packname, state->pack_tmp_name,
1263 state->written, state->nr_written, NULL,
1264 &state->pack_idx_opts, hash, &idx_tmp_name);
1265 rename_tmp_packfile_idx(repo, &packname, &idx_tmp_name);
1266
1267 for (uint32_t i = 0; i < state->nr_written; i++)
1268 free(state->written[i]);
1269
1270clear_exit:
1271 free(idx_tmp_name);
1272 free(state->pack_tmp_name);
1273 free(state->written);
1274 memset(state, 0, sizeof(*state));
1275
1276 strbuf_release(&packname);
1277 /* Make objects we just wrote available to ourselves */
1278 odb_reprepare(repo->objects);
1279}
1280
1281/*
1282 * This writes the specified object to a packfile. Objects written here

Calls 10

free_hashfileFunction · 0.85
finalize_hashfileFunction · 0.85
fixup_pack_header_footerFunction · 0.85
strbuf_addfFunction · 0.85
hash_to_hex_algopFunction · 0.85
stage_tmp_packfilesFunction · 0.85
rename_tmp_packfile_idxFunction · 0.85
strbuf_releaseFunction · 0.85
odb_reprepareFunction · 0.85

Tested by

no test coverage detected