зеркало из https://github.com/microsoft/git.git
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>
This commit is contained in:
Родитель
3ab228137f
Коммит
8de7eeb54b
|
@ -61,8 +61,6 @@ static int delta_search_threads;
|
|||
static int pack_to_stdout;
|
||||
static int num_preferred_base;
|
||||
static struct progress *progress_state;
|
||||
static int pack_compression_level = Z_DEFAULT_COMPRESSION;
|
||||
static int pack_compression_seen;
|
||||
|
||||
static struct packed_git *reuse_packfile;
|
||||
static uint32_t reuse_packfile_objects;
|
||||
|
@ -2368,16 +2366,6 @@ static int git_pack_config(const char *k, const char *v, void *cb)
|
|||
depth = git_config_int(k, v);
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(k, "pack.compression")) {
|
||||
int level = git_config_int(k, v);
|
||||
if (level == -1)
|
||||
level = Z_DEFAULT_COMPRESSION;
|
||||
else if (level < 0 || level > Z_BEST_COMPRESSION)
|
||||
die("bad pack compression level %d", level);
|
||||
pack_compression_level = level;
|
||||
pack_compression_seen = 1;
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(k, "pack.deltacachesize")) {
|
||||
max_delta_cache_size = git_config_int(k, v);
|
||||
return 0;
|
||||
|
@ -2869,8 +2857,6 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
|
|||
|
||||
reset_pack_idx_option(&pack_idx_opts);
|
||||
git_config(git_pack_config, NULL);
|
||||
if (!pack_compression_seen && core_compression_seen)
|
||||
pack_compression_level = core_compression_level;
|
||||
|
||||
progress = isatty(2);
|
||||
argc = parse_options(argc, argv, prefix, pack_objects_options,
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
#include "pack.h"
|
||||
#include "strbuf.h"
|
||||
|
||||
static int pack_compression_level = Z_DEFAULT_COMPRESSION;
|
||||
|
||||
static struct bulk_checkin_state {
|
||||
unsigned plugged:1;
|
||||
|
||||
|
|
2
cache.h
2
cache.h
|
@ -670,7 +670,7 @@ extern const char *git_attributes_file;
|
|||
extern const char *git_hooks_path;
|
||||
extern int zlib_compression_level;
|
||||
extern int core_compression_level;
|
||||
extern int core_compression_seen;
|
||||
extern int pack_compression_level;
|
||||
extern size_t packed_git_window_size;
|
||||
extern size_t packed_git_limit;
|
||||
extern size_t delta_base_cache_limit;
|
||||
|
|
16
config.c
16
config.c
|
@ -66,6 +66,8 @@ static struct key_value_info *current_config_kvi;
|
|||
*/
|
||||
static enum config_scope current_parsing_scope;
|
||||
|
||||
static int core_compression_seen;
|
||||
static int pack_compression_seen;
|
||||
static int zlib_compression_seen;
|
||||
|
||||
/*
|
||||
|
@ -865,6 +867,8 @@ static int git_default_core_config(const char *var, const char *value)
|
|||
core_compression_seen = 1;
|
||||
if (!zlib_compression_seen)
|
||||
zlib_compression_level = level;
|
||||
if (!pack_compression_seen)
|
||||
pack_compression_level = level;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1125,6 +1129,18 @@ int git_default_config(const char *var, const char *value, void *dummy)
|
|||
pack_size_limit_cfg = git_config_ulong(var, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!strcmp(var, "pack.compression")) {
|
||||
int level = git_config_int(var, value);
|
||||
if (level == -1)
|
||||
level = Z_DEFAULT_COMPRESSION;
|
||||
else if (level < 0 || level > Z_BEST_COMPRESSION)
|
||||
die(_("bad pack compression level %d"), level);
|
||||
pack_compression_level = level;
|
||||
pack_compression_seen = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Add other config variables here and to Documentation/config.txt. */
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ const char *git_attributes_file;
|
|||
const char *git_hooks_path;
|
||||
int zlib_compression_level = Z_BEST_SPEED;
|
||||
int core_compression_level;
|
||||
int core_compression_seen;
|
||||
int pack_compression_level = Z_DEFAULT_COMPRESSION;
|
||||
int fsync_object_files;
|
||||
size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
|
||||
size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
|
||||
|
|
|
@ -284,8 +284,6 @@ static unsigned long max_depth = 10;
|
|||
static off_t max_packsize;
|
||||
static int unpack_limit = 100;
|
||||
static int force_update;
|
||||
static int pack_compression_level = Z_DEFAULT_COMPRESSION;
|
||||
static int pack_compression_seen;
|
||||
|
||||
/* Stats and misc. counters */
|
||||
static uintmax_t alloc_count;
|
||||
|
@ -3381,15 +3379,6 @@ static void git_pack_config(void)
|
|||
if (max_depth > MAX_DEPTH)
|
||||
max_depth = MAX_DEPTH;
|
||||
}
|
||||
if (!git_config_get_int("pack.compression", &pack_compression_level)) {
|
||||
if (pack_compression_level == -1)
|
||||
pack_compression_level = Z_DEFAULT_COMPRESSION;
|
||||
else if (pack_compression_level < 0 ||
|
||||
pack_compression_level > Z_BEST_COMPRESSION)
|
||||
git_die_config("pack.compression",
|
||||
"bad pack compression level %d", pack_compression_level);
|
||||
pack_compression_seen = 1;
|
||||
}
|
||||
if (!git_config_get_int("pack.indexversion", &indexversion_value)) {
|
||||
pack_idx_opts.version = indexversion_value;
|
||||
if (pack_idx_opts.version > 2)
|
||||
|
@ -3454,8 +3443,6 @@ int cmd_main(int argc, const char **argv)
|
|||
setup_git_directory();
|
||||
reset_pack_idx_option(&pack_idx_opts);
|
||||
git_pack_config();
|
||||
if (!pack_compression_seen && core_compression_seen)
|
||||
pack_compression_level = core_compression_level;
|
||||
|
||||
alloc_objects(object_entry_alloc);
|
||||
strbuf_init(&command_buf, 0);
|
||||
|
|
|
@ -5,6 +5,12 @@ test_description='adding and checking out large blobs'
|
|||
|
||||
. ./test-lib.sh
|
||||
|
||||
# This should be moved to test-lib.sh together with the
|
||||
# copy in t0021 after both topics have graduated to 'master'.
|
||||
file_size () {
|
||||
perl -e 'print -s $ARGV[0]' "$1"
|
||||
}
|
||||
|
||||
test_expect_success setup '
|
||||
# clone does not allow us to pass core.bigfilethreshold to
|
||||
# new repos, so set core.bigfilethreshold globally
|
||||
|
@ -17,6 +23,29 @@ test_expect_success setup '
|
|||
export GIT_ALLOC_LIMIT
|
||||
'
|
||||
|
||||
# add a large file with different settings
|
||||
while read expect config
|
||||
do
|
||||
test_expect_success "add with $config" '
|
||||
test_when_finished "rm -f .git/objects/pack/pack-*.* .git/index" &&
|
||||
git $config add large1 &&
|
||||
sz=$(file_size .git/objects/pack/pack-*.pack) &&
|
||||
case "$expect" in
|
||||
small) test "$sz" -le 100000 ;;
|
||||
large) test "$sz" -ge 100000 ;;
|
||||
esac
|
||||
'
|
||||
done <<\EOF
|
||||
large -c core.compression=0
|
||||
small -c core.compression=9
|
||||
large -c core.compression=0 -c pack.compression=0
|
||||
large -c core.compression=9 -c pack.compression=0
|
||||
small -c core.compression=0 -c pack.compression=9
|
||||
small -c core.compression=9 -c pack.compression=9
|
||||
large -c pack.compression=0
|
||||
small -c pack.compression=9
|
||||
EOF
|
||||
|
||||
test_expect_success 'add a large file or two' '
|
||||
git add large1 huge large2 &&
|
||||
# make sure we got a single packfile and no loose objects
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
#!/bin/sh
|
||||
|
||||
test_description='pack-object compression configuration'
|
||||
|
||||
. ./test-lib.sh
|
||||
|
||||
# This should be moved to test-lib.sh together with the
|
||||
# copy in t0021 after both topics have graduated to 'master'.
|
||||
file_size () {
|
||||
perl -e 'print -s $ARGV[0]' "$1"
|
||||
}
|
||||
|
||||
test_expect_success setup '
|
||||
printf "%2000000s" X |
|
||||
git hash-object -w --stdin >object-name &&
|
||||
# make sure it resulted in a loose object
|
||||
ob=$(sed -e "s/\(..\).*/\1/" object-name) &&
|
||||
ject=$(sed -e "s/..\(.*\)/\1/" object-name) &&
|
||||
test -f .git/objects/$ob/$ject
|
||||
'
|
||||
|
||||
while read expect config
|
||||
do
|
||||
test_expect_success "pack-objects with $config" '
|
||||
test_when_finished "rm -f pack-*.*" &&
|
||||
git $config pack-objects pack <object-name &&
|
||||
sz=$(file_size pack-*.pack) &&
|
||||
case "$expect" in
|
||||
small) test "$sz" -le 100000 ;;
|
||||
large) test "$sz" -ge 100000 ;;
|
||||
esac
|
||||
'
|
||||
done <<\EOF
|
||||
large -c core.compression=0
|
||||
small -c core.compression=9
|
||||
large -c core.compression=0 -c pack.compression=0
|
||||
large -c core.compression=9 -c pack.compression=0
|
||||
small -c core.compression=0 -c pack.compression=9
|
||||
small -c core.compression=9 -c pack.compression=9
|
||||
large -c pack.compression=0
|
||||
small -c pack.compression=9
|
||||
EOF
|
||||
|
||||
test_done
|
|
@ -0,0 +1,67 @@
|
|||
#!/bin/sh
|
||||
|
||||
test_description='compression setting of fast-import utility'
|
||||
. ./test-lib.sh
|
||||
|
||||
# This should be moved to test-lib.sh together with the
|
||||
# copy in t0021 after both topics have graduated to 'master'.
|
||||
file_size () {
|
||||
perl -e 'print -s $ARGV[0]' "$1"
|
||||
}
|
||||
|
||||
import_large () {
|
||||
(
|
||||
echo blob
|
||||
echo "data <<EOD"
|
||||
printf "%2000000s\n" "$*"
|
||||
echo EOD
|
||||
) | git "$@" fast-import
|
||||
}
|
||||
|
||||
while read expect config
|
||||
do
|
||||
test_expect_success "fast-import (packed) with $config" '
|
||||
test_when_finished "rm -f .git/objects/pack/pack-*.*" &&
|
||||
test_when_finished "rm -rf .git/objects/??" &&
|
||||
import_large -c fastimport.unpacklimit=0 $config &&
|
||||
sz=$(file_size .git/objects/pack/pack-*.pack) &&
|
||||
case "$expect" in
|
||||
small) test "$sz" -le 100000 ;;
|
||||
large) test "$sz" -ge 100000 ;;
|
||||
esac
|
||||
'
|
||||
done <<\EOF
|
||||
large -c core.compression=0
|
||||
small -c core.compression=9
|
||||
large -c core.compression=0 -c pack.compression=0
|
||||
large -c core.compression=9 -c pack.compression=0
|
||||
small -c core.compression=0 -c pack.compression=9
|
||||
small -c core.compression=9 -c pack.compression=9
|
||||
large -c pack.compression=0
|
||||
small -c pack.compression=9
|
||||
EOF
|
||||
|
||||
while read expect config
|
||||
do
|
||||
test_expect_success "fast-import (loose) with $config" '
|
||||
test_when_finished "rm -f .git/objects/pack/pack-*.*" &&
|
||||
test_when_finished "rm -rf .git/objects/??" &&
|
||||
import_large -c fastimport.unpacklimit=9 $config &&
|
||||
sz=$(file_size .git/objects/??/????*) &&
|
||||
case "$expect" in
|
||||
small) test "$sz" -le 100000 ;;
|
||||
large) test "$sz" -ge 100000 ;;
|
||||
esac
|
||||
'
|
||||
done <<\EOF
|
||||
large -c core.compression=0
|
||||
small -c core.compression=9
|
||||
large -c core.compression=0 -c core.loosecompression=0
|
||||
large -c core.compression=9 -c core.loosecompression=0
|
||||
small -c core.compression=0 -c core.loosecompression=9
|
||||
small -c core.compression=9 -c core.loosecompression=9
|
||||
large -c core.loosecompression=0
|
||||
small -c core.loosecompression=9
|
||||
EOF
|
||||
|
||||
test_done
|
Загрузка…
Ссылка в новой задаче