Skip to content

Commit 57cf8de

Browse files
committed
add gzip bug patch from git-for-windows
see: git-for-windows/git#2077
0 parents  commit 57cf8de

File tree

3 files changed

+175
-0
lines changed

3 files changed

+175
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
From f31f5cf29030b1ee0fb25b61845404de054c4bd0 Mon Sep 17 00:00:00 2001
2+
From: Rohit Ashiwal <[email protected]>
3+
Date: Wed, 29 May 2019 09:04:15 +0530
4+
Subject: [PATCH 0/2] [FIX] git-archive error, gzip -cn : command not found
5+
6+
git-archive uses `gzip -cn` to compress tar files but for this to work, gzip needs
7+
to be present on the host system, which sometimes is not the case.
8+
9+
In our implementation, we are trying to add minimal code that will mimic gzip
10+
compression, so as to get rid of this gzip dependency.
11+
12+
Closes: git-for-windows/git#1970
13+
14+
Rohit Ashiwal (2):
15+
archive: replace write_or_die() calls with write_block_or_die()
16+
archive: avoid spawning `gzip`
17+
18+
archive-tar.c | 54 ++++++++++++++++++++++++++++++++++++++-------------
19+
1 file changed, 41 insertions(+), 13 deletions(-)
20+
21+
--
22+
2.21.0
23+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
From f31f5cf29030b1ee0fb25b61845404de054c4bd0 Mon Sep 17 00:00:00 2001
2+
From: Rohit Ashiwal <[email protected]>
3+
Date: Tue, 19 Feb 2019 22:28:41 +0530
4+
Subject: [PATCH 2/2] [FIX] git-archive error, gzip -cn : command not found
5+
6+
archive: avoid spawning `gzip` As we already link to
7+
`zlib` library, we can perform the compression without even requiring gzip on
8+
the host machine
9+
10+
We modify write_tar_filter_archive() function in archive-tar.c
11+
to handle the compression when `gzip -cn` is requested
12+
13+
Signed-off-by: Rohit Ashiwal <[email protected]>
14+
---
15+
archive-tar.c | 34 +++++++++++++++++++++++++---------
16+
1 file changed, 25 insertions(+), 9 deletions(-)
17+
18+
diff --git a/archive-tar.c b/archive-tar.c
19+
index 33795075a4..76738c2992 100644
20+
--- a/archive-tar.c
21+
+++ b/archive-tar.c
22+
@@ -466,18 +466,34 @@ static int write_tar_filter_archive(const struct archiver *ar,
23+
filter.use_shell = 1;
24+
filter.in = -1;
25+
26+
- if (start_command(&filter) < 0)
27+
- die_errno(_("unable to start '%s' filter"), argv[0]);
28+
- close(1);
29+
- if (dup2(filter.in, 1) < 0)
30+
- die_errno(_("unable to redirect descriptor"));
31+
- close(filter.in);
32+
+ if (!strcmp("gzip -cn", ar->data)) {
33+
+ char outmode[4] = "wb\0";
34+
+
35+
+ if (args->compression_level >= 0 && args->compression_level <= 9)
36+
+ outmode[2] = '0' + args->compression_level;
37+
+
38+
+ gzip = gzdopen(fileno(stdout), outmode);
39+
+ if (!gzip)
40+
+ die(_("Could not gzdopen stdout"));
41+
+ } else {
42+
+ if (start_command(&filter) < 0)
43+
+ die_errno(_("unable to start '%s' filter"), argv[0]);
44+
+ close(1);
45+
+ if (dup2(filter.in, 1) < 0)
46+
+ die_errno(_("unable to redirect descriptor"));
47+
+ close(filter.in);
48+
+ }
49+
50+
r = write_tar_archive(ar, args);
51+
52+
- close(1);
53+
- if (finish_command(&filter) != 0)
54+
- die(_("'%s' filter reported error"), argv[0]);
55+
+ if (gzip) {
56+
+ if (gzclose(gzip) != Z_OK)
57+
+ die(_("gzclose failed"));
58+
+ } else {
59+
+ close(1);
60+
+ if (finish_command(&filter) != 0)
61+
+ die(_("'%s' filter reported error"), argv[0]);
62+
+ }
63+
64+
strbuf_release(&cmd);
65+
return r;
66+
--
67+
2.21.0
68+

0 commit comments

Comments
 (0)