Skip to content

Commit

Permalink
archive: avoid spawning gzip
Browse files Browse the repository at this point in the history
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 <rohit.ashiwal265@gmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
r1walz authored and dscho committed Apr 20, 2020
1 parent 7804b61 commit 931de1e
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions archive-tar.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,18 +473,34 @@ static int write_tar_filter_archive(const struct archiver *ar,
filter.use_shell = 1;
filter.in = -1;

if (start_command(&filter) < 0)
die_errno(_("unable to start '%s' filter"), argv[0]);
close(1);
if (dup2(filter.in, 1) < 0)
die_errno(_("unable to redirect descriptor"));
close(filter.in);
if (!strcmp("gzip -cn", ar->data)) {
char outmode[4] = "wb\0";

if (args->compression_level >= 0 && args->compression_level <= 9)
outmode[2] = '0' + args->compression_level;

gzip = gzdopen(fileno(stdout), outmode);
if (!gzip)
die(_("Could not gzdopen stdout"));
} else {
if (start_command(&filter) < 0)
die_errno(_("unable to start '%s' filter"), argv[0]);
close(1);
if (dup2(filter.in, 1) < 0)
die_errno(_("unable to redirect descriptor"));
close(filter.in);
}

r = write_tar_archive(ar, args);

close(1);
if (finish_command(&filter) != 0)
die(_("'%s' filter reported error"), argv[0]);
if (gzip) {
if (gzclose(gzip) != Z_OK)
die(_("gzclose failed"));
} else {
close(1);
if (finish_command(&filter) != 0)
die(_("'%s' filter reported error"), argv[0]);
}

strbuf_release(&cmd);
return r;
Expand Down

0 comments on commit 931de1e

Please sign in to comment.