From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 3/5] archive: delegate blob reading to backend
Date: Mon, 30 Apr 2012 23:07:46 +0200 [thread overview]
Message-ID: <4F9EFF22.4060105@lsrfire.ath.cx> (raw)
In-Reply-To: <1335761837-12482-4-git-send-email-pclouds@gmail.com>
Am 30.04.2012 06:57, schrieb Nguyễn Thái Ngọc Duy:
> 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>
> ---
> archive-tar.c | 20 +++++++++++++++++---
> archive-zip.c | 14 ++++++++++++--
> archive.c | 28 +++++++++++-----------------
> archive.h | 10 +++++++++-
> 4 files changed, 49 insertions(+), 23 deletions(-)
>
> diff --git a/archive-tar.c b/archive-tar.c
> index 6c8a0bd..61821f4 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);
This buffer is never freed.
> + 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));
> diff --git a/archive-zip.c b/archive-zip.c
> index 02d1f37..f8039ba 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);
This one is leaked as well.
> + 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;
You could squash this in:
diff --git a/archive-tar.c b/archive-tar.c
index 61821f4..bb320ad 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -235,6 +235,7 @@ static int write_tar_entry(struct archiver_args *args,
write_blocked(&header, sizeof(header));
if (S_ISREG(mode) && buffer && size > 0)
write_blocked(buffer, size);
+ free(buffer);
return err;
}
diff --git a/archive-zip.c b/archive-zip.c
index f8039ba..716cc42 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -239,6 +239,7 @@ static int write_zip_entry(struct archiver_args *args,
}
free(deflated);
+ free(buffer);
return 0;
}
next prev parent reply other threads:[~2012-04-30 21:07 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-30 4:57 [PATCH 0/5] Large file support for git-archive Nguyễn Thái Ngọc Duy
2012-04-30 4:57 ` [PATCH 1/5] archive-tar: turn write_tar_entry into blob-writing only Nguyễn Thái Ngọc Duy
2012-04-30 18:15 ` Junio C Hamano
2012-04-30 22:11 ` René Scharfe
2012-04-30 4:57 ` [PATCH 2/5] archive-tar: unindent write_tar_entry by one level Nguyễn Thái Ngọc Duy
2012-04-30 4:57 ` [PATCH 3/5] archive: delegate blob reading to backend Nguyễn Thái Ngọc Duy
2012-04-30 21:07 ` René Scharfe [this message]
2012-04-30 4:57 ` [PATCH 4/5] archive-tar: stream large blobs to tar file Nguyễn Thái Ngọc Duy
2012-04-30 19:01 ` Junio C Hamano
2012-04-30 21:08 ` René Scharfe
2012-04-30 21:36 ` Junio C Hamano
2012-04-30 22:12 ` René Scharfe
2012-04-30 4:57 ` [PATCH 5/5] archive-zip: stream large blobs into zip file Nguyễn Thái Ngọc Duy
2012-04-30 19:12 ` Junio C Hamano
2012-04-30 22:54 ` René Scharfe
2012-04-30 22:11 ` [PATCH 5a/5] streaming: void pointer instead of char pointer René Scharfe
2012-04-30 22:12 ` [PATCH 6a/5] archive-zip: remove uncompressed_size René Scharfe
2012-04-30 22:12 ` [PATCH 7a/5] archive-zip: factor out helpers for writing sizes and CRC René Scharfe
2012-04-30 22:12 ` [PATCH 8a/5] archive-zip: streaming for stored files René Scharfe
2012-04-30 22:12 ` [PATCH 9a/5] archive-zip: streaming for deflated files René Scharfe
2012-04-30 19:15 ` [PATCH 0/5] Large file support for git-archive Junio C Hamano
2012-04-30 21:07 ` René Scharfe
2012-05-01 10:19 ` Nguyen Thai Ngoc Duy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4F9EFF22.4060105@lsrfire.ath.cx \
--to=rene.scharfe@lsrfire.ath.cx \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pclouds@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).