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

@ -461,49 +461,48 @@ struct hashfile *create_tmp_packfile(char **pack_tmp_name)
return hashfd(fd, *pack_tmp_name);
}
void finish_tmp_packfile(struct strbuf *name_buffer,
static void rename_tmp_packfile(struct strbuf *name_prefix, const char *source,
const char *ext)
{
size_t name_prefix_len = name_prefix->len;
strbuf_addstr(name_prefix, ext);
if (rename(source, name_prefix->buf))
die_errno("unable to rename temporary file to '%s'",
name_prefix->buf);
strbuf_setlen(name_prefix, name_prefix_len);
}
void rename_tmp_packfile_idx(struct strbuf *name_buffer,
char **idx_tmp_name)
{
rename_tmp_packfile(name_buffer, *idx_tmp_name, "idx");
}
void stage_tmp_packfiles(struct strbuf *name_buffer,
const char *pack_tmp_name,
struct pack_idx_entry **written_list,
uint32_t nr_written,
struct pack_idx_option *pack_idx_opts,
unsigned char hash[])
unsigned char hash[],
char **idx_tmp_name)
{
const char *idx_tmp_name, *rev_tmp_name = NULL;
int basename_len = name_buffer->len;
const char *rev_tmp_name = NULL;
if (adjust_shared_perm(pack_tmp_name))
die_errno("unable to make temporary pack file readable");
idx_tmp_name = write_idx_file(NULL, written_list, nr_written,
pack_idx_opts, hash);
if (adjust_shared_perm(idx_tmp_name))
*idx_tmp_name = (char *)write_idx_file(NULL, written_list, nr_written,
pack_idx_opts, hash);
if (adjust_shared_perm(*idx_tmp_name))
die_errno("unable to make temporary index file readable");
rev_tmp_name = write_rev_file(NULL, written_list, nr_written, hash,
pack_idx_opts->flags);
strbuf_addf(name_buffer, "%s.pack", hash_to_hex(hash));
if (rename(pack_tmp_name, name_buffer->buf))
die_errno("unable to rename temporary pack file");
strbuf_setlen(name_buffer, basename_len);
strbuf_addf(name_buffer, "%s.idx", hash_to_hex(hash));
if (rename(idx_tmp_name, name_buffer->buf))
die_errno("unable to rename temporary index file");
strbuf_setlen(name_buffer, basename_len);
if (rev_tmp_name) {
strbuf_addf(name_buffer, "%s.rev", hash_to_hex(hash));
if (rename(rev_tmp_name, name_buffer->buf))
die_errno("unable to rename temporary reverse-index file");
}
strbuf_setlen(name_buffer, basename_len);
free((void *)idx_tmp_name);
rename_tmp_packfile(name_buffer, pack_tmp_name, "pack");
if (rev_tmp_name)
rename_tmp_packfile(name_buffer, rev_tmp_name, "rev");
}
void write_promisor_file(const char *promisor_name, struct ref **sought, int nr_sought)