archive-zip: fix compressed size for stored export-subst files
commitd3c1472fe35e2575508d80415565822ee2211df5
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>
Wed, 27 Feb 2013 10:20:21 +0000 (27 11:20 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 27 Feb 2013 15:38:32 +0000 (27 07:38 -0800)
treefb824ed2d196f643f2847683b5c6cf134b07be3b
parentd9f85f50ca35d7ed1b35e2990a0082b94f1e1370
archive-zip: fix compressed size for stored export-subst files

Currently ZIP archive entries of files with export-subst attribute are
broken if they are stored uncompressed.

We get the size of a file from sha1_object_info(), but this number is
likely wrong for files whose contents are changed due to export-subst
placeholder expansion.  We use sha1_file_to_archive() to get the
expanded file contents and size in that case.  We proceed to use that
size for the uncompressed size field (good), but the compressed size
field is set based on the size from sha1_object_info() (bad).

This matters only for uncompressed files because for deflated files
we use the correct value after compression is done.  And for files
without export-subst expansion the sizes from sha1_object_info() and
sha1_file_to_archive() are the same, so they are unaffected as well.

This patch fixes the issue by setting the compressed size based on the
uncompressed size only after we actually know the latter.

Also make use of the test file substfile1 to check for the breakage;
it was only stored verbatim so far.  For that purpose, set the
attribute export-subst and replace its contents with the expected
expansion after committing.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
archive-zip.c
t/t5003-archive-zip.sh