Skip to content

Commit

Permalink
get-template-library: various code modernizations suggested by codecl…
Browse files Browse the repository at this point in the history
…imate

- Replace -a by &&
- egrep replaced by grep -E
- grep usage to check a variable content
- variable quoting
- variable definition testing
  • Loading branch information
jouvin committed Nov 10, 2024
1 parent 65ead6f commit d875125
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/scripts/get-template-library
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ then
else
pr_target=${quattor_version}
fi
elif [ -n "$(echo ${pr_target} | egrep '^template-library-')" ]
elif echo "${pr_target}" | grep -E -q '^template-library-'
then
# Old tag name format: renormalize to the new format without the template-library- prefix
[ ${verbose} -eq 1 ] && echo "pr_target: template-library- prefix removed (legacy tag format)"
Expand Down Expand Up @@ -355,16 +355,16 @@ do
tags_ignore_pattern=${!tags_ignore_pattern_variable}
if [ -z ${tags_ignore_pattern} ]
then
if [ -z "$(echo ${branch_pattern} | egrep -- ${tags_ignore_pattern_pattern})" ]
if echo "${branch_pattern}" | grep -E -q -- ${tags_ignore_pattern_pattern}
then
tags_ignore_pattern=0
else
tags_ignore_pattern=1
else
tags_ignore_pattern=0
fi
fi

git_clone_dir=${git_clone_root}/${repo}
if [ $?{!master_dir_variable} ]
if [ "${!master_dir_variable}" ]
then
master_dir_name=${!master_dir_variable}
fi
Expand All @@ -382,7 +382,7 @@ do
# In fact branch_pattern can be a regexp matched against existing branch names
if [ ${use_tags} -eq 1 ]
then
if [ -n "${quattor_version}" -a ${ignore_version} -eq 0 ]
if [ -n "${quattor_version}" ] && [ ${ignore_version} -eq 0 ]
then
if [ ${tags_ignore_pattern} -eq 1 ]
then
Expand All @@ -392,14 +392,14 @@ do
fi
fi
[ ${verbose} -eq 1 ] && echo "Using tags rather than branches for repository ${repo} (branch pattern=${branch_pattern})"
branch_list=$(git tag | egrep -- "${branch_pattern}")
branch_list=$(git tag | grep -E -- "${branch_pattern}")
# If version is HEAD, need to add master branch to all the other tags
if [ "${quattor_version}" = "HEAD" ]
then
branch_list="${branch_list} master"
fi
else
branch_list=$(git branch -r | egrep "origin/${branch_pattern}" | grep -v HEAD)
branch_list=$(git branch -r | grep -E "origin/${branch_pattern}" | grep -v HEAD)
fi
[ ${verbose} -eq 1 -o ${list_branches} -eq 1 ] && echo -e "Branches/tags found in ${repo}:\n${branch_list}"
[ ${list_branches} -eq 1 ] && continue
Expand All @@ -422,7 +422,7 @@ do
if [ ${use_tags} -eq 0 ]
then
pr_actual_target=${branch_or_tag}
if [ "${branch_or_tag}" = "master" -a $?{master_dir_name} ]
if [ "${branch_or_tag}" = "master" ] && [ "${master_dir_name}" ]
then
branch_dir=${master_dir_name}
else
Expand All @@ -434,7 +434,7 @@ do
pr_actual_target=${tag_dir}
# master is normally not a tag name but master branch can be added to
# other tags when the version is HEAD (for example for template-library-core)
if [ "${tag_dir}" = "master" -a $?{master_dir_name} ]
if [ "${tag_dir}" = "master" ] && [ "${master_dir_name}" ]
then
tag_dir=${master_dir_name}
fi
Expand All @@ -446,7 +446,7 @@ do
# If branch_dir is not tag_dir or master, indicates a repository without a master
# branch (e.g. template-library-grid). In this case, pr_actual_target must be
# redefined as branch_dir-tag_dir, as the tag name is prefixed by the branch name (branch_dir).
if [ "${branch_dir}" != "master" -a "${branch_dir}" != "${tag_dir}" ]
if [ "${branch_dir}" != "master" ] && [ "${branch_dir}" != "${tag_dir}" ]
then
pr_actual_target="${branch_dir}-${tag_dir}"
fi
Expand All @@ -459,7 +459,7 @@ do
for ignore_pattern in ${ignore_branch_patterns}
do
[ ${verbose} -eq 1 ] && echo "Branch=${remote_branch}, ignore_pattern = >>${ignore_pattern}<<"
if [ -n "$(echo ${branch_dir} | egrep -- ${ignore_pattern})" -a "${branch_dir}" != "${quattor_version}" ]
if [ "${branch_dir}" != "${quattor_version}" ] && echo "${branch_dir}" | grep -E -q -- "${ignore_pattern}"
then
[ ${verbose} -eq 1 ] && echo "Branch ${remote_branch} ignored"
ignore_branch=1
Expand All @@ -470,7 +470,7 @@ do
for ignore_pattern in ${ignore_version_patterns}
do
[ ${verbose} -eq 1 ] && echo "Branch=${remote_branch}, version=${tag_dir}, ignore_version_pattern = >>${ignore_pattern}<<"
if [ -n "$(echo ${tag_dir} | egrep -- ${ignore_pattern})" -a "${tag_dir}" != "${quattor_version}" ]
if [ "${tag_dir}" != "${quattor_version}" ] && echo "${tag_dir}" | grep -E -q -- "${ignore_pattern}"
then
[ ${verbose} -eq 1 ] && echo "Branch ${remote_branch} (version ${tag_dir}) ignored"
ignore_branch=1
Expand All @@ -486,7 +486,7 @@ do
# If --continuous-inegration and the current repo/target matches the CI context, just define src_dir
# to be what has been checked out as part of the CI.
[ ${verbose} -eq 1 ] && echo "use_ci_work_dir=${use_ci_work_dir}, repo_name=${repo_name}, pr_repo=${pr_repo}, pr_target=${pr_target}, pr_actual_target=${pr_actual_target}"
if [ ${use_ci_work_dir} -eq 1 -a "${pr_repo}" = "${repo_name}" -a "${pr_target}" = "${pr_actual_target}" ]
if [ ${use_ci_work_dir} -eq 1 ] && [ "${pr_repo}" = "${repo_name}" ] && [ "${pr_target}" = "${pr_actual_target}" ]
then
src_dir=${ci_work_dir}

