diff options
author | Junio C Hamano <gitster@pobox.com> | 2011-10-28 12:34:09 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-10-28 12:34:09 -0700 |
commit | 0e990530ae6d6c6805d31c666953541f762dd402 (patch) | |
tree | f16548df1b3b235b92c6e84a7bdb6955052dafde /pack-write.c | |
parent | cdf9db3c83618453809d6a584d1a0db19b3e189f (diff) | |
download | git-0e990530ae6d6c6805d31c666953541f762dd402.tar.gz |
finish_tmp_packfile(): a helper function
Factor out a small logic out of the private write_pack_file() function
in builtin/pack-objects.c.
This changes the order of finishing multi-pack generation slightly. The
code used to
- adjust shared perm of temporary packfile
- rename temporary packfile to the final name
- update mtime of the packfile under the final name
- adjust shared perm of temporary idxfile
- rename temporary idxfile to the final name
but because the helper does not want to do the mtime thing, the updated
code does that step first and then all the rest.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pack-write.c')
-rw-r--r-- | pack-write.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/pack-write.c b/pack-write.c index 863cce8a09..cadc3e1adf 100644 --- a/pack-write.c +++ b/pack-write.c @@ -338,3 +338,34 @@ struct sha1file *create_tmp_packfile(char **pack_tmp_name) *pack_tmp_name = xstrdup(tmpname); return sha1fd(fd, *pack_tmp_name); } + +void finish_tmp_packfile(char *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[]) +{ + const char *idx_tmp_name; + char *end_of_name_prefix = strrchr(name_buffer, 0); + + 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, sha1); + if (adjust_shared_perm(idx_tmp_name)) + die_errno("unable to make temporary index file readable"); + + sprintf(end_of_name_prefix, "%s.pack", sha1_to_hex(sha1)); + free_pack_by_name(name_buffer); + + if (rename(pack_tmp_name, name_buffer)) + die_errno("unable to rename temporary pack file"); + + sprintf(end_of_name_prefix, "%s.idx", sha1_to_hex(sha1)); + if (rename(idx_tmp_name, name_buffer)) + die_errno("unable to rename temporary index file"); + + free((void *)idx_tmp_name); +} |