git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
blob 90a98c44ce9fd8015affa0e5157ef313979bf0ef 1390 bytes (raw)
name: builtin/gzip.c 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
 
#include "cache.h"
#include "builtin.h"
#include "parse-options.h"

static const char * const gzip_usage[] = {
	N_("git gzip [-NUM]"),
	NULL
};

static int level_callback(const struct option *opt, const char *arg, int unset)
{
	int *levelp = opt->value;
	int value;
	const char *endp;

	if (unset)
		BUG("switch -NUM cannot be negated");

	value = strtol(arg, (char **)&endp, 10);
	if (*endp)
		BUG("switch -NUM cannot be non-numeric");

	*levelp = value;
	return 0;
}

#define BUFFERSIZE (64 * 1024)

int cmd_gzip(int argc, const char **argv, const char *prefix)
{
	gzFile gz;
	int level = Z_DEFAULT_COMPRESSION;
	struct option options[] = {
		OPT_NUMBER_CALLBACK(&level, N_("compression level"),
				    level_callback),
		OPT_END()
	};

	argc = parse_options(argc, argv, prefix, options, gzip_usage, 0);
	if (argc > 0)
		usage_with_options(gzip_usage, options);

	gz = gzdopen(1, "wb");
	if (!gz)
		die(_("unable to gzdopen stdout"));

	if (gzsetparams(gz, level, Z_DEFAULT_STRATEGY) != Z_OK)
		die(_("unable to set compression level %d"), level);

	for (;;) {
		char buf[BUFFERSIZE];
		ssize_t read_bytes = xread(0, buf, sizeof(buf));
		if (read_bytes < 0)
			die_errno(_("unable to read from stdin"));
		if (read_bytes == 0)
			break;
		if (gzwrite(gz, buf, read_bytes) != read_bytes)
			die(_("gzwrite failed"));
	}

	if (gzclose(gz) != Z_OK)
		die(_("gzclose failed"));
	return 0;
}

debug log:

solving 90a98c44ce ...
found 90a98c44ce in https://public-inbox.org/git/45afd432-9e45-ea76-aa1b-e8cd1264e3a0@web.de/

applying [1/1] https://public-inbox.org/git/45afd432-9e45-ea76-aa1b-e8cd1264e3a0@web.de/
diff --git a/builtin/gzip.c b/builtin/gzip.c
new file mode 100644
index 0000000000..90a98c44ce

Checking patch builtin/gzip.c...
Applied patch builtin/gzip.c cleanly.

index at:
100644 90a98c44ce9fd8015affa0e5157ef313979bf0ef	builtin/gzip.c

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).