[csw-devel] [PATCH] mgar: Use local variables

Maciej Blizinski maciej at opencsw.org
Sat Mar 5 11:01:15 CET 2011


Bash support local variables in function, if they are declared.  This patch
declares local variables for functions in mgar.
---
 gar-wrapper/mgar |   25 ++++++++++++++-----------
 1 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/gar-wrapper/mgar b/gar-wrapper/mgar
index acf48db..5d5ce56 100755
--- a/gar-wrapper/mgar
+++ b/gar-wrapper/mgar
@@ -54,6 +54,8 @@ REQ_TOOLS="gfind ggrep gmake gxargs mknmz namazu svn"
 REQ_PKGS="findutils ggrep gmake namazu svn"
 
 function assert_required_tools {
+  local tool
+  local dir
   for tool in $REQ_TOOLS; do
     for dir in ${PATH//:/ }; do
       [ -x $dir/$tool ] && continue 2
@@ -100,13 +102,13 @@ EOM
 }
 
 function read_config_value {
-  __param=$1
+  local __param=$1
   [ -f ~/.garrc ] || die_config_missing
   ggrep -E "^$__param *=" ~/.garrc | tail -1 | cut -d= -f2 | sed -e 's/^ *//'
 }
 
 function read_makefile_value {
-  __param=$1
+  local __param=$1
   ggrep -E "^$__param *=" Makefile | tail -1 | cut -d= -f2 | sed -e 's/^ *//'
 }
 
@@ -149,6 +151,7 @@ function assert_in_pkg_dir {
 
 # Is this a per-pkg command? Relies on *-cmd markers in the code (c.f. ##main)
 function is_per_pkg_command {
+  local __cmd __global_cmds
   __cmd=$1
   __global_cmds=`sed -ne '/^# global-cmds/,/^# \/global-cmds/p' $0 | \
     ggrep -E '^\s*[^)]+\) ' | cut -d\) -f1 | tr '|' '\n'`
@@ -189,7 +192,7 @@ function convert_existing_buildtree {
 }
 
 function init_buildtree {
-  __buildtree="$1"
+  local __buildtree="$1"
 
   if [ -a "$__buildtree" ]; then
     echo "The directory $__buildtree already exists. Please remove it." >&2
@@ -214,14 +217,14 @@ function init_buildtree {
 }
 
 function create_legacy_gar_link {
-  __buildsys="$1"
+  local __buildsys="$1"
   if [ ! -h "$__buildsys"/gar ]; then
     ( cd "$__buildsys" && ln -s . gar )
   fi
 }
 
 function assert_multi_buildsys_tree {
-  __buildsys_tree="$1"
+  local __buildsys_tree="$1"
 
   # migrate from single-buildsys to multi-buildsys (<= mgar version 297)
   if [ -f "$__buildsys_tree"/category.mk ]; then 
@@ -237,7 +240,7 @@ function assert_multi_buildsys_tree {
 
 # Commit working files (prefixes pkg path and checks for untracked changes)
 function verify_local_status_and_commit() {
-
+  local opts __forceflag __logmsg __untracked
   # Beware: getopts stops on the first non-option argument, thus
   # "mgar . -m foo -f" won't see any getopts handling
   while getopts "fm:" opts ; do
@@ -288,7 +291,7 @@ function get_stagedir() {
 
 function get_pkg_buildsysdir() {
   # fallback to svn:externals until builds are adjusted to carry GARYTPE
-  __gartype=`read_makefile_value GARTYPE`;
+  local __gartype=`read_makefile_value GARTYPE`;
   if [ -z "$__gartype" ]; then
     __gartype=`svn pg svn:externals . | awk -F/ '/^gar/ { print $NF }'`
   fi
@@ -297,7 +300,7 @@ function get_pkg_buildsysdir() {
 
 # Build the index for locating Makefiles within the package build tree
 function build_index() {
-  __buildtree=$1
+  local __buildtree=$1
   [ -d "$__buildtree/.index" ] || mkdir "$__buildtree/.index"
   cd "$__buildtree" && mknmz \
       -Ux \
@@ -310,9 +313,9 @@ function build_index() {
 # why we do a keyword search first and then - if a specific search "field" was
 # requested - narrow down the result set with grep.
 function search_index() {
-  __buildtree=${1-}
-  __term="$2"
-  __searchby=""
+  local __buildtree=${1-}
+  local __term="$2"
+  local __searchby=""
 
   [ -d "$__buildtree/.index" ] || \
     { echo "Index not found, create it with: mgar index" >&2; exit 2; }
-- 
1.7.3.2



More information about the devel mailing list