Skip to content

Commit 2ec02dd

Browse files
avargitster
authored andcommitted
pack-write: split up finish_tmp_packfile() function
Split up the finish_tmp_packfile() function and use the split-up version in pack-objects.c in preparation for moving the step of renaming the *.idx file later as part of a function change. Since the only other caller of finish_tmp_packfile() was in bulk-checkin.c, and it won't be needing a change to its *.idx renaming, provide a thin wrapper for the old function as a static function in that file. If other callers end up needing the simpler version it could be moved back to "pack-write.c" and "pack.h". 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 522a5c2 commit 2ec02dd

File tree

4 files changed

+39
-13
lines changed

4 files changed

+39
-13
lines changed

builtin/pack-objects.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,7 @@ static void write_pack_file(void)
12171217
if (!pack_to_stdout) {
12181218
struct stat st;
12191219
struct strbuf tmpname = STRBUF_INIT;
1220+
char *idx_tmp_name = NULL;
12201221

12211222
/*
12221223
* Packs are runtime accessed in their mtime
@@ -1246,9 +1247,10 @@ static void write_pack_file(void)
12461247
&to_pack, written_list, nr_written);
12471248
}
12481249

1249-
finish_tmp_packfile(&tmpname, pack_tmp_name,
1250+
stage_tmp_packfiles(&tmpname, pack_tmp_name,
12501251
written_list, nr_written,
1251-
&pack_idx_opts, hash);
1252+
&pack_idx_opts, hash, &idx_tmp_name);
1253+
rename_tmp_packfile_idx(&tmpname, &idx_tmp_name);
12521254

12531255
if (write_bitmap_index) {
12541256
size_t tmpname_len = tmpname.len;
@@ -1265,6 +1267,7 @@ static void write_pack_file(void)
12651267
strbuf_setlen(&tmpname, tmpname_len);
12661268
}
12671269

1270+
free(idx_tmp_name);
12681271
strbuf_release(&tmpname);
12691272
free(pack_tmp_name);
12701273
puts(hash_to_hex(hash));

bulk-checkin.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ static struct bulk_checkin_state {
2323
uint32_t nr_written;
2424
} state;
2525

26+
static void finish_tmp_packfile(struct strbuf *basename,
27+
const char *pack_tmp_name,
28+
struct pack_idx_entry **written_list,
29+
uint32_t nr_written,
30+
struct pack_idx_option *pack_idx_opts,
31+
unsigned char hash[])
32+
{
33+
char *idx_tmp_name = NULL;
34+
35+
stage_tmp_packfiles(basename, pack_tmp_name, written_list, nr_written,
36+
pack_idx_opts, hash, &idx_tmp_name);
37+
rename_tmp_packfile_idx(basename, &idx_tmp_name);
38+
39+
free(idx_tmp_name);
40+
}
41+
2642
static void finish_bulk_checkin(struct bulk_checkin_state *state)
2743
{
2844
unsigned char hash[GIT_MAX_RAWSZ];

pack-write.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -474,21 +474,28 @@ static void rename_tmp_packfile(struct strbuf *name_prefix, const char *source,
474474
strbuf_setlen(name_prefix, name_prefix_len);
475475
}
476476

477-
void finish_tmp_packfile(struct strbuf *name_buffer,
477+
void rename_tmp_packfile_idx(struct strbuf *name_buffer,
478+
char **idx_tmp_name)
479+
{
480+
rename_tmp_packfile(name_buffer, *idx_tmp_name, "idx");
481+
}
482+
483+
void stage_tmp_packfiles(struct strbuf *name_buffer,
478484
const char *pack_tmp_name,
479485
struct pack_idx_entry **written_list,
480486
uint32_t nr_written,
481487
struct pack_idx_option *pack_idx_opts,
482-
unsigned char hash[])
488+
unsigned char hash[],
489+
char **idx_tmp_name)
483490
{
484-
const char *idx_tmp_name, *rev_tmp_name = NULL;
491+
const char *rev_tmp_name = NULL;
485492

486493
if (adjust_shared_perm(pack_tmp_name))
487494
die_errno("unable to make temporary pack file readable");
488495

489-
idx_tmp_name = write_idx_file(NULL, written_list, nr_written,
490-
pack_idx_opts, hash);
491-
if (adjust_shared_perm(idx_tmp_name))
496+
*idx_tmp_name = (char *)write_idx_file(NULL, written_list, nr_written,
497+
pack_idx_opts, hash);
498+
if (adjust_shared_perm(*idx_tmp_name))
492499
die_errno("unable to make temporary index file readable");
493500

494501
rev_tmp_name = write_rev_file(NULL, written_list, nr_written, hash,
@@ -497,9 +504,6 @@ void finish_tmp_packfile(struct strbuf *name_buffer,
497504
rename_tmp_packfile(name_buffer, pack_tmp_name, "pack");
498505
if (rev_tmp_name)
499506
rename_tmp_packfile(name_buffer, rev_tmp_name, "rev");
500-
rename_tmp_packfile(name_buffer, idx_tmp_name, "idx");
501-
502-
free((void *)idx_tmp_name);
503507
}
504508

505509
void write_promisor_file(const char *promisor_name, struct ref **sought, int nr_sought)

pack.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,14 @@ int encode_in_pack_object_header(unsigned char *hdr, int hdr_len,
110110
int read_pack_header(int fd, struct pack_header *);
111111

112112
struct hashfile *create_tmp_packfile(char **pack_tmp_name);
113-
void finish_tmp_packfile(struct strbuf *name_buffer,
113+
void stage_tmp_packfiles(struct strbuf *name_buffer,
114114
const char *pack_tmp_name,
115115
struct pack_idx_entry **written_list,
116116
uint32_t nr_written,
117117
struct pack_idx_option *pack_idx_opts,
118-
unsigned char sha1[]);
118+
unsigned char hash[],
119+
char **idx_tmp_name);
120+
void rename_tmp_packfile_idx(struct strbuf *basename,
121+
char **idx_tmp_name);
119122

120123
#endif

0 commit comments

Comments
 (0)