From: "René Scharfe" <l.s.r@web.de>
To: luatex@nililand.de, git@vger.kernel.org
Subject: Re: [PATCH] archive-zip: add --text parameter
Date: Thu, 05 Mar 2015 16:27:48 +0100 [thread overview]
Message-ID: <54F875F4.1080508@web.de> (raw)
In-Reply-To: <54F77573.80109@web.de>
Am 04.03.2015 um 22:13 schrieb René Scharfe:
> diff --git a/archive-zip.c b/archive-zip.c
> index 4bde019..3767940 100644
> --- a/archive-zip.c
> +++ b/archive-zip.c
> @@ -5,6 +5,7 @@
> #include "archive.h"
> #include "streaming.h"
> #include "utf8.h"
> +#include "xdiff-interface.h"
>
> static int zip_date;
> static int zip_time;
> @@ -210,6 +211,7 @@ static int write_zip_entry(struct archiver_args *args,
> struct git_istream *stream = NULL;
> unsigned long flags = 0;
> unsigned long size;
> + int is_binary = -1;
>
> crc = crc32(0, NULL, 0);
>
> @@ -238,8 +240,14 @@ static int write_zip_entry(struct archiver_args *args,
> method = 0;
> attr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) :
> (mode & 0111) ? ((mode) << 16) : 0;
> - if (S_ISREG(mode) && args->compression_level != 0 && size > 0)
> - method = 8;
> + if (S_ISREG(mode)) {
> + if (args->compression_level != 0 && size > 0)
> + method = 8;
> + if (args->text == ARCHIVE_TEXT_ALL)
> + is_binary = 0;
> + else if (args->text == ARCHIVE_TEXT_NONE)
> + is_binary = 1;
> + }
>
> if (S_ISREG(mode) && type == OBJ_BLOB && !args->convert &&
> size > big_file_threshold) {
> @@ -256,6 +264,8 @@ static int write_zip_entry(struct archiver_args *args,
> return error("cannot read %s",
> sha1_to_hex(sha1));
> crc = crc32(crc, buffer, size);
> + if (is_binary < 0)
> + is_binary = buffer_is_binary(buffer, size);
> out = buffer;
> }
> compressed_size = (method == 0) ? size : 0;
> @@ -300,7 +310,6 @@ static int write_zip_entry(struct archiver_args *args,
> copy_le16(dirent.extra_length, ZIP_EXTRA_MTIME_SIZE);
> copy_le16(dirent.comment_length, 0);
> copy_le16(dirent.disk, 0);
> - copy_le16(dirent.attr1, 0);
> copy_le32(dirent.attr2, attr2);
> copy_le32(dirent.offset, zip_offset);
>
> @@ -328,6 +337,8 @@ static int write_zip_entry(struct archiver_args *args,
> if (readlen <= 0)
> break;
> crc = crc32(crc, buf, readlen);
> + if (is_binary < 0)
> + is_binary = buffer_is_binary(buffer, size);
buffer is NULL here, so this crashes. buf and readlen have to be used
instead. This code path is only used for entries that are too big to be
compressed in one go.
> write_or_die(1, buf, readlen);
> }
> close_istream(stream);
> @@ -361,6 +372,8 @@ static int write_zip_entry(struct archiver_args *args,
> if (readlen <= 0)
> break;
> crc = crc32(crc, buf, readlen);
> + if (is_binary < 0)
> + is_binary = buffer_is_binary(buffer, size);
Same here.
> zstream.next_in = buf;
> zstream.avail_in = readlen;
> @@ -405,6 +418,8 @@ static int write_zip_entry(struct archiver_args *args,
> free(deflated);
> free(buffer);
>
> + copy_le16(dirent.attr1, !is_binary);
> +
> memcpy(zip_dir + zip_dir_offset, &dirent, ZIP_DIR_HEADER_SIZE);
> zip_dir_offset += ZIP_DIR_HEADER_SIZE;
> memcpy(zip_dir + zip_dir_offset, path, pathlen);
> @@ -466,7 +481,7 @@ static int write_zip_archive(const struct archiver *ar,
> static struct archiver zip_archiver = {
> "zip",
> write_zip_archive,
> - ARCHIVER_WANT_COMPRESSION_LEVELS|ARCHIVER_REMOTE
> + ARCHIVER_WANT_COMPRESSION_LEVELS|ARCHIVER_REMOTE|ARCHIVER_TEXT_ATTRIBUTE
> };
>
> void init_zip_archiver(void)
next prev parent reply other threads:[~2015-03-05 15:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-23 13:58 zip files created with git archive flags text files as binaries Ulrike Fischer
2015-02-23 19:30 ` René Scharfe
2015-03-04 21:13 ` René Scharfe
2015-03-04 21:13 ` [PATCH] archive-zip: add --text parameter René Scharfe
2015-03-05 2:16 ` Junio C Hamano
2015-03-05 15:27 ` René Scharfe
2015-03-05 15:27 ` René Scharfe [this message]
2015-03-05 19:06 ` [PATCH v2] archive-zip: mark text files in archives René Scharfe
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=54F875F4.1080508@web.de \
--to=l.s.r@web.de \
--cc=git@vger.kernel.org \
--cc=luatex@nililand.de \
/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).