Merge branch 'tb/pack-finalize-ordering' into maint
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:
commit
6287460203
@ -1477,6 +1477,22 @@ static void write_special_file(const char *suffix, const char *msg,
|
||||
strbuf_release(&name_buf);
|
||||
}
|
||||
|
||||
static void rename_tmp_packfile(const char **final_name,
|
||||
const char *curr_name,
|
||||
struct strbuf *name, unsigned char *hash,
|
||||
const char *ext, int make_read_only_if_same)
|
||||
{
|
||||
if (*final_name != curr_name) {
|
||||
if (!*final_name)
|
||||
*final_name = odb_pack_name(name, hash, ext);
|
||||
if (finalize_object_file(curr_name, *final_name))
|
||||
die(_("unable to rename temporary '*.%s' file to '%s"),
|
||||
ext, *final_name);
|
||||
} else if (make_read_only_if_same) {
|
||||
chmod(*final_name, 0444);
|
||||
}
|
||||
}
|
||||
|
||||
static void final(const char *final_pack_name, const char *curr_pack_name,
|
||||
const char *final_index_name, const char *curr_index_name,
|
||||
const char *final_rev_index_name, const char *curr_rev_index_name,
|
||||
@ -1505,31 +1521,13 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
|
||||
write_special_file("promisor", promisor_msg, final_pack_name,
|
||||
hash, NULL);
|
||||
|
||||
if (final_pack_name != curr_pack_name) {
|
||||
if (!final_pack_name)
|
||||
final_pack_name = odb_pack_name(&pack_name, hash, "pack");
|
||||
if (finalize_object_file(curr_pack_name, final_pack_name))
|
||||
die(_("cannot store pack file"));
|
||||
} else if (from_stdin)
|
||||
chmod(final_pack_name, 0444);
|
||||
|
||||
if (final_index_name != curr_index_name) {
|
||||
if (!final_index_name)
|
||||
final_index_name = odb_pack_name(&index_name, hash, "idx");
|
||||
if (finalize_object_file(curr_index_name, final_index_name))
|
||||
die(_("cannot store index file"));
|
||||
} else
|
||||
chmod(final_index_name, 0444);
|
||||
|
||||
if (curr_rev_index_name) {
|
||||
if (final_rev_index_name != curr_rev_index_name) {
|
||||
if (!final_rev_index_name)
|
||||
final_rev_index_name = odb_pack_name(&rev_index_name, hash, "rev");
|
||||
if (finalize_object_file(curr_rev_index_name, final_rev_index_name))
|
||||
die(_("cannot store reverse index file"));
|
||||
} else
|
||||
chmod(final_rev_index_name, 0444);
|
||||
}
|
||||
rename_tmp_packfile(&final_pack_name, curr_pack_name, &pack_name,
|
||||
hash, "pack", from_stdin);
|
||||
if (curr_rev_index_name)
|
||||
rename_tmp_packfile(&final_rev_index_name, curr_rev_index_name,
|
||||
&rev_index_name, hash, "rev", 1);
|
||||
rename_tmp_packfile(&final_index_name, curr_index_name, &index_name,
|
||||
hash, "idx", 1);
|
||||
|
||||
if (do_fsck_object) {
|
||||
struct packed_git *p;
|
||||
|
@ -1217,6 +1217,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
|
||||
@ -1237,7 +1238,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);
|
||||
@ -1245,13 +1247,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);
|
||||
@ -1260,8 +1263,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));
|
||||
|
@ -208,10 +208,10 @@ static struct {
|
||||
unsigned optional:1;
|
||||
} exts[] = {
|
||||
{".pack"},
|
||||
{".idx"},
|
||||
{".rev", 1},
|
||||
{".bitmap", 1},
|
||||
{".promisor", 1},
|
||||
{".idx"},
|
||||
};
|
||||
|
||||
static unsigned populate_pack_exts(char *name)
|
||||
|
@ -23,9 +23,25 @@ static struct bulk_checkin_state {
|
||||
uint32_t nr_written;
|
||||
} state;
|
||||
|
||||
static void finish_tmp_packfile(struct strbuf *basename,
|
||||
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[])
|
||||
{
|
||||
char *idx_tmp_name = NULL;
|
||||
|
||||
stage_tmp_packfiles(basename, pack_tmp_name, written_list, nr_written,
|
||||
pack_idx_opts, hash, &idx_tmp_name);
|
||||
rename_tmp_packfile_idx(basename, &idx_tmp_name);
|
||||
|
||||
free(idx_tmp_name);
|
||||
}
|
||||
|
||||
static void finish_bulk_checkin(struct bulk_checkin_state *state)
|
||||
{
|
||||
struct object_id oid;
|
||||
unsigned char hash[GIT_MAX_RAWSZ];
|
||||
struct strbuf packname = STRBUF_INIT;
|
||||
int i;
|
||||
|
||||
@ -37,19 +53,20 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)
|
||||
unlink(state->pack_tmp_name);
|
||||
goto clear_exit;
|
||||
} else if (state->nr_written == 1) {
|
||||
finalize_hashfile(state->f, oid.hash, CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE);
|
||||
finalize_hashfile(state->f, hash, CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE);
|
||||
} else {
|
||||
int fd = finalize_hashfile(state->f, oid.hash, 0);
|
||||
fixup_pack_header_footer(fd, oid.hash, state->pack_tmp_name,
|
||||
state->nr_written, oid.hash,
|
||||
int fd = finalize_hashfile(state->f, hash, 0);
|
||||
fixup_pack_header_footer(fd, hash, state->pack_tmp_name,
|
||||
state->nr_written, hash,
|
||||
state->offset);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
strbuf_addf(&packname, "%s/pack/pack-", get_object_directory());
|
||||
strbuf_addf(&packname, "%s/pack/pack-%s.", get_object_directory(),
|
||||
hash_to_hex(hash));
|
||||
finish_tmp_packfile(&packname, state->pack_tmp_name,
|
||||
state->written, state->nr_written,
|
||||
&state->pack_idx_opts, oid.hash);
|
||||
&state->pack_idx_opts, hash);
|
||||
for (i = 0; i < state->nr_written; i++)
|
||||
free(state->written[i]);
|
||||
|
||||
|
57
pack-write.c
57
pack-write.c
@ -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)
|
||||
|
10
pack.h
10
pack.h
@ -110,6 +110,14 @@ int encode_in_pack_object_header(unsigned char *hdr, int hdr_len,
|
||||
int read_pack_header(int fd, struct pack_header *);
|
||||
|
||||
struct hashfile *create_tmp_packfile(char **pack_tmp_name);
|
||||
void finish_tmp_packfile(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 sha1[]);
|
||||
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[],
|
||||
char **idx_tmp_name);
|
||||
void rename_tmp_packfile_idx(struct strbuf *basename,
|
||||
char **idx_tmp_name);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user