Expand All @@ -500,7 +500,7 @@ do
if [ -n "${pull_request}" ]
then
[ ${verbose} -eq 1 ] && echo "Checking if pull request applies to current branch/tag (pr_repo=${pr_repo}, pr_target=${pr_target}, pr_actual_target=${pr_actual_target})..."
if [ "${pr_repo}" = "${repo_name}" -a "${pr_target}" = "${pr_actual_target}" ]
if [ "${pr_repo}" = "${repo_name}" ] && [ "${pr_target}" = "${pr_actual_target}" ]
then
echo "Merging pull request from ${pr_user}/${pr_branch} into branch/tag ${branch_or_tag}..."
pr_remote=${git_url_root}/${pr_user}/${pr_repo}
Expand Down Expand Up @@ -567,7 +567,7 @@ do
fi

# Except if --debug has been specified, remove Git clone created
if [ ${verbose} -eq 0 -a -d ${repo_dir} ]
if [ ${verbose} -eq 0 ] && [ -d "${repo_dir}" ]
then
rm -Rf ${repo_dir}
fi
Expand All @@ -577,14 +577,14 @@ done # repository loop
# cluster.build.properties: update version used to the requested Quattor version.
# Ine the case of HEAD, use the directory the master branch has been checkout to/

if [ ${list_branches} -eq 0 -a ${cluster_build_properties_update} -eq 1 ]
if [ ${list_branches} -eq 0 ] && [ ${cluster_build_properties_update} -eq 1 ]
then
property_files=$(find ${template_lib_root}/clusters -name cluster.build.properties)
if [ -n "${property_files}" ]
then
if [ "${quattor_version}" = "HEAD" ]
then
if [ $?{core_master_dir} ]
if [ ${core_master_dir} ]
then
quattor_version_dir=${core_master_dir}
else
Expand All @@ -594,7 +594,7 @@ then
quattor_version_dir=${branch_or_tag}
fi
echo "Updating cluster.build.properties files to use Quattor version ${quattor_version_dir} ($(echo ${property_files}))..."
sed -i "s%\squattor/\S\+\s% quattor/${quattor_version_dir} %" ${property_files}
sed -i "s%\squattor/\S\+\s% quattor/${quattor_version_dir} %" ${property_files}
else
echo "Warning: no cluster.build.properties file found. Examples may be incomplete"
fi
Expand Down

0 comments on commit d875125

Please sign in to comment.