Fourth batch
[gitweb.git] / t / lib-pack.sh
index 7e8685b44c90047bff973bec61f046f6900637e5..c4d907a450a7863ff0fe32fe9aed7ef5c100dd3e 100644 (file)
@@ -1,5 +1,3 @@
-#!/bin/sh
-#
 # Support routines for hand-crafting weird or malicious packs.
 #
 # You can make a complete pack like:
 # Print the big-endian 4-byte octal representation of $1
 uint32_octal () {
        n=$1
-       printf '\%o' $(($n / 16777216)); n=$((n % 16777216))
-       printf '\%o' $(($n /    65536)); n=$((n %    65536))
-       printf '\%o' $(($n /      256)); n=$((n %      256))
-       printf '\%o' $(($n           ));
+       printf '\\%o' $(($n / 16777216)); n=$((n % 16777216))
+       printf '\\%o' $(($n /    65536)); n=$((n %    65536))
+       printf '\\%o' $(($n /      256)); n=$((n %      256))
+       printf '\\%o' $(($n           ));
 }
 
 # Print the big-endian 4-byte binary representation of $1
@@ -81,13 +79,25 @@ pack_obj () {
                ;;
        esac
 
+       # If it's not a delta, we can convince pack-objects to generate a pack
+       # with just our entry, and then strip off the header (12 bytes) and
+       # trailer (20 bytes).
+       if test -z "$2"
+       then
+               echo "$1" | git pack-objects --stdout >pack_obj.tmp &&
+               size=$(wc -c <pack_obj.tmp) &&
+               dd if=pack_obj.tmp bs=1 count=$((size - 20 - 12)) skip=12 &&
+               rm -f pack_obj.tmp
+               return
+       fi
+
        echo >&2 "BUG: don't know how to print $1${2:+ (from $2)}"
        return 1
 }
 
 # Compute and append pack trailer to "$1"
 pack_trailer () {
-       test-sha1 -b <"$1" >trailer.tmp &&
+       test-tool sha1 -b <"$1" >trailer.tmp &&
        cat trailer.tmp >>"$1" &&
        rm -f trailer.tmp
 }