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 <gitster@pobox.com>
Junio C Hamano committed
Oct 28, 2011 at 11:52 UTC
cdf9db3c83618453809d6a584d1a0db19b3e189f
3 files changed
+16
-9
builtin/pack-objects.c
+3
-9
@@ -584,16 +584,10 @@ static void write_pack_file(void)
584
unsigned char sha1[20];
585
char *pack_tmp_name = NULL;
586
587
- if (pack_to_stdout) {
587
+ if (pack_to_stdout)
588
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);
591
592
offset = write_pack_header(f, nr_remaining);
593
if (!offset)
pack-write.c
+10
@@ -328,3 +328,13 @@ int encode_in_pack_object_header(enum object_type type, uintmax_t size, unsigned
328
*hdr = c;
329
return n;
330
}
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
+3
@@ -84,4 +84,7 @@ extern int encode_in_pack_object_header(enum object_type, uintmax_t, unsigned ch
84
#define PH_ERROR_PACK_SIGNATURE (-2)
85
#define PH_ERROR_PROTOCOL (-3)
86
extern int read_pack_header(int fd, struct pack_header *);
87
+
88
+extern struct sha1file *create_tmp_packfile(char **pack_tmp_name);
89
+
90
#endif