]> arthur.barton.de Git - bup.git/commitdiff
Honor git config pack.packSizeLimit when set
authorRob Browning <rlb@defaultvalue.org>
Mon, 15 May 2017 06:19:37 +0000 (01:19 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sat, 20 May 2017 19:21:48 +0000 (14:21 -0500)
Thanks to Ross Patterson for suggesting the improvement and proposing
an earlier implementation.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
Makefile
lib/bup/git.py
t/test-packsizelimit [new file with mode: 0755]

index 6a46b8de7a2829214b016a95850e68461d07f5a5..62536f0eb23be70ba8fdb7a8d5358e03ad1df928 100644 (file)
--- 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 \
index a0b42ffaf3997eced2b5745b776ef3da58354b77..950a2d4ebb41e0399851d8b71ee49d6e9c301d5b 100644 (file)
@@ -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 (executable)
index 0000000..6bd6a00
--- /dev/null
@@ -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"