summaryrefslogtreecommitdiff
path: root/archive-tar.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2020-09-19 21:23:32 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-09-19 22:56:05 (GMT)
commit200589abcb4d7f107ed9da85e43b9a7268016c23 (patch)
tree1b9e0829b242a6a1439ee9b115700842460737ad /archive-tar.c
parent385c171a018f2747b329bcfa6be8eda1709e5abd (diff)
downloadgit-200589abcb4d7f107ed9da85e43b9a7268016c23.zip
git-200589abcb4d7f107ed9da85e43b9a7268016c23.tar.gz
git-200589abcb4d7f107ed9da85e43b9a7268016c23.tar.bz2
archive: read short blobs in archive.c::write_archive_entry()
Centralize reading of symlink destinations and the contents of regular files that are too small to be streamed. This reduces code duplication and allows future patches to add support for adding non-tracked files to archives. The backends are expected to stream blobs if buffer is NULL. object_file_to_archive() is only called from archive.c and thus no longer exported. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'archive-tar.c')
-rw-r--r--archive-tar.c22
1 files changed, 3 insertions, 19 deletions
diff --git a/archive-tar.c b/archive-tar.c
index 5ceec36..f1a1447 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -242,13 +242,12 @@ static void write_extended_header(struct archiver_args *args,
static int write_tar_entry(struct archiver_args *args,
const struct object_id *oid,
const char *path, size_t pathlen,
- unsigned int mode)
+ unsigned int mode,
+ void *buffer, unsigned long size)
{
struct ustar_header header;
struct strbuf ext_header = STRBUF_INIT;
- unsigned int old_mode = mode;
- unsigned long size, size_in_header;
- void *buffer;
+ unsigned long size_in_header;
int err = 0;
memset(&header, 0, sizeof(header));
@@ -282,20 +281,6 @@ static int write_tar_entry(struct archiver_args *args,
} else
memcpy(header.name, path, pathlen);
- if (S_ISREG(mode) && !args->convert &&
- oid_object_info(args->repo, oid, &size) == OBJ_BLOB &&
- size > big_file_threshold)
- buffer = NULL;
- else if (S_ISLNK(mode) || S_ISREG(mode)) {
- enum object_type type;
- buffer = object_file_to_archive(args, path, oid, old_mode, &type, &size);
- if (!buffer)
- return error(_("cannot read %s"), oid_to_hex(oid));
- } else {
- buffer = NULL;
- size = 0;
- }
-
if (S_ISLNK(mode)) {
if (size > sizeof(header.linkname)) {
xsnprintf(header.linkname, sizeof(header.linkname),
@@ -326,7 +311,6 @@ static int write_tar_entry(struct archiver_args *args,
else
err = stream_blocked(args->repo, oid);
}
- free(buffer);
return err;
}