Skip to content

Commit 6c7bf51

Browse files
r1walzdscho
authored andcommitted
archive: avoid spawning gzip
As we already link to the zlib library, we can perform the compression without even requiring gzip on the host machine. Signed-off-by: Rohit Ashiwal <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 99fa223 commit 6c7bf51

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

archive-tar.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -467,18 +467,34 @@ static int write_tar_filter_archive(const struct archiver *ar,
467467
filter.use_shell = 1;
468468
filter.in = -1;
469469

470-
if (start_command(&filter) < 0)
471-
die_errno(_("unable to start '%s' filter"), argv[0]);
472-
close(1);
473-
if (dup2(filter.in, 1) < 0)
474-
die_errno(_("unable to redirect descriptor"));
475-
close(filter.in);
470+
if (!strcmp("gzip -cn", ar->data)) {
471+
char outmode[4] = "wb\0";
472+
473+
if (args->compression_level >= 0 && args->compression_level <= 9)
474+
outmode[2] = '0' + args->compression_level;
475+
476+
gzip = gzdopen(fileno(stdout), outmode);
477+
if (!gzip)
478+
die(_("Could not gzdopen stdout"));
479+
} else {
480+
if (start_command(&filter) < 0)
481+
die_errno(_("unable to start '%s' filter"), argv[0]);
482+
close(1);
483+
if (dup2(filter.in, 1) < 0)
484+
die_errno(_("unable to redirect descriptor"));
485+
close(filter.in);
486+
}
476487

477488
r = write_tar_archive(ar, args);
478489

479-
close(1);
480-
if (finish_command(&filter) != 0)
481-
die(_("'%s' filter reported error"), argv[0]);
490+
if (gzip) {
491+
if (gzclose(gzip) != Z_OK)
492+
die(_("gzclose failed"));
493+
} else {
494+
close(1);
495+
if (finish_command(&filter) != 0)
496+
die(_("'%s' filter reported error"), argv[0]);
497+
}
482498

483499
strbuf_release(&cmd);
484500
return r;

0 commit comments

Comments
 (0)