summaryrefslogtreecommitdiff
path: root/archive-zip.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-zip.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-zip.c')
-rw-r--r--archive-zip.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/archive-zip.c b/archive-zip.c
index 02d1f3787a..716cc42710 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -121,8 +121,9 @@ static void *zlib_deflate(void *data, unsigned long size,
}
static int write_zip_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 zip_local_header header;
struct zip_dir_header dirent;
@@ -134,6 +135,8 @@ static int write_zip_entry(struct archiver_args *args,
int method;
unsigned char *out;
void *deflated = NULL;
+ void *buffer;
+ unsigned long size;
crc = crc32(0, NULL, 0);
@@ -148,7 +151,14 @@ static int write_zip_entry(struct archiver_args *args,
out = NULL;
uncompressed_size = 0;
compressed_size = 0;
+ buffer = NULL;
+ size = 0;
} else if (S_ISREG(mode) || S_ISLNK(mode)) {
+ enum object_type type;
+ buffer = sha1_file_to_archive(args, path, sha1, mode, &type, &size);
+ if (!buffer)
+ return error("cannot read %s", sha1_to_hex(sha1));
+
method = 0;
attr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) :
(mode & 0111) ? ((mode) << 16) : 0;
@@ -229,6 +239,7 @@ static int write_zip_entry(struct archiver_args *args,
}
free(deflated);
+ free(buffer);
return 0;
}