summaryrefslogtreecommitdiff
path: root/t/t5411/common-functions.sh
diff options
context:
space:
mode:
authorJiang Xin <worldhello.net@gmail.com>2021-06-17 03:17:27 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-06-17 05:12:24 (GMT)
commit12d6991cf417465d567c38ba8ae7d59bda7a202f (patch)
tree9474d49f346d2db497f1bc2b95dacaf61b69128a /t/t5411/common-functions.sh
parent3c06a583398f6630c7162b463ff1acbdf0110f83 (diff)
downloadgit-12d6991cf417465d567c38ba8ae7d59bda7a202f.zip
git-12d6991cf417465d567c38ba8ae7d59bda7a202f.tar.gz
git-12d6991cf417465d567c38ba8ae7d59bda7a202f.tar.bz2
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>
Diffstat (limited to 't/t5411/common-functions.sh')
-rw-r--r--t/t5411/common-functions.sh20
1 files changed, 15 insertions, 5 deletions
diff --git a/t/t5411/common-functions.sh b/t/t5411/common-functions.sh
index b9c6ade..3c74778 100644
--- a/t/t5411/common-functions.sh
+++ b/t/t5411/common-functions.sh
@@ -18,6 +18,18 @@ create_commits_in () {
done
}
+get_abbrev_oid () {
+ oid=$1 &&
+ suffix=${oid#???????} &&
+ oid=${oid%$suffix} &&
+ if test -n "$oid"
+ then
+ echo "$oid"
+ else
+ echo "undefined-oid"
+ fi
+}
+
# Format the output of git-push, git-show-ref and other commands to make a
# user-friendly and stable text. We can easily prepare the expect text
# without having to worry about changes of the commit ID (full or abbrev.)
@@ -28,12 +40,10 @@ create_commits_in () {
make_user_friendly_and_stable_output () {
sed \
-e "s/'/\"/g" \
- -e "s/$A/<COMMIT-A>/g" \
- -e "s/$B/<COMMIT-B>/g" \
- -e "s/$TAG/<TAG-v123>/g" \
+ -e "s/$(get_abbrev_oid $A)[0-9a-f]*/<COMMIT-A>/g" \
+ -e "s/$(get_abbrev_oid $B)[0-9a-f]*/<COMMIT-B>/g" \
+ -e "s/$(get_abbrev_oid $TAG)[0-9a-f]*/<TAG-v123>/g" \
-e "s/$ZERO_OID/<ZERO-OID>/g" \
- -e "s/$(echo $A | cut -c1-7)[0-9a-f]*/<OID-A>/g" \
- -e "s/$(echo $B | cut -c1-7)[0-9a-f]*/<OID-B>/g" \
-e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#" \
-e "/^error: / d"
}