Raw
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 }