common/bin/hgforest.sh

Print this page
rev 1005 : 8038435: Some hgforest.sh commands don't receive parameters
Reviewed-by: duke
   1 #!/bin/bash
   2 
   3 #
   4 # Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
   5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   6 #
   7 # This code is free software; you can redistribute it and/or modify it
   8 # under the terms of the GNU General Public License version 2 only, as
   9 # published by the Free Software Foundation.
  10 #
  11 # This code is distributed in the hope that it will be useful, but WITHOUT
  12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14 # version 2 for more details (a copy is included in the LICENSE file that
  15 # accompanied this code).
  16 #
  17 # You should have received a copy of the GNU General Public License version
  18 # 2 along with this work; if not, write to the Free Software Foundation,
  19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20 #
  21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA


  43       global_opts="${global_opts} -v"
  44       ;;
  45 
  46     '--' ) # no more options
  47       shift; break
  48       ;;
  49 
  50     -*)  # bad option
  51       usage
  52       ;;
  53 
  54      * )  # non option
  55       break
  56       ;;
  57   esac
  58   shift
  59 done
  60 
  61 
  62 command="$1"; shift
  63 repo_base="$@"
  64 
  65 usage() {
  66       echo "usage: $0 [-q|--quiet] [-v|--verbose] [--] <command> [repo_base_path]" > ${status_output}
  67       exit 1
  68 }
  69 
  70 
  71 if [ "x" = "x$command" ] ; then
  72   echo "ERROR: No command to hg supplied!"
  73   usage
  74 fi
  75 
  76 # Clean out the temporary directory that stores the pid files.
  77 tmp=/tmp/forest.$$
  78 rm -f -r ${tmp}
  79 mkdir -p ${tmp}
  80 
  81 safe_interrupt () {
  82   if [ -d ${tmp} ]; then
  83     if [ "`ls ${tmp}/*.pid`" != "" ]; then
  84       echo "Waiting for processes ( `cat ${tmp}/*.pid | tr '\n' ' '`) to terminate nicely!" > ${status_output}
  85       sleep 1
  86       # Pipe stderr to dev/null to silence kill, that complains when trying to kill


  97 nice_exit () {
  98   if [ -d ${tmp} ]; then
  99     if [ "`ls ${tmp}`" != "" ]; then
 100       wait
 101     fi
 102     rm -f -r ${tmp}
 103   fi
 104 }
 105 
 106 trap 'safe_interrupt' INT QUIT
 107 trap 'nice_exit' EXIT
 108 
 109 subrepos="corba jaxp jaxws langtools jdk hotspot nashorn"
 110 subrepos_extra="closed jdk/src/closed jdk/make/closed jdk/test/closed hotspot/make/closed hotspot/src/closed hotspot/test/closed deploy install sponsors pubs"
 111 
 112 # Only look in specific locations for possible forests (avoids long searches)
 113 pull_default=""
 114 repos=""
 115 repos_extra=""
 116 if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then
 117   if [ -f .hg/hgrc ] ; then




 118     pull_default=`hg paths default`
 119     if [ "${pull_default}" = "" ] ; then
 120       echo "ERROR: Need initial clone with 'hg paths default' defined" > ${status_output}
 121       exit 1
 122     fi
 123   fi
 124   if [ "${pull_default}" = "" ] ; then
 125     echo "ERROR: Need initial repository to use this script" > ${status_output}
 126     exit 1
 127   fi

 128   for i in ${subrepos} ; do
 129     if [ ! -f ${i}/.hg/hgrc ] ; then
 130       repos="${repos} ${i}"
 131     fi
 132   done
 133   if [ "${repo_base}" != "" ] ; then
 134     pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'`
 135     pull_extra="${repo_base}/${pull_default_tail}"
 136     for i in ${subrepos_extra} ; do
 137       if [ ! -f ${i}/.hg/hgrc ] ; then
 138         repos_extra="${repos_extra} ${i}"
 139       fi
 140     done
 141   fi
 142   at_a_time=2
 143   # Any repos to deal with?
 144   if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then
 145     echo "No repositories to process." > ${status_output}
 146     exit
 147   fi
 148 else
 149   for i in . ${subrepos} ${subrepos_extra} ; do
 150     if [ -d ${i}/.hg ] ; then
 151       repos="${repos} ${i}"
 152     fi
 153   done
 154 
 155   # Any repos to deal with?


 214     done
 215     (
 216       (
 217         if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then
 218           pull_newrepo="`echo ${pull_base}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`"
 219           echo "hg clone ${pull_newrepo} ${i}" > ${status_output}
 220           path="`dirname ${i}`"
 221           if [ "${path}" != "." ] ; then
 222             times=0
 223             while [ ! -d "${path}" ]   ## nested repo, ensure containing dir exists
 224             do
 225               times=`expr ${times} '+' 1`
 226               if [ `expr ${times} '%' 10` -eq 0 ] ; then
 227                 echo "${path} still not created, waiting..." > ${status_output}
 228               fi
 229               sleep 5
 230             done
 231           fi
 232           (PYTHONUNBUFFERED=true hg${global_opts} clone ${pull_newrepo} ${i}; echo "$?" > ${tmp}/${repopidfile}.pid.rc ) 2>&1 &
 233         else
 234           echo "cd ${i} && hg${global_opts} ${command} ${repo_base}" > ${status_output}
 235           cd ${i} && (PYTHONUNBUFFERED=true hg${global_opts} ${command} ${command_repo}; echo "$?" > ${tmp}/${repopidfile}.pid.rc ) 2>&1 &
 236         fi
 237 
 238         echo $! > ${tmp}/${repopidfile}.pid
 239       ) 2>&1 | sed -e "s@^@${reponame}:   @" > ${status_output}
 240     ) &
 241 
 242     if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then
 243       sleep 2
 244       echo "Waiting 5 secs before spawning next background command." > ${status_output}
 245       sleep 3
 246     fi
 247   done
 248 fi
 249 
 250 # Wait for all hg commands to complete
 251 wait
 252 
 253 # Terminate with exit 0 only if all subprocesses were successful
 254 ec=0
 255 if [ -d ${tmp} ]; then
   1 #!/bin/sh
   2 
   3 #
   4 # Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
   5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   6 #
   7 # This code is free software; you can redistribute it and/or modify it
   8 # under the terms of the GNU General Public License version 2 only, as
   9 # published by the Free Software Foundation.
  10 #
  11 # This code is distributed in the hope that it will be useful, but WITHOUT
  12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14 # version 2 for more details (a copy is included in the LICENSE file that
  15 # accompanied this code).
  16 #
  17 # You should have received a copy of the GNU General Public License version
  18 # 2 along with this work; if not, write to the Free Software Foundation,
  19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20 #
  21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA


  43       global_opts="${global_opts} -v"
  44       ;;
  45 
  46     '--' ) # no more options
  47       shift; break
  48       ;;
  49 
  50     -*)  # bad option
  51       usage
  52       ;;
  53 
  54      * )  # non option
  55       break
  56       ;;
  57   esac
  58   shift
  59 done
  60 
  61 
  62 command="$1"; shift
  63 command_args="$@"
  64 
  65 usage() {
  66       echo "usage: $0 [-q|--quiet] [-v|--verbose] [--] <command> [commands...]" > ${status_output}
  67       exit 1
  68 }
  69 
  70 
  71 if [ "x" = "x$command" ] ; then
  72   echo "ERROR: No command to hg supplied!"
  73   usage
  74 fi
  75 
  76 # Clean out the temporary directory that stores the pid files.
  77 tmp=/tmp/forest.$$
  78 rm -f -r ${tmp}
  79 mkdir -p ${tmp}
  80 
  81 safe_interrupt () {
  82   if [ -d ${tmp} ]; then
  83     if [ "`ls ${tmp}/*.pid`" != "" ]; then
  84       echo "Waiting for processes ( `cat ${tmp}/*.pid | tr '\n' ' '`) to terminate nicely!" > ${status_output}
  85       sleep 1
  86       # Pipe stderr to dev/null to silence kill, that complains when trying to kill


  97 nice_exit () {
  98   if [ -d ${tmp} ]; then
  99     if [ "`ls ${tmp}`" != "" ]; then
 100       wait
 101     fi
 102     rm -f -r ${tmp}
 103   fi
 104 }
 105 
 106 trap 'safe_interrupt' INT QUIT
 107 trap 'nice_exit' EXIT
 108 
 109 subrepos="corba jaxp jaxws langtools jdk hotspot nashorn"
 110 subrepos_extra="closed jdk/src/closed jdk/make/closed jdk/test/closed hotspot/make/closed hotspot/src/closed hotspot/test/closed deploy install sponsors pubs"
 111 
 112 # Only look in specific locations for possible forests (avoids long searches)
 113 pull_default=""
 114 repos=""
 115 repos_extra=""
 116 if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then
 117   if [ ! -f .hg/hgrc ] ; then
 118     echo "ERROR: Need initial repository to use this script" > ${status_output}
 119     exit 1
 120   fi
 121 
 122   pull_default=`hg paths default`
 123   if [ "${pull_default}" = "" ] ; then
 124     echo "ERROR: Need initial clone with 'hg paths default' defined" > ${status_output}
 125     exit 1
 126   fi
 127   pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'`
 128   if [ "x${pull_default}" = "x${pull_default_tail}" ] ; then
 129       echo "ERROR: Need initial clone from non-local source" > ${status_output}
 130       exit 1
 131   fi
 132 
 133   for i in ${subrepos} ; do
 134     if [ ! -f ${i}/.hg/hgrc ] ; then
 135       repos="${repos} ${i}"
 136     fi
 137   done
 138   if [ "${command_args}" != "" ] ; then
 139     pull_extra="${command_args}/${pull_default_tail}"

 140     for i in ${subrepos_extra} ; do
 141       if [ ! -f ${i}/.hg/hgrc ] ; then
 142         repos_extra="${repos_extra} ${i}"
 143       fi
 144     done
 145   fi
 146   at_a_time=2
 147   # Any repos to deal with?
 148   if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then
 149     echo "No repositories to process." > ${status_output}
 150     exit
 151   fi
 152 else
 153   for i in . ${subrepos} ${subrepos_extra} ; do
 154     if [ -d ${i}/.hg ] ; then
 155       repos="${repos} ${i}"
 156     fi
 157   done
 158 
 159   # Any repos to deal with?


 218     done
 219     (
 220       (
 221         if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then
 222           pull_newrepo="`echo ${pull_base}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`"
 223           echo "hg clone ${pull_newrepo} ${i}" > ${status_output}
 224           path="`dirname ${i}`"
 225           if [ "${path}" != "." ] ; then
 226             times=0
 227             while [ ! -d "${path}" ]   ## nested repo, ensure containing dir exists
 228             do
 229               times=`expr ${times} '+' 1`
 230               if [ `expr ${times} '%' 10` -eq 0 ] ; then
 231                 echo "${path} still not created, waiting..." > ${status_output}
 232               fi
 233               sleep 5
 234             done
 235           fi
 236           (PYTHONUNBUFFERED=true hg${global_opts} clone ${pull_newrepo} ${i}; echo "$?" > ${tmp}/${repopidfile}.pid.rc ) 2>&1 &
 237         else
 238           echo "cd ${i} && hg${global_opts} ${command} ${command_args}" > ${status_output}
 239           cd ${i} && (PYTHONUNBUFFERED=true hg${global_opts} ${command} ${command_args}; echo "$?" > ${tmp}/${repopidfile}.pid.rc ) 2>&1 &
 240         fi
 241 
 242         echo $! > ${tmp}/${repopidfile}.pid
 243       ) 2>&1 | sed -e "s@^@${reponame}:   @" > ${status_output}
 244     ) &
 245 
 246     if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then
 247       sleep 2
 248       echo "Waiting 5 secs before spawning next background command." > ${status_output}
 249       sleep 3
 250     fi
 251   done
 252 fi
 253 
 254 # Wait for all hg commands to complete
 255 wait
 256 
 257 # Terminate with exit 0 only if all subprocesses were successful
 258 ec=0
 259 if [ -d ${tmp} ]; then