Git fork

t: add lib-loose.sh

This commit adds a shell library for writing raw loose objects into the
object database. Normally this is done with hash-object, but the
specific intent here is to allow broken objects that hash-object may not
support.

We'll convert several cases that use "hash-object --literally" to write
objects with invalid types. That works currently, but dropping this
dependency will allow us to remove that feature and simplify the
object-writing code.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Jeff King and committed by
Junio C Hamano
b5643b60 f2ed511a

+38 -5
+30
t/lib-loose.sh
··· 1 + # Support routines for hand-crafting loose objects. 2 + 3 + # Write a loose object into the odb at $1, with object type $2 and contents 4 + # from stdin. Writes the oid to stdout. Example: 5 + # 6 + # oid=$(echo foo | loose_obj .git/objects blob) 7 + # 8 + loose_obj () { 9 + cat >tmp_loose.content && 10 + size=$(wc -c <tmp_loose.content) && 11 + { 12 + # Do not quote $size here; we want the shell 13 + # to strip whitespace that "wc" adds on some platforms. 14 + printf "%s %s\0" "$2" $size && 15 + cat tmp_loose.content 16 + } >tmp_loose.raw && 17 + 18 + oid=$(test-tool $test_hash_algo <tmp_loose.raw) && 19 + suffix=${oid#??} && 20 + prefix=${oid%$suffix} && 21 + dir=$1/$prefix && 22 + file=$dir/$suffix && 23 + 24 + test-tool zlib deflate <tmp_loose.raw >tmp_loose.zlib && 25 + mkdir -p "$dir" && 26 + mv tmp_loose.zlib "$file" && 27 + 28 + rm tmp_loose.raw tmp_loose.content && 29 + echo "$oid" 30 + }
+3 -2
t/t1006-cat-file.sh
··· 3 3 test_description='git cat-file' 4 4 5 5 . ./test-lib.sh 6 + . "$TEST_DIRECTORY/lib-loose.sh" 6 7 7 8 test_cmdmode_usage () { 8 9 test_expect_code 129 "$@" 2>err && ··· 657 658 bogus_short_type="bogus" && 658 659 bogus_short_content="bogus" && 659 660 bogus_short_size=$(strlen "$bogus_short_content") && 660 - bogus_short_oid=$(echo_without_newline "$bogus_short_content" | git hash-object -t $bogus_short_type --literally -w --stdin) && 661 + bogus_short_oid=$(echo_without_newline "$bogus_short_content" | loose_obj .git/objects $bogus_short_type) && 661 662 662 663 bogus_long_type="abcdefghijklmnopqrstuvwxyz1234679" && 663 664 bogus_long_content="bogus" && 664 665 bogus_long_size=$(strlen "$bogus_long_content") && 665 - bogus_long_oid=$(echo_without_newline "$bogus_long_content" | git hash-object -t $bogus_long_type --literally -w --stdin) 666 + bogus_long_oid=$(echo_without_newline "$bogus_long_content" | loose_obj .git/objects $bogus_long_type) 666 667 ' 667 668 668 669 for arg1 in -s -t -p
+2 -1
t/t1450-fsck.sh
··· 7 7 ' 8 8 9 9 . ./test-lib.sh 10 + . "$TEST_DIRECTORY/lib-loose.sh" 10 11 11 12 test_expect_success setup ' 12 13 git config gc.auto 0 && ··· 973 974 ( 974 975 cd garbage-type && 975 976 976 - garbage_blob=$(git hash-object --stdin -w -t garbage --literally </dev/null) && 977 + garbage_blob=$(loose_obj objects garbage </dev/null) && 977 978 978 979 test_must_fail git fsck 2>err && 979 980 grep -e "^error" -e "^fatal" err >errors &&
+3 -2
t/t1512-rev-parse-disambiguation.sh
··· 24 24 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 25 25 26 26 . ./test-lib.sh 27 + . "$TEST_DIRECTORY/lib-loose.sh" 27 28 28 29 test_cmp_failed_rev_parse () { 29 30 dir=$1 ··· 67 68 cd blob.bad && 68 69 69 70 # Both have the prefix "bad0" 70 - echo xyzfaowcoh | git hash-object -t bad -w --stdin --literally && 71 - echo xyzhjpyvwl | git hash-object -t bad -w --stdin --literally 71 + echo xyzfaowcoh | loose_obj objects bad && 72 + echo xyzhjpyvwl | loose_obj objects bad 72 73 ) && 73 74 74 75 test_cmp_failed_rev_parse blob.bad bad0 <<-\EOF