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 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,12 +658,12 @@ test_expect_success 'setup bogus data' '
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
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ test_description='git fsck random collection of tests
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,7 +974,7 @@ test_expect_success 'fsck error and recovery on invalid object type' '
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 &&
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
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,8 +68,8 @@ test_expect_success 'ambiguous loose bad object parsed as OBJ_BAD' '
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
You can’t perform that action at this time.
0 commit comments