File tree Expand file tree Collapse file tree 4 files changed +38
-5
lines changed Expand file tree Collapse file tree 4 files changed +38
-5
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 33test_description=' git cat-file'
44
55. ./test-lib.sh
6+ . " $TEST_DIRECTORY /lib-loose.sh"
67
78test_cmdmode_usage () {
89 test_expect_code 129 " $@ " 2> err &&
@@ -657,12 +658,12 @@ test_expect_success 'setup bogus data' '
657658 bogus_short_type="bogus" &&
658659 bogus_short_content="bogus" &&
659660 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) &&
661662
662663 bogus_long_type="abcdefghijklmnopqrstuvwxyz1234679" &&
663664 bogus_long_content="bogus" &&
664665 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)
666667'
667668
668669for arg1 in -s -t -p
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ test_description='git fsck random collection of tests
77'
88
99. ./test-lib.sh
10+ . " $TEST_DIRECTORY /lib-loose.sh"
1011
1112test_expect_success setup '
1213 git config gc.auto 0 &&
@@ -973,7 +974,7 @@ test_expect_success 'fsck error and recovery on invalid object type' '
973974 (
974975 cd garbage-type &&
975976
976- garbage_blob=$(git hash-object --stdin -w -t garbage --literally </dev/null) &&
977+ garbage_blob=$(loose_obj objects garbage </dev/null) &&
977978
978979 test_must_fail git fsck 2>err &&
979980 grep -e "^error" -e "^fatal" err >errors &&
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
2424export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
2525
2626. ./test-lib.sh
27+ . " $TEST_DIRECTORY /lib-loose.sh"
2728
2829test_cmp_failed_rev_parse () {
2930 dir=$1
@@ -67,8 +68,8 @@ test_expect_success 'ambiguous loose bad object parsed as OBJ_BAD' '
6768 cd blob.bad &&
6869
6970 # 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
7273 ) &&
7374
7475 test_cmp_failed_rev_parse blob.bad bad0 <<-\EOF
You can’t perform that action at this time.
0 commit comments