compression: unify pack.compression configuration parsing

There are three codepaths that use a variable whose name is pack_compression_level to affect how objects and deltas sent to a packfile is compressed. Unlike zlib_compression_level that controls the loose object compression, however, this variable was static to each of these codepaths. Two of them read the pack.compression configuration variable, using core.compression as the default, and one of them also allowed overriding it from the command line. The other codepath in bulk-checkin did not pay any attention to the configuration. Unify the configuration parsing to git_default_config(), where we implement the parsing of core.loosecompression and core.compression and make the former override the latter, by moving code to parse pack.compression and also allow core.compression to give default to this variable. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Nov 15, 2016 at 17:42 UTC 8de7eeb54b6aaa6d429b5d9c2b667847c35480ff
9 files changed +158 -31
builtin/pack-objects.c
-14
@@ -61,8 +61,6 @@ static int delta_search_threads;
61 static int pack_to_stdout;
62 static int num_preferred_base;
63 static struct progress *progress_state;
64 -static int pack_compression_level = Z_DEFAULT_COMPRESSION;
65 -static int pack_compression_seen;
64
65 static struct packed_git *reuse_packfile;
66 static uint32_t reuse_packfile_objects;
@@ -2368,16 +2366,6 @@ static int git_pack_config(const char *k, const char *v, void *cb)
2366 depth = git_config_int(k, v);
2367 return 0;
2368 }
2371 - if (!strcmp(k, "pack.compression")) {
2372 - int level = git_config_int(k, v);
2373 - if (level == -1)
2374 - level = Z_DEFAULT_COMPRESSION;
2375 - else if (level < 0 || level > Z_BEST_COMPRESSION)
2376 - die("bad pack compression level %d", level);
2377 - pack_compression_level = level;
2378 - pack_compression_seen = 1;
2379 - return 0;
2380 - }
2369 if (!strcmp(k, "pack.deltacachesize")) {
2370 max_delta_cache_size = git_config_int(k, v);
2371 return 0;
@@ -2869,8 +2857,6 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
2857
2858 reset_pack_idx_option(&pack_idx_opts);
2859 git_config(git_pack_config, NULL);
2872 - if (!pack_compression_seen && core_compression_seen)
2873 - pack_compression_level = core_compression_level;
2860
2861 progress = isatty(2);
2862 argc = parse_options(argc, argv, prefix, pack_objects_options,
bulk-checkin.c
-2
@@ -7,8 +7,6 @@
7 #include "pack.h"
8 #include "strbuf.h"
9
10 -static int pack_compression_level = Z_DEFAULT_COMPRESSION;
11 -
10 static struct bulk_checkin_state {
11 unsigned plugged:1;
12
cache.h
+1 -1
@@ -670,7 +670,7 @@ extern const char *git_attributes_file;
670 extern const char *git_hooks_path;
671 extern int zlib_compression_level;
672 extern int core_compression_level;
673 -extern int core_compression_seen;
673 +extern int pack_compression_level;
674 extern size_t packed_git_window_size;
675 extern size_t packed_git_limit;
676 extern size_t delta_base_cache_limit;
config.c
+16
@@ -66,6 +66,8 @@ static struct key_value_info *current_config_kvi;
66 */
67 static enum config_scope current_parsing_scope;
68
69 +static int core_compression_seen;
70 +static int pack_compression_seen;
71 static int zlib_compression_seen;
72
73 /*
@@ -865,6 +867,8 @@ static int git_default_core_config(const char *var, const char *value)
867 core_compression_seen = 1;
868 if (!zlib_compression_seen)
869 zlib_compression_level = level;
870 + if (!pack_compression_seen)
871 + pack_compression_level = level;
872 return 0;
873 }
874
@@ -1125,6 +1129,18 @@ int git_default_config(const char *var, const char *value, void *dummy)
1129 pack_size_limit_cfg = git_config_ulong(var, value);
1130 return 0;
1131 }
1132 +
1133 + if (!strcmp(var, "pack.compression")) {
1134 + int level = git_config_int(var, value);
1135 + if (level == -1)
1136 + level = Z_DEFAULT_COMPRESSION;
1137 + else if (level < 0 || level > Z_BEST_COMPRESSION)
1138 + die(_("bad pack compression level %d"), level);
1139 + pack_compression_level = level;
1140 + pack_compression_seen = 1;
1141 + return 0;
1142 + }
1143 +
1144 /* Add other config variables here and to Documentation/config.txt. */
1145 return 0;
1146 }
environment.c
+1 -1
@@ -34,7 +34,7 @@ const char *git_attributes_file;
34 const char *git_hooks_path;
35 int zlib_compression_level = Z_BEST_SPEED;
36 int core_compression_level;
37 -int core_compression_seen;
37 +int pack_compression_level = Z_DEFAULT_COMPRESSION;
38 int fsync_object_files;
39 size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
40 size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
fast-import.c
-13
@@ -284,8 +284,6 @@ static unsigned long max_depth = 10;
284 static off_t max_packsize;
285 static int unpack_limit = 100;
286 static int force_update;
287 -static int pack_compression_level = Z_DEFAULT_COMPRESSION;
288 -static int pack_compression_seen;
287
288 /* Stats and misc. counters */
289 static uintmax_t alloc_count;
@@ -3381,15 +3379,6 @@ static void git_pack_config(void)
3379 if (max_depth > MAX_DEPTH)
3380 max_depth = MAX_DEPTH;
3381 }
3384 - if (!git_config_get_int("pack.compression", &pack_compression_level)) {
3385 - if (pack_compression_level == -1)
3386 - pack_compression_level = Z_DEFAULT_COMPRESSION;
3387 - else if (pack_compression_level < 0 ||
3388 - pack_compression_level > Z_BEST_COMPRESSION)
3389 - git_die_config("pack.compression",
3390 - "bad pack compression level %d", pack_compression_level);
3391 - pack_compression_seen = 1;
3392 - }
3382 if (!git_config_get_int("pack.indexversion", &indexversion_value)) {
3383 pack_idx_opts.version = indexversion_value;
3384 if (pack_idx_opts.version > 2)
@@ -3454,8 +3443,6 @@ int cmd_main(int argc, const char **argv)
3443 setup_git_directory();
3444 reset_pack_idx_option(&pack_idx_opts);
3445 git_pack_config();
3457 - if (!pack_compression_seen && core_compression_seen)
3458 - pack_compression_level = core_compression_level;
3446
3447 alloc_objects(object_entry_alloc);
3448 strbuf_init(&command_buf, 0);
t/t1050-large.sh
+29
@@ -5,6 +5,12 @@ test_description='adding and checking out large blobs'
5
6 . ./test-lib.sh
7
8 +# This should be moved to test-lib.sh together with the
9 +# copy in t0021 after both topics have graduated to 'master'.
10 +file_size () {
11 + perl -e 'print -s $ARGV[0]' "$1"
12 +}
13 +
14 test_expect_success setup '
15 # clone does not allow us to pass core.bigfilethreshold to
16 # new repos, so set core.bigfilethreshold globally
@@ -17,6 +23,29 @@ test_expect_success setup '
23 export GIT_ALLOC_LIMIT
24 '
25
26 +# add a large file with different settings
27 +while read expect config
28 +do
29 + test_expect_success "add with $config" '
30 + test_when_finished "rm -f .git/objects/pack/pack-*.* .git/index" &&
31 + git $config add large1 &&
32 + sz=$(file_size .git/objects/pack/pack-*.pack) &&
33 + case "$expect" in
34 + small) test "$sz" -le 100000 ;;
35 + large) test "$sz" -ge 100000 ;;
36 + esac
37 + '
38 +done <<\EOF
39 +large -c core.compression=0
40 +small -c core.compression=9
41 +large -c core.compression=0 -c pack.compression=0
42 +large -c core.compression=9 -c pack.compression=0
43 +small -c core.compression=0 -c pack.compression=9
44 +small -c core.compression=9 -c pack.compression=9
45 +large -c pack.compression=0
46 +small -c pack.compression=9
47 +EOF
48 +
49 test_expect_success 'add a large file or two' '
50 git add large1 huge large2 &&
51 # make sure we got a single packfile and no loose objects
t/t5315-pack-objects-compression.sh new
+44
@@ -0,0 +1,44 @@
1 +#!/bin/sh
2 +
3 +test_description='pack-object compression configuration'
4 +
5 +. ./test-lib.sh
6 +
7 +# This should be moved to test-lib.sh together with the
8 +# copy in t0021 after both topics have graduated to 'master'.
9 +file_size () {
10 + perl -e 'print -s $ARGV[0]' "$1"
11 +}
12 +
13 +test_expect_success setup '
14 + printf "%2000000s" X |
15 + git hash-object -w --stdin >object-name &&
16 + # make sure it resulted in a loose object
17 + ob=$(sed -e "s/\(..\).*/\1/" object-name) &&
18 + ject=$(sed -e "s/..\(.*\)/\1/" object-name) &&
19 + test -f .git/objects/$ob/$ject
20 +'
21 +
22 +while read expect config
23 +do
24 + test_expect_success "pack-objects with $config" '
25 + test_when_finished "rm -f pack-*.*" &&
26 + git $config pack-objects pack <object-name &&
27 + sz=$(file_size pack-*.pack) &&
28 + case "$expect" in
29 + small) test "$sz" -le 100000 ;;
30 + large) test "$sz" -ge 100000 ;;
31 + esac
32 + '
33 +done <<\EOF
34 +large -c core.compression=0
35 +small -c core.compression=9
36 +large -c core.compression=0 -c pack.compression=0
37 +large -c core.compression=9 -c pack.compression=0
38 +small -c core.compression=0 -c pack.compression=9
39 +small -c core.compression=9 -c pack.compression=9
40 +large -c pack.compression=0
41 +small -c pack.compression=9
42 +EOF
43 +
44 +test_done
t/t9303-fast-import-compression.sh new
+67
@@ -0,0 +1,67 @@
1 +#!/bin/sh
2 +
3 +test_description='compression setting of fast-import utility'
4 +. ./test-lib.sh
5 +
6 +# This should be moved to test-lib.sh together with the
7 +# copy in t0021 after both topics have graduated to 'master'.
8 +file_size () {
9 + perl -e 'print -s $ARGV[0]' "$1"
10 +}
11 +
12 +import_large () {
13 + (
14 + echo blob
15 + echo "data <<EOD"
16 + printf "%2000000s\n" "$*"
17 + echo EOD
18 + ) | git "$@" fast-import
19 +}
20 +
21 +while read expect config
22 +do
23 + test_expect_success "fast-import (packed) with $config" '
24 + test_when_finished "rm -f .git/objects/pack/pack-*.*" &&
25 + test_when_finished "rm -rf .git/objects/??" &&
26 + import_large -c fastimport.unpacklimit=0 $config &&
27 + sz=$(file_size .git/objects/pack/pack-*.pack) &&
28 + case "$expect" in
29 + small) test "$sz" -le 100000 ;;
30 + large) test "$sz" -ge 100000 ;;
31 + esac
32 + '
33 +done <<\EOF
34 +large -c core.compression=0
35 +small -c core.compression=9
36 +large -c core.compression=0 -c pack.compression=0
37 +large -c core.compression=9 -c pack.compression=0
38 +small -c core.compression=0 -c pack.compression=9
39 +small -c core.compression=9 -c pack.compression=9
40 +large -c pack.compression=0
41 +small -c pack.compression=9
42 +EOF
43 +
44 +while read expect config
45 +do
46 + test_expect_success "fast-import (loose) with $config" '
47 + test_when_finished "rm -f .git/objects/pack/pack-*.*" &&
48 + test_when_finished "rm -rf .git/objects/??" &&
49 + import_large -c fastimport.unpacklimit=9 $config &&
50 + sz=$(file_size .git/objects/??/????*) &&
51 + case "$expect" in
52 + small) test "$sz" -le 100000 ;;
53 + large) test "$sz" -ge 100000 ;;
54 + esac
55 + '
56 +done <<\EOF
57 +large -c core.compression=0
58 +small -c core.compression=9
59 +large -c core.compression=0 -c core.loosecompression=0
60 +large -c core.compression=9 -c core.loosecompression=0
61 +small -c core.compression=0 -c core.loosecompression=9
62 +small -c core.compression=9 -c core.loosecompression=9
63 +large -c core.loosecompression=0
64 +small -c core.loosecompression=9
65 +EOF
66 +
67 +test_done