From 176fcaecef4e987c6661058bc053ce96c953489e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Sat, 2 Oct 2010 18:35:12 +0200 Subject: [PATCH] Introduce array_append() function, in favor of inline assignments. --- sunrise-commit | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/sunrise-commit b/sunrise-commit index 7128ec1..17377fa 100755 --- a/sunrise-commit +++ b/sunrise-commit @@ -26,6 +26,16 @@ req() { "${@}" || die "'${@}' failed." } +# Append the arguments to an IFS-separated list variable whose name was +# passed as the first arg. +array_append() { + local varname + varname=${1} + shift + + eval "set -- \${${varname}} \"\${@}\"; ${varname}=\${*}" +} + # -- POSIX compat -- # Check whether 'local' is supported. @@ -97,7 +107,7 @@ is_package_removal() { local dir olist for dir in ${list}; do # 2) These removes have to remove whole directories. - is_whole_dir_removed ${dir} && olist=${olist+${olist} }${dir} + is_whole_dir_removed ${dir} && array_append olist "${dir}" done [ -z "${olist}" ] && return 1 @@ -142,7 +152,7 @@ find_ebuilds() { esac fi SC_CP=${SC_CP:+${SC_CP}, }${category}${pkg} - SC_REMOVED_PACKAGE_LIST=${SC_REMOVED_PACKAGE_LIST:+${SC_REMOVED_PACKAGE_LIST} }${category}${pkg} + array_append SC_REMOVED_PACKAGE_LIST "${category}${pkg}" done SC_ROOT=${category:+../} @@ -151,7 +161,7 @@ find_ebuilds() { # relative to SC_ROOT. SC_CHANGE_LIST= for pkg in ${SC_REMOVED_PACKAGE_LIST}; do - SC_CHANGE_LIST=${SC_CHANGE_LIST+${SC_CHANGE_LIST} }${SC_ROOT}${pkg} + array_append SC_CHANGE_LIST "${SC_ROOT}${pkg}" done local sdir @@ -324,14 +334,14 @@ main() { --) shift - commitmsg=${commitmsg+${commitmsg} }${@} + array_append commitmsg "${@}" break ;; -*) die "Unknown option: ${1}; see --help." >&2 ;; *) - commitmsg=${commitmsg+${commitmsg} }${1} + array_append commitmsg "${1}" ;; esac shift @@ -464,7 +474,7 @@ main() { local pkg regex regex= for pkg in ${SC_REMOVED_PACKAGE_LIST}; do - regex="${regex:+${regex}\|}${pkg}" + regex=${regex:+${regex}\|}${pkg} done say "${GREEN}Grepping for package references...${RESET}"