common/bin/hgforest.sh

Print this page
rev 667 : 8011350: hgforest.sh uses non-POSIX sh features that may fail with some shells
Reviewed-by: duke

@@ -1,9 +1,9 @@
 #!/bin/sh
 
 #
-# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License version 2 only, as
 # published by the Free Software Foundation.

@@ -23,23 +23,23 @@
 # questions.
 #
 
 # Shell script for a fast parallel forest command
 command="$1"
-pull_extra_base="$2"
+pull_extra_base="$#"
 
 # Python always buffers stdout significantly, thus we will not see any output from hg clone jdk,
 # until a lot of time has passed! By passing -u to python, we get incremental updates
 # on stdout. Much nicer.
 whichhg="`which hg`"
 
-if [ "${whichhg}" = "" ] ; then
+if [ -z "${whichhg}" ] ; then
   echo Cannot find hg!
   exit 1
 fi
 
-if [ "" = "$command" ] ; then
+if [ -z "$command" ] ; then
   echo No command to hg supplied!
   exit 1
 fi
 
 has_hash_bang="`head -n 1 "${whichhg}" | cut -b 1-2`"

@@ -49,14 +49,19 @@
 if [ "#!" = "$has_hash_bang" ] ; then
    python="`head -n 1 ${whichhg} | cut -b 3-`"
    bpython="`basename "$python"`"
 fi
 
-if [ -x "$python" -a ! -d "$python" -a  "`${python} -V 2>&1 | cut -f 1 -d " "`" == "Python" ] ; then
+if test -x "$python" && test ! -d "$python" ; then
+  vpython="`(${python} -V 2>&1 || echo false)| cut -f 1 -d " "`"
+  if [ "x$vpython" = "xPython" ]; then
   hg="${python} -u ${whichhg}"
-else
-  echo Cannot find python from hg launcher. Running plain hg, which probably has buffered stdout.
+  fi
+fi
+
+if [ -z "$hg" ]; then
+  echo "Cannot find python from hg launcher. Running plain hg, which probably has buffered stdout."
   hg="hg"
 fi
 
 # Clean out the temporary directory that stores the pid files.
 tmp=/tmp/forest.$$

@@ -86,18 +91,25 @@
     fi
   fi
   rm -f -r ${tmp}
 }
 
+remove_last() {
+  while test $# -gt 1; do
+    echo $1
+    shift
+done
+}
+
 trap 'safe_interrupt' INT QUIT
 trap 'nice_exit' EXIT
 
 # Only look in specific locations for possible forests (avoids long searches)
 pull_default=""
 repos=""
 repos_extra=""
-if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then
+if test "${command}" = "clone" || test "${command}" = "fclone" ; then
   subrepos="corba jaxp jaxws langtools jdk hotspot nashorn"
   if [ -f .hg/hgrc ] ; then
     pull_default=`hg paths default`
     if [ "${pull_default}" = "" ] ; then
       echo "ERROR: Need initial clone with 'hg paths default' defined"

@@ -111,11 +123,11 @@
   for i in ${subrepos} ; do
     if [ ! -f ${i}/.hg/hgrc ] ; then
       repos="${repos} ${i}"
     fi
   done
-  if [ "${pull_extra_base}" != "" ] ; then
+  if [ -n "${pull_extra_base}" ] ; then
     subrepos_extra="jdk/src/closed jdk/make/closed jdk/test/closed hotspot/make/closed hotspot/src/closed hotspot/test/closed deploy install sponsors pubs"
     pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'`
     pull_extra="${pull_extra_base}/${pull_default_tail}"
     for i in ${subrepos_extra} ; do
       if [ ! -f ${i}/.hg/hgrc ] ; then

@@ -123,31 +135,31 @@
       fi
     done
   fi
   at_a_time=2
   # Any repos to deal with?
-  if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then
+  if test -z "${repos}" && test -z "${repos_extra}" ; then
     exit
   fi
 else
   hgdirs=`ls -d ./.hg ./*/.hg ./*/*/.hg ./*/*/*/.hg ./*/*/*/*/.hg 2>/dev/null`
   # Derive repository names from the .hg directory locations
   for i in ${hgdirs} ; do
     repos="${repos} `echo ${i} | sed -e 's@/.hg$@@'`"
   done
   for i in ${repos} ; do
-    if [ -h ${i}/.hg/store/lock -o -f ${i}/.hg/store/lock ] ; then
+    if test -h ${i}/.hg/store/lock || test -f ${i}/.hg/store/lock ; then
       locked="${i} ${locked}"
     fi
   done
-  at_a_time=8
+  at_a_time=9
   # Any repos to deal with?
-  if [ "${repos}" = "" ] ; then
+  if [ -z "${repos}" ] ; then
     echo "No repositories to process."
     exit
   fi
-  if [ "${locked}" != "" ] ; then
+  if [ -n "${locked}" ] ; then
     echo "These repositories are locked: ${locked}"
     exit
   fi
 fi
 

@@ -167,11 +179,11 @@
           pull_base="${pull_extra}"
       fi
   done
   (
     (
-      if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then
+      if test "${command}" = "clone" || test "${command}" = "fclone" ; then
         pull_newrepo="`echo ${pull_base}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`"
         echo ${hg} clone ${pull_newrepo} ${i}
         path="`dirname ${i}`"
         if [ "${path}" != "." ] ; then
           times=0

@@ -205,11 +217,12 @@
 ec=0
 if [ -d ${tmp} ]; then
   for rc in ${tmp}/*.pid.rc ; do
     exit_code=`cat ${rc} | tr -d ' \n\r'`
     if [ "${exit_code}" != "0" ] ; then
-      echo "WARNING: ${rc} exited abnormally."
-      ec=1
+      reponame=`basename ${rc} | cut -f 1 -d . | sed -e :a -e 's/^.\{1,20\}$/ &/;ta'`
+      echo "${reponame}:   WARNING: hg cmd exited with ${exit_code}"
+      ec=${exit_code}
     fi
   done
 fi
 exit ${ec}