From 642316519154df7abbd75f346cd386f17feca5bb Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Mon, 15 May 2017 01:19:37 -0500 Subject: [PATCH] Honor git config pack.packSizeLimit when set Thanks to Ross Patterson for suggesting the improvement and proposing an earlier implementation. Signed-off-by: Rob Browning Tested-by: Rob Browning --- Makefile | 1 + lib/bup/git.py | 25 ++++++++++++++++++++++--- t/test-packsizelimit | 30 ++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100755 t/test-packsizelimit diff --git a/Makefile b/Makefile index 6a46b8d..62536f0 100644 --- a/Makefile +++ b/Makefile @@ -148,6 +148,7 @@ runtests-python: all t/tmp | tee -a t/tmp/test-log/$$$$.log cmdline_tests := \ + t/test-packsizelimit \ t/test-prune-older \ t/test-web.sh \ t/test-rm.sh \ diff --git a/lib/bup/git.py b/lib/bup/git.py index a0b42ff..950a2d4 100644 --- a/lib/bup/git.py +++ b/lib/bup/git.py @@ -12,6 +12,7 @@ from bup.helpers import (Sha1, add_error, chunkyreader, debug1, debug2, fdatasync, hostname, localtime, log, merge_iter, mmap_read, mmap_readwrite, + parse_num, progress, qprogress, stat_if_exists, unlink, username, userfullname, utc_offset_str) @@ -42,6 +43,18 @@ def _git_capture(argv): _git_wait(repr(argv), p) return r +def git_config_get(option, repo_dir=None): + cmd = ('git', 'config', '--get', option) + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, + preexec_fn=_gitenv(repo_dir=repo_dir)) + r = p.stdout.read() + rc = p.wait() + if rc == 0: + return r + if rc != 1: + raise GitError('%s returned %d' % (cmd, rc)) + return None + def parse_tz_offset(s): """UTC offset in seconds.""" @@ -606,9 +619,15 @@ class PackWriter: self.compression_level = compression_level self.run_midx=run_midx self.on_pack_finish = on_pack_finish - # larger packs will slow down pruning - self.max_pack_size = max_pack_size if max_pack_size \ - else 1000 * 1000 * 1000 + if not max_pack_size: + max_pack_size = git_config_get('pack.packSizeLimit', + repo_dir=self.repo_dir) + if max_pack_size is not None: + max_pack_size = parse_num(max_pack_size) + if not max_pack_size: + # larger packs slow down pruning + max_pack_size = 1000 * 1000 * 1000 + self.max_pack_size = max_pack_size # cache memory usage is about 83 bytes per object self.max_pack_objects = max_pack_objects if max_pack_objects \ else max(1, self.max_pack_size // 5000) diff --git a/t/test-packsizelimit b/t/test-packsizelimit new file mode 100755 index 0000000..6bd6a00 --- /dev/null +++ b/t/test-packsizelimit @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +. wvtest-bup.sh || exit $? +. t/lib.sh || exit $? + +set -o pipefail + +top="$(WVPASS pwd)" || exit $? +tmpdir="$(WVPASS wvmktempdir)" || exit $? +export BUP_DIR="$tmpdir/bup" +export GIT_DIR="$tmpdir/bup" + +bup() { "$top/bup" "$@"; } + +WVPASS cd "$tmpdir" + +WVSTART 'pack size limit' + +WVPASS bup init +WVPASSEQ $(WVPASS find "$BUP_DIR"/objects/pack -name "*.pack" | wc -l) 0 +WVPASS bup random 50k | WVPASS bup split -n foo +WVPASSEQ 1 $(WVPASS find "$BUP_DIR"/objects/pack/*.pack | wc -l) + +rm -rf "$BUP_DIR" +WVPASS bup init +WVPASS git config pack.packSizeLimit 10k +WVPASSEQ $(WVPASS find "$BUP_DIR"/objects/pack -name "*.pack" | wc -l) 0 +WVPASS bup random 50k | WVPASS bup split -n foo +WVPASS test $(WVPASS find "$BUP_DIR"/objects/pack/*.pack | wc -l) -gt 2 + +WVPASS rm -r "$tmpdir" -- 2.39.2