]> arthur.barton.de Git - bup.git/commitdiff
test-cat-file.sh: handle hashsplit bupm files
authorRob Browning <rlb@defaultvalue.org>
Fri, 17 Oct 2014 15:44:24 +0000 (10:44 -0500)
committerRob Browning <rlb@defaultvalue.org>
Fri, 17 Oct 2014 15:48:07 +0000 (10:48 -0500)
A bit back we started allowing .bupm files to be hashsplit:

  ee777400cf624b4f7a24b15614c2b6c745560dcb

So add t/git-cat-tree and use it in test-cat-file.sh to prevent the
test from crashing whenever the bupm is a tree.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
t/git-cat-tree [new file with mode: 0755]
t/test-cat-file.sh

diff --git a/t/git-cat-tree b/t/git-cat-tree
new file mode 100755 (executable)
index 0000000..bbbfa6b
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/env bash
+
+# Recursively dump all blobs in the subtree identified by ID.
+
+set -o pipefail
+
+usage() {
+cat <<EOF
+Usage: cat-git-tree ID
+EOF
+}
+
+cat-item()
+{
+    local hash="$1"
+    local type="$2"
+    case "$type" in
+        blob)
+            git cat-file blob "$hash" || exit $?
+            ;;
+        tree)
+            local tree=$(git ls-tree "$hash") || exit $?
+            while read -r line; do
+                local sub_type=$(echo "$line" | cut -d' ' -f 2) || exit $?
+                local sub_hash=$(echo "$line" | cut -d' ' -f 3) || exit $?
+                sub_hash=$(echo "$sub_hash" | cut -d'  ' -f 1) || exit $?
+                cat-item "$sub_hash" "$sub_type"
+            done <<< "$tree"
+            ;;
+        *)
+            echo "Unexpected item: $type $hash" 1>&2
+            exit 1
+            ;;
+    esac
+}
+
+if test $# -ne 1
+then
+    usage 1>&2
+    exit 1
+fi
+
+top="$1"
+type=$(git cat-file -t "$top") || exit $?
+cat-item "$top" "$type"
index c8d148a728e98642703e7a7ce2c485a7ed5d737e..a60c7c7a999452a200c076d82f1fb55835bf4538 100755 (executable)
@@ -36,7 +36,7 @@ src_hash=$(WVPASS bup ls -s "src/latest/$(pwd)" | cut -d' ' -f 1) || exit $?
 bupm_hash=$(WVPASS git ls-tree "$src_hash" | grep -F .bupm | cut -d' ' -f 3) \
     || exit $?
 bupm_hash=$(WVPASS echo "$bupm_hash" | cut -d' ' -f 1) || exit $?
-WVPASS git cat-file blob "$bupm_hash" > git-cat-bupm
+WVPASS "$top/t/git-cat-tree" "$bupm_hash" > git-cat-bupm
 if ! cmp git-cat-bupm bup-cat-bupm; then
     cmp -l git-cat-bupm bup-cat-bupm
     diff -uN <(bup meta -tvvf git-cat-bupm) <(bup meta -tvvf bup-cat-bupm)