@matheusbsbs / matheus-bagliano / commits / 12f6c308d5
Fork 0

Make zlib compression level configurable, and change default.

With the change in default, "git add ." on kernel dir is about twice as fast as before, with only minimal (0.5%) change in object size. The speed difference is even more noticeable when committing large files, which is now up to 8 times faster. The configurability is through setting core.compression = [-1..9] which maps to the zlib constants; -1 is the default, 0 is no compression, and 1..9 are various speed/size tradeoffs, 9 being slowest. Signed-off-by: Joachim B Haga (cjhaga@fys.uio.no) Acked-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Joachim B Haga committed Jul 3, 2006 at 22:11 UTC 12f6c308d53509dcb11e309604457d21d60438db
8 files changed +23 -5
Documentation/config.txt
+6
@@ -91,6 +91,12 @@ core.warnAmbiguousRefs::
91 If true, git will warn you if the ref name you passed it is ambiguous
92 and might match multiple refs in the .git/refs/ tree. True by default.
93
94 +core.compression:
95 + An integer -1..9, indicating the compression level for objects that
96 + are not in a pack file. -1 is the zlib and git default. 0 means no
97 + compression, and 1..9 are various speed/size tradeoffs, 9 being
98 + slowest.
99 +
100 alias.*::
101 Command aliases for the gitlink:git[1] command wrapper - e.g.
102 after defining "alias.last = cat-file commit HEAD", the invocation
cache.h
+1
@@ -183,6 +183,7 @@ extern int log_all_ref_updates;
183 extern int warn_ambiguous_refs;
184 extern int shared_repository;
185 extern const char *apply_default_whitespace;
186 +extern int zlib_compression_level;
187
188 #define GIT_REPO_VERSION 0
189 extern int repository_format_version;
config.c
+10
@@ -279,6 +279,16 @@ int git_default_config(const char *var, const char *value)
279 return 0;
280 }
281
282 + if (!strcmp(var, "core.compression")) {
283 + int level = git_config_int(var, value);
284 + if (level == -1)
285 + level = Z_DEFAULT_COMPRESSION;
286 + else if (level < 0 || level > Z_BEST_COMPRESSION)
287 + die("bad zlib compression level %d", level);
288 + zlib_compression_level = level;
289 + return 0;
290 + }
291 +
292 if (!strcmp(var, "user.name")) {
293 strlcpy(git_default_name, value, sizeof(git_default_name));
294 return 0;
csum-file.c
+1 -1
@@ -122,7 +122,7 @@ int sha1write_compressed(struct sha1file *f, void *in, unsigned int size)
122 void *out;
123
124 memset(&stream, 0, sizeof(stream));
125 - deflateInit(&stream, Z_DEFAULT_COMPRESSION);
125 + deflateInit(&stream, zlib_compression_level);
126 maxsize = deflateBound(&stream, size);
127 out = xmalloc(maxsize);
128
diff.c
+1 -1
@@ -583,7 +583,7 @@ static unsigned char *deflate_it(char *data,
583 z_stream stream;
584
585 memset(&stream, 0, sizeof(stream));
586 - deflateInit(&stream, Z_BEST_COMPRESSION);
586 + deflateInit(&stream, zlib_compression_level);
587 bound = deflateBound(&stream, size);
588 deflated = xmalloc(bound);
589 stream.next_out = deflated;
environment.c
+1
@@ -20,6 +20,7 @@ int repository_format_version = 0;
20 char git_commit_encoding[MAX_ENCODING_LENGTH] = "utf-8";
21 int shared_repository = PERM_UMASK;
22 const char *apply_default_whitespace = NULL;
23 +int zlib_compression_level = Z_DEFAULT_COMPRESSION;
24
25 static char *git_dir, *git_object_dir, *git_index_file, *git_refs_dir,
26 *git_graft_file;
http-push.c
+1 -1
@@ -492,7 +492,7 @@ static void start_put(struct transfer_request *request)
492
493 /* Set it up */
494 memset(&stream, 0, sizeof(stream));
495 - deflateInit(&stream, Z_BEST_COMPRESSION);
495 + deflateInit(&stream, zlib_compression_level);
496 size = deflateBound(&stream, len + hdrlen);
497 request->buffer.buffer = xmalloc(size);
498
sha1_file.c
+2 -2
@@ -1458,7 +1458,7 @@ int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned cha
1458
1459 /* Set it up */
1460 memset(&stream, 0, sizeof(stream));
1461 - deflateInit(&stream, Z_BEST_COMPRESSION);
1461 + deflateInit(&stream, zlib_compression_level);
1462 size = deflateBound(&stream, len+hdrlen);
1463 compressed = xmalloc(size);
1464
@@ -1511,7 +1511,7 @@ static void *repack_object(const unsigned char *sha1, unsigned long *objsize)
1511
1512 /* Set it up */
1513 memset(&stream, 0, sizeof(stream));
1514 - deflateInit(&stream, Z_BEST_COMPRESSION);
1514 + deflateInit(&stream, zlib_compression_level);
1515 size = deflateBound(&stream, len + hdrlen);
1516 buf = xmalloc(size);
1517