@matheusbsbs / matheus-bagliano / commits / db12505c2c
Fork 0

t/lib-pack: support SHA-256

Update the support routines for generating packs to support both SHA-1 and SHA-256. Compute the trailing pack checksum and its length correctly depending on the algorithm, and look up the object names based on the algorithm as well. Ensure we initialize the algorithm facts so that our callers need not do so. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Feb 7, 2020 at 00:52 UTC db12505c2c59f1e126e4bd79f80196510a7d30df
1 file changed +30 -5
t/lib-pack.sh
+30 -5
@@ -35,9 +35,11 @@ pack_header () {
35 # have hardcoded some well-known objects. See the case statements below for the
36 # complete list.
37 pack_obj () {
38 + test_oid_init
39 +
40 case "$1" in
41 # empty blob
40 - e69de29bb2d1d6434b8b29ae775ad8c2e48c5391)
42 + $EMPTY_BLOB)
43 case "$2" in
44 '')
45 printf '\060\170\234\003\0\0\0\0\1'
@@ -47,7 +49,7 @@ pack_obj () {
49 ;;
50
51 # blob containing "\7\76"
50 - e68fe8129b546b101aee9510c5328e7f21ca1d18)
52 + $(test_oid packlib_7_76))
53 case "$2" in
54 '')
55 printf '\062\170\234\143\267\3\0\0\116\0\106'
@@ -59,11 +61,18 @@ pack_obj () {
61 printf '\234\143\142\142\142\267\003\0\0\151\0\114'
62 return
63 ;;
64 + 37c8e2c15bb22b912e59b43fd51a4f7e9465ed0b5084c5a1411d991cbe630683)
65 + printf '\165\67\310\342\301\133\262\53\221\56\131' &&
66 + printf '\264\77\325\32\117\176\224\145\355\13\120' &&
67 + printf '\204\305\241\101\35\231\34\276\143\6\203\170' &&
68 + printf '\234\143\142\142\142\267\003\0\0\151\0\114'
69 + return
70 + ;;
71 esac
72 ;;
73
74 # blob containing "\7\0"
66 - 01d7713666f4de822776c7622c10f1b07de280dc)
75 + $(test_oid packlib_7_0))
76 case "$2" in
77 '')
78 printf '\062\170\234\143\147\0\0\0\20\0\10'
@@ -75,6 +84,13 @@ pack_obj () {
84 printf '\143\142\142\142\147\0\0\0\53\0\16'
85 return
86 ;;
87 + 5d8e6fc40f2dab00e6983a48523fe57e621f46434cb58dbd4422fba03380d886)
88 + printf '\165\135\216\157\304\17\55\253\0\346\230\72' &&
89 + printf '\110\122\77\345\176\142\37\106\103\114\265' &&
90 + printf '\215\275\104\42\373\240\63\200\330\206\170\234' &&
91 + printf '\143\142\142\142\147\0\0\0\53\0\16'
92 + return
93 + ;;
94 esac
95 ;;
96 esac
@@ -86,7 +102,7 @@ pack_obj () {
102 then
103 echo "$1" | git pack-objects --stdout >pack_obj.tmp &&
104 size=$(wc -c <pack_obj.tmp) &&
89 - dd if=pack_obj.tmp bs=1 count=$((size - 20 - 12)) skip=12 &&
105 + dd if=pack_obj.tmp bs=1 count=$((size - $(test_oid rawsz) - 12)) skip=12 &&
106 rm -f pack_obj.tmp
107 return
108 fi
@@ -97,7 +113,8 @@ pack_obj () {
113
114 # Compute and append pack trailer to "$1"
115 pack_trailer () {
100 - test-tool sha1 -b <"$1" >trailer.tmp &&
116 + test_oid_init &&
117 + test-tool $(test_oid algo) -b <"$1" >trailer.tmp &&
118 cat trailer.tmp >>"$1" &&
119 rm -f trailer.tmp
120 }
@@ -108,3 +125,11 @@ pack_trailer () {
125 clear_packs () {
126 rm -f .git/objects/pack/*
127 }
128 +
129 +test_oid_cache <<-EOF
130 +packlib_7_0 sha1:01d7713666f4de822776c7622c10f1b07de280dc
131 +packlib_7_0 sha256:37c8e2c15bb22b912e59b43fd51a4f7e9465ed0b5084c5a1411d991cbe630683
132 +
133 +packlib_7_76 sha1:e68fe8129b546b101aee9510c5328e7f21ca1d18
134 +packlib_7_76 sha256:5d8e6fc40f2dab00e6983a48523fe57e621f46434cb58dbd4422fba03380d886
135 +EOF