|
| 1 | +From e00dd10fbd4d00bad4a02563cf0b151f35092189 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Rohit Ashiwal < [email protected]> |
| 3 | +Date: Fri, 15 Feb 2019 19:03:57 +0530 |
| 4 | +Subject: [PATCH 1/2] [FIX] git-archive error, gzip -cn : command not found |
| 5 | + |
| 6 | +archive: replace write_or_die() calls with |
| 7 | +write_block_or_die() MinGit for Windows comes without `gzip` bundled inside, |
| 8 | +git-archive uses `gzip -cn` to compress tar files but for this to work, gzip |
| 9 | +needs to be present on the host system, which sometimes is not the case |
| 10 | + |
| 11 | +In the next commit, we will change the gzip compression |
| 12 | +so that we no longer spawn `gzip` but let zlib perform |
| 13 | +the compression in the same process |
| 14 | + |
| 15 | +In preparation for this, we consolidate all the block |
| 16 | +writes into a single function |
| 17 | + |
| 18 | +Closes: #1970 |
| 19 | +Signed-off-by: Rohit Ashiwal < [email protected]> |
| 20 | +--- |
| 21 | + archive-tar.c | 20 ++++++++++++++++---- |
| 22 | + 1 file changed, 16 insertions(+), 4 deletions(-) |
| 23 | + |
| 24 | +diff --git a/archive-tar.c b/archive-tar.c |
| 25 | +index a58e1a8ebf..33795075a4 100644 |
| 26 | +--- a/archive-tar.c |
| 27 | ++++ b/archive-tar.c |
| 28 | +@@ -17,6 +17,8 @@ static unsigned long offset; |
| 29 | + |
| 30 | + static int tar_umask = 002; |
| 31 | + |
| 32 | ++static gzFile gzip; |
| 33 | ++ |
| 34 | + static int write_tar_filter_archive(const struct archiver *ar, |
| 35 | + struct archiver_args *args); |
| 36 | + |
| 37 | +@@ -38,11 +40,21 @@ static int write_tar_filter_archive(const struct archiver *ar, |
| 38 | + #define USTAR_MAX_MTIME 077777777777ULL |
| 39 | + #endif |
| 40 | + |
| 41 | ++/* writes out the whole block, or dies if fails */ |
| 42 | ++static void write_block_or_die(const char *block) { |
| 43 | ++ if (gzip) { |
| 44 | ++ if (gzwrite(gzip, block, (unsigned) BLOCKSIZE) != BLOCKSIZE) |
| 45 | ++ die(_("gzwrite failed")); |
| 46 | ++ } else { |
| 47 | ++ write_or_die(1, block, BLOCKSIZE); |
| 48 | ++ } |
| 49 | ++} |
| 50 | ++ |
| 51 | + /* writes out the whole block, but only if it is full */ |
| 52 | + static void write_if_needed(void) |
| 53 | + { |
| 54 | + if (offset == BLOCKSIZE) { |
| 55 | +- write_or_die(1, block, BLOCKSIZE); |
| 56 | ++ write_block_or_die(block); |
| 57 | + offset = 0; |
| 58 | + } |
| 59 | + } |
| 60 | +@@ -66,7 +78,7 @@ static void do_write_blocked(const void *data, unsigned long size) |
| 61 | + write_if_needed(); |
| 62 | + } |
| 63 | + while (size >= BLOCKSIZE) { |
| 64 | +- write_or_die(1, buf, BLOCKSIZE); |
| 65 | ++ write_block_or_die(buf); |
| 66 | + size -= BLOCKSIZE; |
| 67 | + buf += BLOCKSIZE; |
| 68 | + } |
| 69 | +@@ -101,10 +113,10 @@ static void write_trailer(void) |
| 70 | + { |
| 71 | + int tail = BLOCKSIZE - offset; |
| 72 | + memset(block + offset, 0, tail); |
| 73 | +- write_or_die(1, block, BLOCKSIZE); |
| 74 | ++ write_block_or_die(block); |
| 75 | + if (tail < 2 * RECORDSIZE) { |
| 76 | + memset(block, 0, offset); |
| 77 | +- write_or_die(1, block, BLOCKSIZE); |
| 78 | ++ write_block_or_die(block); |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | +-- |
| 83 | +2.21.0 |
| 84 | + |
0 commit comments