[pacman-dev] [PATCH 1/2] Remove pre-optimization from in_array()
The '[[ -z' test in in_array() doesn't really do anything, so I'm removing it. I think this is much cleaner. Signed-off-by: DJ Mills <danielmills1@gmail.com> --- scripts/makepkg.sh.in | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 1b132a9..e215c4b 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -318,10 +318,8 @@ in_opt_array() { # 1 - not found ## in_array() { - local needle=$1; shift - [[ -z $1 ]] && return 1 # Not Found - local item - for item in "$@"; do + local needle=$1 item; shift + for item; do [[ $item = $needle ]] && return 0 # Found done return 1 # Not Found -- 1.7.6
Instead of using var=$(command || echo blah); if [[ $var = *"blah"* ]], which IMO is a creative hack, but very unnecessary, simply use: if ! var=$(command); then This patch gets rid of the hack. Signed-off-by: DJ Mills <danielmills1@gmail.com> --- scripts/makepkg.sh.in | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index e215c4b..3152bf1 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1752,9 +1752,7 @@ OPT_LONG+=",install,key:,log,nocolor,nobuild,nocheck,nosign,pkg:,rmdeps" OPT_LONG+=",repackage,skipinteg,sign,source,syncdeps,version,config:" # Pacman Options OPT_LONG+=",noconfirm,noprogressbar" -OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@" || echo 'PARSE_OPTIONS FAILED')" -if [[ $OPT_TEMP = *'PARSE_OPTIONS FAILED'* ]]; then - # This is a small hack to stop the script bailing with 'set -e' +if ! OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@")"; then echo; usage; exit 1 # E_INVALID_OPTION; fi eval set -- "$OPT_TEMP" -- 1.7.6
On 08/07/11 14:31, DJ Mills wrote:
Instead of using var=$(command || echo blah); if [[ $var = *"blah"* ]], which IMO is a creative hack, but very unnecessary, simply use: if ! var=$(command); then
This patch gets rid of the hack.
Signed-off-by: DJ Mills<danielmills1@gmail.com>
On my working branch with a changed commit message. Allan
On 08/07/11 14:31, DJ Mills wrote:
The '[[ -z' test in in_array() doesn't really do anything, so I'm removing it. I think this is much cleaner.
Signed-off-by: DJ Mills<danielmills1@gmail.com>
Pulled to my working branch. I kept the 'for item in "$@"' part as I find it less clear what is being looped when $@ is not specified.
participants (2)
-
Allan McRae
-
DJ Mills