Skip to content

Commit 8de7eeb

Browse files
committed
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 <[email protected]>
1 parent 3ab2281 commit 8de7eeb

File tree

9 files changed

+158
-31
lines changed

9 files changed

+158
-31
lines changed

builtin/pack-objects.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ static int delta_search_threads;
6161
static int pack_to_stdout;
6262
static int num_preferred_base;
6363
static struct progress *progress_state;
64-
static int pack_compression_level = Z_DEFAULT_COMPRESSION;
65-
static int pack_compression_seen;
6664

6765
static struct packed_git *reuse_packfile;
6866
static uint32_t reuse_packfile_objects;
@@ -2368,16 +2366,6 @@ static int git_pack_config(const char *k, const char *v, void *cb)
23682366
depth = git_config_int(k, v);
23692367
return 0;
23702368
}
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-
}
23812369
if (!strcmp(k, "pack.deltacachesize")) {
23822370
max_delta_cache_size = git_config_int(k, v);
23832371
return 0;
@@ -2869,8 +2857,6 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
28692857

28702858
reset_pack_idx_option(&pack_idx_opts);
28712859
git_config(git_pack_config, NULL);
2872-
if (!pack_compression_seen && core_compression_seen)
2873-
pack_compression_level = core_compression_level;
28742860

28752861
progress = isatty(2);
28762862
argc = parse_options(argc, argv, prefix, pack_objects_options,

bulk-checkin.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#include "pack.h"
88
#include "strbuf.h"
99

10-
static int pack_compression_level = Z_DEFAULT_COMPRESSION;
11-
1210
static struct bulk_checkin_state {
1311
unsigned plugged:1;
1412

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ extern const char *git_attributes_file;
670670
extern const char *git_hooks_path;
671671
extern int zlib_compression_level;
672672
extern int core_compression_level;
673-
extern int core_compression_seen;
673+
extern int pack_compression_level;
674674
extern size_t packed_git_window_size;
675675
extern size_t packed_git_limit;
676676
extern size_t delta_base_cache_limit;

config.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ static struct key_value_info *current_config_kvi;
6666
*/
6767
static enum config_scope current_parsing_scope;
6868

69+
static int core_compression_seen;
70+
static int pack_compression_seen;
6971
static int zlib_compression_seen;
7072

7173
/*
@@ -865,6 +867,8 @@ static int git_default_core_config(const char *var, const char *value)
865867
core_compression_seen = 1;
866868
if (!zlib_compression_seen)
867869
zlib_compression_level = level;
870+
if (!pack_compression_seen)
871+
pack_compression_level = level;
868872
return 0;
869873
}
870874

@@ -1125,6 +1129,18 @@ int git_default_config(const char *var, const char *value, void *dummy)
11251129
pack_size_limit_cfg = git_config_ulong(var, value);
11261130
return 0;
11271131
}
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+
11281144
/* Add other config variables here and to Documentation/config.txt. */
11291145
return 0;
11301146
}

environment.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const char *git_attributes_file;
3434
const char *git_hooks_path;
3535
int zlib_compression_level = Z_BEST_SPEED;
3636
int core_compression_level;
37-
int core_compression_seen;
37+
int pack_compression_level = Z_DEFAULT_COMPRESSION;
3838
int fsync_object_files;
3939
size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
4040
size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;

fast-import.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,6 @@ static unsigned long max_depth = 10;
284284
static off_t max_packsize;
285285
static int unpack_limit = 100;
286286
static int force_update;
287-
static int pack_compression_level = Z_DEFAULT_COMPRESSION;
288-
static int pack_compression_seen;
289287

290288
/* Stats and misc. counters */
291289
static uintmax_t alloc_count;
@@ -3381,15 +3379,6 @@ static void git_pack_config(void)
33813379
if (max_depth > MAX_DEPTH)
33823380
max_depth = MAX_DEPTH;
33833381
}
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-
}
33933382
if (!git_config_get_int("pack.indexversion", &indexversion_value)) {
33943383
pack_idx_opts.version = indexversion_value;
33953384
if (pack_idx_opts.version > 2)
@@ -3454,8 +3443,6 @@ int cmd_main(int argc, const char **argv)
34543443
setup_git_directory();
34553444
reset_pack_idx_option(&pack_idx_opts);
34563445
git_pack_config();
3457-
if (!pack_compression_seen && core_compression_seen)
3458-
pack_compression_level = core_compression_level;
34593446

34603447
alloc_objects(object_entry_alloc);
34613448
strbuf_init(&command_buf, 0);

t/t1050-large.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ test_description='adding and checking out large blobs'
55

66
. ./test-lib.sh
77

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+
814
test_expect_success setup '
915
# clone does not allow us to pass core.bigfilethreshold to
1016
# new repos, so set core.bigfilethreshold globally
@@ -17,6 +23,29 @@ test_expect_success setup '
1723
export GIT_ALLOC_LIMIT
1824
'
1925

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+
2049
test_expect_success 'add a large file or two' '
2150
git add large1 huge large2 &&
2251
# make sure we got a single packfile and no loose objects

t/t5315-pack-objects-compression.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)