Git fork

test: refactor to use "get_abbrev_oid" to get abbrev oid

Add new function "get_abbrev_oid" to get abbrev object ID. This
function has a default value which helps to prepare a nonempty replace
pattern for sed command. An empty replace pattern may cause sed fail
to allocate memory.

Refactor function "make_user_friendly_and_stable_output" to use
"get_abbrev_oid" to get abbrev object ID.

Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Jiang Xin and committed by
Junio C Hamano
12d6991c 3c06a583

+72 -52
+15 -5
t/t5411/common-functions.sh
··· 18 18 done 19 19 } 20 20 21 + get_abbrev_oid () { 22 + oid=$1 && 23 + suffix=${oid#???????} && 24 + oid=${oid%$suffix} && 25 + if test -n "$oid" 26 + then 27 + echo "$oid" 28 + else 29 + echo "undefined-oid" 30 + fi 31 + } 32 + 21 33 # Format the output of git-push, git-show-ref and other commands to make a 22 34 # user-friendly and stable text. We can easily prepare the expect text 23 35 # without having to worry about changes of the commit ID (full or abbrev.) ··· 28 40 make_user_friendly_and_stable_output () { 29 41 sed \ 30 42 -e "s/'/\"/g" \ 31 - -e "s/$A/<COMMIT-A>/g" \ 32 - -e "s/$B/<COMMIT-B>/g" \ 33 - -e "s/$TAG/<TAG-v123>/g" \ 43 + -e "s/$(get_abbrev_oid $A)[0-9a-f]*/<COMMIT-A>/g" \ 44 + -e "s/$(get_abbrev_oid $B)[0-9a-f]*/<COMMIT-B>/g" \ 45 + -e "s/$(get_abbrev_oid $TAG)[0-9a-f]*/<TAG-v123>/g" \ 34 46 -e "s/$ZERO_OID/<ZERO-OID>/g" \ 35 - -e "s/$(echo $A | cut -c1-7)[0-9a-f]*/<OID-A>/g" \ 36 - -e "s/$(echo $B | cut -c1-7)[0-9a-f]*/<OID-B>/g" \ 37 47 -e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#" \ 38 48 -e "/^error: / d" 39 49 }
+3 -3
t/t5411/test-0000-standard-git-push.sh
··· 15 15 > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/main Z 16 16 > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next Z 17 17 > To <URL/of/upstream.git> 18 - > <OID-A>..<OID-B> <COMMIT-B> -> main 18 + > <COMMIT-A>..<COMMIT-B> <COMMIT-B> -> main 19 19 > * [new branch] HEAD -> next 20 20 EOF 21 21 test_cmp expect actual && ··· 69 69 > remote: # post-receive hook Z 70 70 > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/next Z 71 71 > To <URL/of/upstream.git> 72 - > <OID-A>..<OID-B> <COMMIT-B> -> next 72 + > <COMMIT-A>..<COMMIT-B> <COMMIT-B> -> next 73 73 > ! [rejected] main -> main (non-fast-forward) 74 74 EOF 75 75 test_cmp expect actual && ··· 106 106 > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/review/main/topic Z 107 107 > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/a/b/c Z 108 108 > To <URL/of/upstream.git> 109 - > + <OID-B>...<OID-A> main -> main (forced update) 109 + > + <COMMIT-B>...<COMMIT-A> main -> main (forced update) 110 110 > - [deleted] next 111 111 > * [new tag] v123 -> v123 112 112 > * [new reference] main -> refs/review/main/topic
+3 -3
t/t5411/test-0001-standard-git-push--porcelain.sh
··· 15 15 > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/main Z 16 16 > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next Z 17 17 > To <URL/of/upstream.git> 18 - > <COMMIT-B>:refs/heads/main <OID-A>..<OID-B> 18 + > <COMMIT-B>:refs/heads/main <COMMIT-A>..<COMMIT-B> 19 19 > * HEAD:refs/heads/next [new branch] 20 20 > Done 21 21 EOF ··· 71 71 > remote: # post-receive hook Z 72 72 > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/next Z 73 73 > To <URL/of/upstream.git> 74 - > <COMMIT-B>:refs/heads/next <OID-A>..<OID-B> 74 + > <COMMIT-B>:refs/heads/next <COMMIT-A>..<COMMIT-B> 75 75 > ! refs/heads/main:refs/heads/main [rejected] (non-fast-forward) 76 76 > Done 77 77 EOF ··· 109 109 > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/review/main/topic Z 110 110 > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/a/b/c Z 111 111 > To <URL/of/upstream.git> 112 - > + refs/heads/main:refs/heads/main <OID-B>...<OID-A> (forced update) 112 + > + refs/heads/main:refs/heads/main <COMMIT-B>...<COMMIT-A> (forced update) 113 113 > - :refs/heads/next [deleted] 114 114 > * refs/tags/v123:refs/tags/v123 [new tag] 115 115 > * refs/heads/main:refs/review/main/topic [new reference]
+1 -1
t/t5411/test-0022-report-unexpect-ref.sh
··· 26 26 > remote: # post-receive hook Z 27 27 > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/main Z 28 28 > To <URL/of/upstream.git> 29 - > <OID-A>..<OID-B> <COMMIT-B> -> main 29 + > <COMMIT-A>..<COMMIT-B> <COMMIT-B> -> main 30 30 > ! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status) 31 31 EOF 32 32 test_cmp expect actual &&
+1 -1
t/t5411/test-0023-report-unexpect-ref--porcelain.sh
··· 26 26 > remote: # post-receive hook Z 27 27 > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/main Z 28 28 > To <URL/of/upstream.git> 29 - > <COMMIT-B>:refs/heads/main <OID-A>..<OID-B> 29 + > <COMMIT-B>:refs/heads/main <COMMIT-A>..<COMMIT-B> 30 30 > ! HEAD:refs/for/main/topic [remote rejected] (proc-receive failed to report status) 31 31 > Done 32 32 EOF
+4 -4
t/t5411/test-0032-report-with-options.sh
··· 123 123 > remote: # post-receive hook Z 124 124 > remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/123/head Z 125 125 > To <URL/of/upstream.git> 126 - > <OID-B>..<OID-A> HEAD -> refs/pull/123/head 126 + > <COMMIT-B>..<COMMIT-A> HEAD -> refs/pull/123/head 127 127 EOF 128 128 test_cmp expect actual 129 129 ' ··· 155 155 > remote: # post-receive hook Z 156 156 > remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/main/topic Z 157 157 > To <URL/of/upstream.git> 158 - > <OID-B>..<OID-A> HEAD -> refs/for/main/topic 158 + > <COMMIT-B>..<COMMIT-A> HEAD -> refs/for/main/topic 159 159 EOF 160 160 test_cmp expect actual 161 161 ' ··· 189 189 > remote: # post-receive hook Z 190 190 > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/main/topic Z 191 191 > To <URL/of/upstream.git> 192 - > <OID-A>..<OID-B> HEAD -> refs/for/main/topic 192 + > <COMMIT-A>..<COMMIT-B> HEAD -> refs/for/main/topic 193 193 EOF 194 194 test_cmp expect actual 195 195 ' ··· 243 243 > To <URL/of/upstream.git> 244 244 > * [new reference] HEAD -> refs/pull/123/head 245 245 > * [new reference] HEAD -> refs/for/a/b/c/topic 246 - > + <OID-B>...<OID-A> HEAD -> refs/pull/124/head (forced update) 246 + > + <COMMIT-B>...<COMMIT-A> HEAD -> refs/pull/124/head (forced update) 247 247 EOF 248 248 test_cmp expect actual && 249 249
+4 -4
t/t5411/test-0033-report-with-options--porcelain.sh
··· 127 127 > remote: # post-receive hook Z 128 128 > remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/123/head Z 129 129 > To <URL/of/upstream.git> 130 - > HEAD:refs/pull/123/head <OID-B>..<OID-A> 130 + > HEAD:refs/pull/123/head <COMMIT-B>..<COMMIT-A> 131 131 > Done 132 132 EOF 133 133 test_cmp expect actual ··· 160 160 > remote: # post-receive hook Z 161 161 > remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/main/topic Z 162 162 > To <URL/of/upstream.git> 163 - > HEAD:refs/for/main/topic <OID-B>..<OID-A> 163 + > HEAD:refs/for/main/topic <COMMIT-B>..<COMMIT-A> 164 164 > Done 165 165 EOF 166 166 test_cmp expect actual ··· 195 195 > remote: # post-receive hook Z 196 196 > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/main/topic Z 197 197 > To <URL/of/upstream.git> 198 - > HEAD:refs/for/main/topic <OID-A>..<OID-B> 198 + > HEAD:refs/for/main/topic <COMMIT-A>..<COMMIT-B> 199 199 > Done 200 200 EOF 201 201 test_cmp expect actual ··· 251 251 > To <URL/of/upstream.git> 252 252 > * HEAD:refs/pull/123/head [new reference] 253 253 > * HEAD:refs/for/a/b/c/topic [new reference] 254 - > + HEAD:refs/pull/124/head <OID-B>...<OID-A> (forced update) 254 + > + HEAD:refs/pull/124/head <COMMIT-B>...<COMMIT-A> (forced update) 255 255 > Done 256 256 EOF 257 257 test_cmp expect actual &&
+5 -5
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh
··· 60 60 > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1 Z 61 61 > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1 Z 62 62 > To <URL/of/upstream.git> 63 - > <OID-A>..<OID-B> HEAD -> refs/for/main/topic 63 + > <COMMIT-A>..<COMMIT-B> HEAD -> refs/for/main/topic 64 64 > * [new reference] HEAD -> refs/changes/24/124/1 65 - > <OID-A>..<OID-B> HEAD -> refs/changes/25/125/1 65 + > <COMMIT-A>..<COMMIT-B> HEAD -> refs/changes/25/125/1 66 66 EOF 67 67 test_cmp expect actual && 68 68 ··· 136 136 > remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1 Z 137 137 > To <URL/of/upstream.git> 138 138 > * [new reference] HEAD -> refs/changes/24/124/1 139 - > <OID-A>..<OID-B> HEAD -> refs/for/main/topic 140 - > + <OID-B>...<OID-A> HEAD -> refs/changes/25/125/1 (forced update) 139 + > <COMMIT-A>..<COMMIT-B> HEAD -> refs/for/main/topic 140 + > + <COMMIT-B>...<COMMIT-A> HEAD -> refs/changes/25/125/1 (forced update) 141 141 EOF 142 142 test_cmp expect actual && 143 143 ··· 198 198 > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2 Z 199 199 > To <URL/of/upstream.git> 200 200 > * [new reference] HEAD -> refs/changes/23/123/1 201 - > <OID-A>..<OID-B> HEAD -> refs/changes/24/124/2 201 + > <COMMIT-A>..<COMMIT-B> HEAD -> refs/changes/24/124/2 202 202 EOF 203 203 test_cmp expect actual && 204 204
+5 -5
t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh
··· 45 45 > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1 Z 46 46 > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1 Z 47 47 > To <URL/of/upstream.git> 48 - > HEAD:refs/for/main/topic <OID-A>..<OID-B> 48 + > HEAD:refs/for/main/topic <COMMIT-A>..<COMMIT-B> 49 49 > * HEAD:refs/changes/24/124/1 [new reference] 50 - > HEAD:refs/changes/25/125/1 <OID-A>..<OID-B> 50 + > HEAD:refs/changes/25/125/1 <COMMIT-A>..<COMMIT-B> 51 51 > Done 52 52 EOF 53 53 test_cmp expect actual && ··· 107 107 > remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1 Z 108 108 > To <URL/of/upstream.git> 109 109 > * HEAD:refs/changes/24/124/1 [new reference] 110 - > HEAD:refs/for/main/topic <OID-A>..<OID-B> 111 - > + HEAD:refs/changes/25/125/1 <OID-B>...<OID-A> (forced update) 110 + > HEAD:refs/for/main/topic <COMMIT-A>..<COMMIT-B> 111 + > + HEAD:refs/changes/25/125/1 <COMMIT-B>...<COMMIT-A> (forced update) 112 112 > Done 113 113 EOF 114 114 test_cmp expect actual && ··· 155 155 > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2 Z 156 156 > To <URL/of/upstream.git> 157 157 > * HEAD:refs/changes/23/123/1 [new reference] 158 - > HEAD:refs/changes/24/124/2 <OID-A>..<OID-B> 158 + > HEAD:refs/changes/24/124/2 <COMMIT-A>..<COMMIT-B> 159 159 > Done 160 160 EOF 161 161 test_cmp expect actual &&
+2 -2
t/t5411/test-0038-report-mixed-refs.sh
··· 55 55 > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo Z 56 56 > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/main/topic Z 57 57 > To <URL/of/upstream.git> 58 - > <OID-A>..<OID-B> <COMMIT-B> -> main 58 + > <COMMIT-A>..<COMMIT-B> <COMMIT-B> -> main 59 59 > * [new branch] HEAD -> bar 60 60 > * [new branch] HEAD -> baz 61 61 > * [new reference] HEAD -> refs/for/next/topic2 62 62 > * [new branch] HEAD -> foo 63 - > <OID-A>..<OID-B> HEAD -> refs/for/main/topic 63 + > <COMMIT-A>..<COMMIT-B> HEAD -> refs/for/main/topic 64 64 > ! [remote rejected] HEAD -> refs/for/next/topic1 (fail to call Web API) 65 65 > ! [remote rejected] HEAD -> refs/for/next/topic3 (proc-receive failed to report status) 66 66 EOF
+2 -2
t/t5411/test-0039-report-mixed-refs--porcelain.sh
··· 55 55 > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo Z 56 56 > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/main/topic Z 57 57 > To <URL/of/upstream.git> 58 - > <COMMIT-B>:refs/heads/main <OID-A>..<OID-B> 58 + > <COMMIT-B>:refs/heads/main <COMMIT-A>..<COMMIT-B> 59 59 > * HEAD:refs/heads/bar [new branch] 60 60 > * HEAD:refs/heads/baz [new branch] 61 61 > * HEAD:refs/for/next/topic2 [new reference] 62 62 > * HEAD:refs/heads/foo [new branch] 63 - > HEAD:refs/for/main/topic <OID-A>..<OID-B> 63 + > HEAD:refs/for/main/topic <COMMIT-A>..<COMMIT-B> 64 64 > ! HEAD:refs/for/next/topic1 [remote rejected] (fail to call Web API) 65 65 > ! HEAD:refs/for/next/topic3 [remote rejected] (proc-receive failed to report status) 66 66 > Done
+4 -4
t/t5411/test-0040-process-all-refs.sh
··· 85 85 > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/pull/123/head Z 86 86 > remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head Z 87 87 > To <URL/of/upstream.git> 88 - > <OID-A>..<OID-B> <COMMIT-B> -> bar 88 + > <COMMIT-A>..<COMMIT-B> <COMMIT-B> -> bar 89 89 > - [deleted] foo 90 - > + <OID-B>...<OID-A> HEAD -> main (forced update) 91 - > <OID-A>..<OID-B> HEAD -> refs/pull/123/head 92 - > + <OID-B>...<OID-A> HEAD -> refs/pull/124/head (forced update) 90 + > + <COMMIT-B>...<COMMIT-A> HEAD -> main (forced update) 91 + > <COMMIT-A>..<COMMIT-B> HEAD -> refs/pull/123/head 92 + > + <COMMIT-B>...<COMMIT-A> HEAD -> refs/pull/124/head (forced update) 93 93 EOF 94 94 test_cmp expect actual && 95 95
+4 -4
t/t5411/test-0041-process-all-refs--porcelain.sh
··· 85 85 > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/pull/123/head Z 86 86 > remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head Z 87 87 > To <URL/of/upstream.git> 88 - > <COMMIT-B>:refs/heads/bar <OID-A>..<OID-B> 88 + > <COMMIT-B>:refs/heads/bar <COMMIT-A>..<COMMIT-B> 89 89 > - :refs/heads/foo [deleted] 90 - > + HEAD:refs/heads/main <OID-B>...<OID-A> (forced update) 91 - > HEAD:refs/pull/123/head <OID-A>..<OID-B> 92 - > + HEAD:refs/pull/124/head <OID-B>...<OID-A> (forced update) 90 + > + HEAD:refs/heads/main <COMMIT-B>...<COMMIT-A> (forced update) 91 + > HEAD:refs/pull/123/head <COMMIT-A>..<COMMIT-B> 92 + > + HEAD:refs/pull/124/head <COMMIT-B>...<COMMIT-A> (forced update) 93 93 > Done 94 94 EOF 95 95 test_cmp expect actual &&
+2 -2
t/t5411/test-0050-proc-receive-refs-with-modifiers.sh
··· 46 46 > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/pull/123/head Z 47 47 > remote: post-receive< <ZERO-OID> <TAG-v123> refs/pull/124/head Z 48 48 > To <URL/of/upstream.git> 49 - > <OID-A>..<OID-B> <COMMIT-B> -> refs/pull/123/head 49 + > <COMMIT-A>..<COMMIT-B> <COMMIT-B> -> refs/pull/123/head 50 50 > * [new reference] v123 -> refs/pull/124/head 51 51 EOF 52 52 test_cmp expect actual && ··· 116 116 > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/124/head Z 117 117 > To <URL/of/upstream.git> 118 118 > - [deleted] refs/pull/123/head 119 - > <OID-A>..<OID-B> <COMMIT-B> -> topic 119 + > <COMMIT-A>..<COMMIT-B> <COMMIT-B> -> topic 120 120 > - [deleted] v123 121 121 > * [new reference] <COMMIT-A> -> refs/pull/124/head 122 122 EOF
+17 -7
t/t5548-push-porcelain.sh
··· 26 26 done 27 27 } 28 28 29 + get_abbrev_oid () { 30 + oid=$1 && 31 + suffix=${oid#???????} && 32 + oid=${oid%$suffix} && 33 + if test -n "$oid" 34 + then 35 + echo "$oid" 36 + else 37 + echo "undefined-oid" 38 + fi 39 + } 40 + 29 41 # Format the output of git-push, git-show-ref and other commands to make a 30 42 # user-friendly and stable text. We can easily prepare the expect text 31 43 # without having to worry about future changes of the commit ID and spaces 32 44 # of the output. 33 45 make_user_friendly_and_stable_output () { 34 46 sed \ 35 - -e "s/$A/<COMMIT-A>/g" \ 36 - -e "s/$B/<COMMIT-B>/g" \ 47 + -e "s/$(get_abbrev_oid $A)[0-9a-f]*/<COMMIT-A>/g" \ 48 + -e "s/$(get_abbrev_oid $B)[0-9a-f]*/<COMMIT-B>/g" \ 37 49 -e "s/$ZERO_OID/<ZERO-OID>/g" \ 38 - -e "s/$(echo $A | cut -c1-7)[0-9a-f]*/<OID-A>/g" \ 39 - -e "s/$(echo $B | cut -c1-7)[0-9a-f]*/<OID-B>/g" \ 40 50 -e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#" 41 51 } 42 52 ··· 102 112 format_and_save_expect <<-EOF && 103 113 > To <URL/of/upstream.git> 104 114 > = refs/heads/baz:refs/heads/baz [up to date] 105 - > <COMMIT-B>:refs/heads/bar <OID-A>..<OID-B> 115 + > <COMMIT-B>:refs/heads/bar <COMMIT-A>..<COMMIT-B> 106 116 > - :refs/heads/foo [deleted] 107 - > + refs/heads/main:refs/heads/main <OID-B>...<OID-A> (forced update) 117 + > + refs/heads/main:refs/heads/main <COMMIT-B>...<COMMIT-A> (forced update) 108 118 > * refs/heads/next:refs/heads/next [new branch] 109 119 > Done 110 120 EOF ··· 220 230 To <URL/of/upstream.git> 221 231 > = refs/heads/next:refs/heads/next [up to date] 222 232 > - :refs/heads/baz [deleted] 223 - > refs/heads/main:refs/heads/main <OID-A>..<OID-B> 233 + > refs/heads/main:refs/heads/main <COMMIT-A>..<COMMIT-B> 224 234 > ! refs/heads/bar:refs/heads/bar [rejected] (non-fast-forward) 225 235 Done 226 236 EOF