summaryrefslogtreecommitdiff
path: root/fast-import.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-02-22 17:44:46 -0500
committerJunio C Hamano <gitster@pobox.com>2016-02-22 14:51:09 -0800
commita78c188a32dd2ce02db2b966a70bffec52c98d20 (patch)
tree420a86e890f7d3850693b3859aca3b8133026da3 /fast-import.c
parente0b837351084c3cb52c5acaf8a505835e631744a (diff)
downloadgit-a78c188a32dd2ce02db2b966a70bffec52c98d20.tar.gz
fast-import: simplify allocation in start_packfile
This function allocate a packed_git flex-array, and adds a mysterious 2 bytes to the length of the pack_name field. One is for the trailing NUL, but the other has no purpose. This is probably cargo-culted from add_packed_git, which gets the ".idx" path and needed to allocate enough space to hold the matching ".pack" (though since 48bcc1c, we calculate the size there differently). This site, however, is using the raw path of a tempfile, and does not need the extra byte. We can just replace the allocation with FLEX_ALLOC_STR, which handles the allocation and the NUL for us. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'fast-import.c')
-rw-r--r--fast-import.c5
1 files changed, 1 insertions, 4 deletions
diff --git a/fast-import.c b/fast-import.c
index 9622b89df7..75f77480a2 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -865,15 +865,12 @@ static void start_packfile(void)
{
static char tmp_file[PATH_MAX];
struct packed_git *p;
- int namelen;
struct pack_header hdr;
int pack_fd;
pack_fd = odb_mkstemp(tmp_file, sizeof(tmp_file),
"pack/tmp_pack_XXXXXX");
- namelen = strlen(tmp_file) + 2;
- p = xcalloc(1, sizeof(*p) + namelen);
- xsnprintf(p->pack_name, namelen, "%s", tmp_file);
+ FLEX_ALLOC_STR(p, pack_name, tmp_file);
p->pack_fd = pack_fd;
p->do_not_close = 1;
pack_file = sha1fd(pack_fd, p->pack_name);