From d168425cc3c8c82d8b34947ddf3cd7a2c4188039 Mon Sep 17 00:00:00 2001 From: Peter Swica Date: Sun, 30 Jun 2019 11:45:40 -0400 Subject: [PATCH] Cleaning prin so that it passes shellcheck --- prin | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/prin b/prin index 91c4bfd57a6..b8c16c4c3cd 100755 --- a/prin +++ b/prin @@ -53,8 +53,10 @@ PROG=${0##*/} # If NO ARGUMENTS should return *usage*, uncomment the following line: usage=${1:-yes} -source $(dirname $(readlink -ne $BASH_SOURCE))/lib/common.sh -source $TOOL_LIB_PATH/gitlib.sh +# shellcheck source=./lib/common.sh +source "$(dirname "$(readlink -ne ${BASH_SOURCE[0]})")/lib/common.sh" +# shellcheck source=./lib/gitlib.sh +source "$TOOL_LIB_PATH/gitlib.sh" ############################################################################### # FUNCTIONS @@ -70,7 +72,7 @@ show_tags () { local pr=$1 local initial_commit=$2 shift 2 - local cp_commits=($*) + local cp_commits=("$*") local commit local commit_seconds local tag_seconds @@ -97,11 +99,11 @@ show_tags () { fi # We only care about the initial commit for latency calculation - commit_seconds=$(git show -s --format="%ct" $initial_commit) + commit_seconds=$(git show -s --format="%ct" "$initial_commit") for commit in $initial_commit ${cp_commits[*]}; do - for tag in $(git tag --contains $commit); do - tag_seconds=$(git show -s --pretty=format:%ct $tag |tail -1) + for tag in $(git tag --contains "$commit"); do + tag_seconds=$(git show -s --pretty=format:%ct "$tag" |tail -1) # Convert to days with some precision days=$(echo "scale=2; ($tag_seconds-$commit_seconds)/86400"|bc) @@ -121,7 +123,7 @@ show_tags () { ############################################################################### # Stubbed out security_layer::hosted_map () { - logecho "Skipping $FUNCNAME extensions..." + logecho "Skipping ${FUNCNAME[0]} extensions..." return 0 } @@ -142,15 +144,15 @@ if [[ ${POSITIONAL_ARGV[0]} =~ [0-9]{5,} ]]; then # non-cherrypick commit searches on branches INITIAL_COMMIT=$(git log --grep "Merge pull request #$PR" \ --all --pretty=format:"%h") - CP_COMMITS=($(git log --grep "cherry-pick-of-.*#$PR-" \ - --all --pretty=format:"%h")) + mapfile -i CP_COMMITS < <(git log --grep "cherry-pick-of-.*#$PR-" \ + --all --pretty=format:"%h") else # TODO: Need to validate this is a git hash INITIAL_COMMIT=("${POSITIONAL_ARGV[0]}") fi -[[ -z "$INITIAL_COMMIT" ]] && common::exit 1 "No commit/pr found in this repo." +[[ -z "${INITIAL_COMMIT[0]}" ]] && common::exit 1 "No commit/pr found in this repo." security_layer::hosted_map -show_tags "$PR" $INITIAL_COMMIT ${CP_COMMITS[*]} +show_tags "$PR" "${INITIAL_COMMIT[0]}" "${CP_COMMITS[*]}"