Skip to content

Commit 16a8690

Browse files
ttaylorrgitster
authored andcommitted
pack-write.c: rename .idx files after *.rev
We treat the presence of an `.idx` file as the indicator of whether or not it's safe to use a packfile. But `finish_tmp_packfile()` (which is responsible for writing the pack and moving the temporary versions of all of its auxiliary files into place) is inconsistent about the write order. Specifically, it moves the `.rev` file into place after the `.idx`, leaving open the possibility to open a pack which looks "ready" (because the `.idx` file exists and is readable) but appears momentarily to not have a `.rev` file. This causes Git to fall back to generating the pack's reverse index in memory. Though racy, this amounts to an unnecessary slow-down at worst, and doesn't affect the correctness of the resulting reverse index. Close this race by moving the .rev file into place before moving the .idx file into place. This still leaves the issue of `.idx` files being renamed into place before the auxiliary `.bitmap` file is renamed when in pack-object.c's write_pack_file() "write_bitmap_index" is true. That race will be addressed in subsequent commits. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 66833f0 commit 16a8690

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

pack-write.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,9 @@ void finish_tmp_packfile(struct strbuf *name_buffer,
495495
pack_idx_opts->flags);
496496

497497
rename_tmp_packfile(name_buffer, pack_tmp_name, "pack");
498-
rename_tmp_packfile(name_buffer, idx_tmp_name, "idx");
499498
if (rev_tmp_name)
500499
rename_tmp_packfile(name_buffer, rev_tmp_name, "rev");
500+
rename_tmp_packfile(name_buffer, idx_tmp_name, "idx");
501501

502502
free((void *)idx_tmp_name);
503503
}

0 commit comments

Comments
 (0)