[csw-devel] SF.net SVN: opencsw:[361] gar-wrapper/mgar

skayser at users.sourceforge.net skayser at users.sourceforge.net
Wed Mar 16 00:21:12 CET 2011


Revision: 361
          http://opencsw.svn.sourceforge.net/opencsw/?rev=361&view=rev
Author:   skayser
Date:     2011-03-15 23:21:12 +0000 (Tue, 15 Mar 2011)

Log Message:
-----------
mgar: restrict functions variables to local scope

Modified Paths:
--------------
    gar-wrapper/mgar

Modified: gar-wrapper/mgar
===================================================================
--- gar-wrapper/mgar	2011-03-15 22:45:53 UTC (rev 360)
+++ gar-wrapper/mgar	2011-03-15 23:21:12 UTC (rev 361)
@@ -64,6 +64,7 @@
 REQ_PKGS="findutils ggrep gmake namazu svn"
 
 function assert_required_tools {
+  local tool dir
   for tool in $REQ_TOOLS; do
     for dir in ${PATH//:/ }; do
       [ -x $dir/$tool ] && continue 2
@@ -79,29 +80,29 @@
 }
 
 function update_self {
-    __rev=${1:-HEAD}
+  local __rev=${1:-HEAD}
 
-    [ -f $0.tmp ] && rm $0.tmp
-    svn export -r $__rev $SVN_SELF $0.tmp >/dev/null
+  [ -f $0.tmp ] && rm $0.tmp
+  svn export -r $__rev $SVN_SELF $0.tmp >/dev/null
 
-    if [ $? -ne 0 ]; then
-        echo "Error: Retrieval from SVN failed. Script untouched." >&2
-        exit 1;
-    fi
+  if [ $? -ne 0 ]; then
+    echo "Error: Retrieval from SVN failed. Script untouched." >&2
+    exit 1;
+  fi
 
-    oldv=`grep '# $Id' $0 | head -1`
-    newv=`grep '# $Id' $0.tmp | head -1`
+  oldv=`grep '# $Id' $0 | head -1`
+  newv=`grep '# $Id' $0.tmp | head -1`
 
-    if [ "$oldv" == "$newv" ]; then
-        echo "Script is already at the desired version. No replacement needed."
-        echo "Current version: $oldv"
-        rm $0.tmp
-        exit;
-    fi
+  if [ "$oldv" == "$newv" ]; then
+    echo "Script is already at the desired version. No replacement needed."
+    echo "Current version: $oldv"
+    rm $0.tmp
+    exit;
+  fi
 
-    mv $0.tmp $0
+  mv $0.tmp $0
 
-    cat <<EOM
+  cat <<EOM
 Script replaced.
 
 Old version: $oldv
@@ -110,13 +111,13 @@
 }
 
 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/^ *//'
 }
 
@@ -159,6 +160,7 @@
 
 # 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'`
@@ -173,7 +175,7 @@
 # Undocumented function to ease the migration of existing local build trees
 # for existing GAR (non-mgar) users. Not intended to stay here forever.
 function convert_existing_buildtree {
-  __buildtree="$1"
+  local __buildtree="$1"
 
   [ -f $__buildtree/Makefile ] || {
     echo "$__buildtree doesn't look like a package build tree." >&2
@@ -199,7 +201,7 @@
 }
 
 function init_buildtree {
-  __buildtree="$1"
+  local __buildtree="$1"
 
   if [ -a "$__buildtree" ]; then
     echo "The directory $__buildtree already exists. Please remove it." >&2
@@ -224,14 +226,14 @@
 }
 
 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 
@@ -247,7 +249,7 @@
 
 # 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
@@ -298,7 +300,7 @@
 
 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
@@ -307,7 +309,7 @@
 
 # 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 \
@@ -320,9 +322,9 @@
 # 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; }


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


More information about the devel mailing list