Merge branch 'tb/pack-finalize-ordering'

The order in which various files that make up a single (conceptual)
packfile has been reevaluated and straightened up.  This matters in
correctness, as an incomplete set of files must not be shown to a
running Git.

* tb/pack-finalize-ordering:
  pack-objects: rename .idx files into place after .bitmap files
  pack-write: split up finish_tmp_packfile() function
  builtin/index-pack.c: move `.idx` files into place last
  index-pack: refactor renaming in final()
  builtin/repack.c: move `.idx` files into place last
  pack-write.c: rename `.idx` files after `*.rev`
  pack-write: refactor renaming in finish_tmp_packfile()
  bulk-checkin.c: store checksum directly
  pack.h: line-wrap the definition of finish_tmp_packfile()
This commit is contained in:
Junio C Hamano
2021-09-20 15:20:42 -07:00
6 changed files with 96 additions and 67 deletions

View File

@ -1222,6 +1222,7 @@ static void write_pack_file(void)
if (!pack_to_stdout) {
struct stat st;
struct strbuf tmpname = STRBUF_INIT;
char *idx_tmp_name = NULL;
/*
* Packs are runtime accessed in their mtime
@ -1242,7 +1243,8 @@ static void write_pack_file(void)
warning_errno(_("failed utime() on %s"), pack_tmp_name);
}
strbuf_addf(&tmpname, "%s-", base_name);
strbuf_addf(&tmpname, "%s-%s.", base_name,
hash_to_hex(hash));
if (write_bitmap_index) {
bitmap_writer_set_checksum(hash);
@ -1250,13 +1252,14 @@ static void write_pack_file(void)
&to_pack, written_list, nr_written);
}
finish_tmp_packfile(&tmpname, pack_tmp_name,
stage_tmp_packfiles(&tmpname, pack_tmp_name,
written_list, nr_written,
&pack_idx_opts, hash);
&pack_idx_opts, hash, &idx_tmp_name);
if (write_bitmap_index) {
strbuf_addf(&tmpname, "%s.bitmap", hash_to_hex(hash));
size_t tmpname_len = tmpname.len;
strbuf_addstr(&tmpname, "bitmap");
stop_progress(&progress_state);
bitmap_writer_show_progress(progress);
@ -1266,8 +1269,12 @@ static void write_pack_file(void)
bitmap_writer_finish(written_list, nr_written,
tmpname.buf, write_bitmap_options);
write_bitmap_index = 0;
strbuf_setlen(&tmpname, tmpname_len);
}
rename_tmp_packfile_idx(&tmpname, &idx_tmp_name);
free(idx_tmp_name);
strbuf_release(&tmpname);
free(pack_tmp_name);
puts(hash_to_hex(hash));