summaryrefslogtreecommitdiff
path: root/archive-tar.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2012-05-03 08:51:03 +0700
committerJunio C Hamano <gitster@pobox.com>2012-05-03 10:22:56 -0700
commit9cb513b7988c2fe443c47186e42dd827b76ddb14 (patch)
tree536e1847e3b4265e39f08b1fed147e7c63b2b7d3 /archive-tar.c
parent853907097af803c595f0c12fc355c907702eb7c8 (diff)
downloadgit-9cb513b7988c2fe443c47186e42dd827b76ddb14.tar.gz
archive: delegate blob reading to backend
archive-tar.c and archive-zip.c now perform conversion check, with help of sha1_file_to_archive() from archive.c This gives backends more freedom in dealing with (streaming) large blobs. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'archive-tar.c')
-rw-r--r--archive-tar.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/archive-tar.c b/archive-tar.c
index 6c8a0bd3bf..3be0cdf350 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -161,11 +161,15 @@ static int write_extended_header(struct archiver_args *args,
}
static int write_tar_entry(struct archiver_args *args,
- const unsigned char *sha1, const char *path, size_t pathlen,
- unsigned int mode, void *buffer, unsigned long size)
+ const unsigned char *sha1,
+ const char *path, size_t pathlen,
+ unsigned int mode)
{
struct ustar_header header;
struct strbuf ext_header = STRBUF_INIT;
+ unsigned int old_mode = mode;
+ unsigned long size;
+ void *buffer;
int err = 0;
memset(&header, 0, sizeof(header));
@@ -199,7 +203,17 @@ static int write_tar_entry(struct archiver_args *args,
} else
memcpy(header.name, path, pathlen);
- if (S_ISLNK(mode) && buffer) {
+ if (S_ISLNK(mode) || S_ISREG(mode)) {
+ enum object_type type;
+ buffer = sha1_file_to_archive(args, path, sha1, old_mode, &type, &size);
+ if (!buffer)
+ return error("cannot read %s", sha1_to_hex(sha1));
+ } else {
+ buffer = NULL;
+ size = 0;
+ }
+
+ if (S_ISLNK(mode)) {
if (size > sizeof(header.linkname)) {
sprintf(header.linkname, "see %s.paxheader",
sha1_to_hex(sha1));
@@ -214,13 +228,16 @@ static int write_tar_entry(struct archiver_args *args,
if (ext_header.len > 0) {
err = write_extended_header(args, sha1, ext_header.buf,
ext_header.len);
- if (err)
+ if (err) {
+ free(buffer);
return err;
+ }
}
strbuf_release(&ext_header);
write_blocked(&header, sizeof(header));
if (S_ISREG(mode) && buffer && size > 0)
write_blocked(buffer, size);
+ free(buffer);
return err;
}