]> arthur.barton.de Git - bup.git/commitdiff
save-cmd.py: don't write an irrelevant and incomplete .bupm fragment.
authorRob Browning <rlb@defaultvalue.org>
Sun, 25 Aug 2013 22:33:42 +0000 (17:33 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sun, 25 Aug 2013 22:33:45 +0000 (17:33 -0500)
When finishing up (leaving) a directory and preparing to store its
related tree in the repository, don't write the pending .bupm (which
is still incomplete) to the pack if we know the directory already
exists in the repository (i.e. when we're not going to write it
either).

This problem was discovered when Zoran noticed that two consecutive
saves without an intervening index could produce a repository with an
unreferenced blob (according to git fsck).

Reported-by: Zoran Zaric <zz@zoranzaric.de>
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
cmd/save-cmd.py
t/test-save-creates-no-unrefs.sh [new file with mode: 0755]

index 66d56e2449a45a4db61a378d77fce694caa0ef8c..5031edb690801e229dbfe9808a36c442f4a0c73e 100755 (executable)
@@ -124,7 +124,7 @@ def _pop(force_tree, dir_metadata=None):
     part = parts.pop()
     shalist = shalists.pop()
     metalist = metalists.pop()
-    if metalist:
+    if metalist and not force_tree:
         if dir_metadata: # Override the original metadata pushed for this dir.
             metalist = [('', dir_metadata)] + metalist[1:]
         sorted_metalist = sorted(metalist, key = lambda x : x[0])
diff --git a/t/test-save-creates-no-unrefs.sh b/t/test-save-creates-no-unrefs.sh
new file mode 100755 (executable)
index 0000000..229da4c
--- /dev/null
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+. ./wvtest-bup.sh
+
+set -eo pipefail
+
+WVSTART 'all'
+
+top="$(pwd)"
+tmpdir="$(wvmktempdir)"
+export BUP_DIR="$tmpdir/bup"
+export GIT_DIR="$BUP_DIR"
+
+bup() { "$top/bup" "$@"; }
+
+mkdir -p "$tmpdir/src"
+touch "$tmpdir/src/foo"
+bup init
+bup index "$tmpdir/src"
+bup save -n src "$tmpdir/src"
+WVPASSEQ "$(git fsck --unreachable)" ""
+bup save -n src "$tmpdir/src"
+WVPASSEQ "$(git fsck --unreachable)" ""
+
+rm -rf "$tmpdir"