Skip to content

Commit cdf9db3

Browse files
committed
create_tmp_packfile(): a helper function
Factor out a small logic out of the private write_pack_file() function in builtin/pack-objects.c Signed-off-by: Junio C Hamano <[email protected]>
1 parent c0ad465 commit cdf9db3

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

builtin/pack-objects.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -584,16 +584,10 @@ static void write_pack_file(void)
584584
unsigned char sha1[20];
585585
char *pack_tmp_name = NULL;
586586

587-
if (pack_to_stdout) {
587+
if (pack_to_stdout)
588588
f = sha1fd_throughput(1, "<stdout>", progress_state);
589-
} else {
590-
char tmpname[PATH_MAX];
591-
int fd;
592-
fd = odb_mkstemp(tmpname, sizeof(tmpname),
593-
"pack/tmp_pack_XXXXXX");
594-
pack_tmp_name = xstrdup(tmpname);
595-
f = sha1fd(fd, pack_tmp_name);
596-
}
589+
else
590+
f = create_tmp_packfile(&pack_tmp_name);
597591

598592
offset = write_pack_header(f, nr_remaining);
599593
if (!offset)

pack-write.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,13 @@ int encode_in_pack_object_header(enum object_type type, uintmax_t size, unsigned
328328
*hdr = c;
329329
return n;
330330
}
331+
332+
struct sha1file *create_tmp_packfile(char **pack_tmp_name)
333+
{
334+
char tmpname[PATH_MAX];
335+
int fd;
336+
337+
fd = odb_mkstemp(tmpname, sizeof(tmpname), "pack/tmp_pack_XXXXXX");
338+
*pack_tmp_name = xstrdup(tmpname);
339+
return sha1fd(fd, *pack_tmp_name);
340+
}

pack.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,7 @@ extern int encode_in_pack_object_header(enum object_type, uintmax_t, unsigned ch
8484
#define PH_ERROR_PACK_SIGNATURE (-2)
8585
#define PH_ERROR_PROTOCOL (-3)
8686
extern int read_pack_header(int fd, struct pack_header *);
87+
88+
extern struct sha1file *create_tmp_packfile(char **pack_tmp_name);
89+
8790
#endif

0 commit comments

Comments
 (0)