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 `zlib` library, we can perform the
compression without even requiring gzip on the host
machine

We modify write_tar_filter_archive() function in archive-tar.c
to handle the compression when `gzip -cn` is requested

Signed-off-by: Rohit Ashiwal <rohit.ashiwal265@gmail.com>
  • Loading branch information
r1walz committed Feb 19, 2019
1 parent e00dd10 commit f31f5cf
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 @@ -466,18 +466,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 f31f5cf

Please sign in to comment.