Tue, 06 May 2014 13:57:30 -0700
8030681: add "serve" command and --quiet and --verbose options to hgforest
Reviewed-by: ihse
common/bin/hgforest.sh | file | annotate | diff | comparison | revisions |
1.1 --- a/common/bin/hgforest.sh Tue Jul 15 18:46:37 2014 -0700 1.2 +++ b/common/bin/hgforest.sh Tue May 06 13:57:30 2014 -0700 1.3 @@ -1,4 +1,4 @@ 1.4 -#!/bin/sh 1.5 +#!/bin/bash 1.6 1.7 # 1.8 # Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. 1.9 @@ -24,12 +24,53 @@ 1.10 # 1.11 1.12 # Shell script for a fast parallel forest command 1.13 -command="$1" 1.14 -pull_extra_base="$2" 1.15 1.16 -if [ "" = "$command" ] ; then 1.17 - echo No command to hg supplied! 1.18 - exit 1 1.19 +global_opts="" 1.20 +status_output="/dev/stdout" 1.21 +qflag="false" 1.22 +vflag="false" 1.23 +while [ $# -gt 0 ] 1.24 +do 1.25 + case $1 in 1.26 + -q | --quiet ) 1.27 + qflag="true" 1.28 + global_opts="${global_opts} -q" 1.29 + status_output="/dev/null" 1.30 + ;; 1.31 + 1.32 + -v | --verbose ) 1.33 + vflag="true" 1.34 + global_opts="${global_opts} -v" 1.35 + ;; 1.36 + 1.37 + '--' ) # no more options 1.38 + shift; break 1.39 + ;; 1.40 + 1.41 + -*) # bad option 1.42 + usage 1.43 + ;; 1.44 + 1.45 + * ) # non option 1.46 + break 1.47 + ;; 1.48 + esac 1.49 + shift 1.50 +done 1.51 + 1.52 + 1.53 +command="$1"; shift 1.54 +repo_base="$@" 1.55 + 1.56 +usage() { 1.57 + echo "usage: $0 [-q|--quiet] [-v|--verbose] [--] <command> [repo_base_path]" > ${status_output} 1.58 + exit 1 1.59 +} 1.60 + 1.61 + 1.62 +if [ "x" = "x$command" ] ; then 1.63 + echo "ERROR: No command to hg supplied!" 1.64 + usage 1.65 fi 1.66 1.67 # Clean out the temporary directory that stores the pid files. 1.68 @@ -40,17 +81,17 @@ 1.69 safe_interrupt () { 1.70 if [ -d ${tmp} ]; then 1.71 if [ "`ls ${tmp}/*.pid`" != "" ]; then 1.72 - echo "Waiting for processes ( `cat ${tmp}/*.pid | tr '\n' ' '`) to terminate nicely!" 1.73 + echo "Waiting for processes ( `cat ${tmp}/*.pid | tr '\n' ' '`) to terminate nicely!" > ${status_output} 1.74 sleep 1 1.75 # Pipe stderr to dev/null to silence kill, that complains when trying to kill 1.76 # a subprocess that has already exited. 1.77 kill -TERM `cat ${tmp}/*.pid | tr '\n' ' '` 2> /dev/null 1.78 wait 1.79 - echo Interrupt complete! 1.80 + echo "Interrupt complete!" > ${status_output} 1.81 fi 1.82 + rm -f -r ${tmp} 1.83 fi 1.84 - rm -f -r ${tmp} 1.85 - exit 1 1.86 + exit 130 1.87 } 1.88 1.89 nice_exit () { 1.90 @@ -58,28 +99,30 @@ 1.91 if [ "`ls ${tmp}`" != "" ]; then 1.92 wait 1.93 fi 1.94 + rm -f -r ${tmp} 1.95 fi 1.96 - rm -f -r ${tmp} 1.97 } 1.98 1.99 trap 'safe_interrupt' INT QUIT 1.100 trap 'nice_exit' EXIT 1.101 1.102 +subrepos="corba jaxp jaxws langtools jdk hotspot nashorn" 1.103 +subrepos_extra="jdk/src/closed jdk/make/closed jdk/test/closed hotspot/make/closed hotspot/src/closed hotspot/test/closed deploy install sponsors pubs" 1.104 + 1.105 # Only look in specific locations for possible forests (avoids long searches) 1.106 pull_default="" 1.107 repos="" 1.108 repos_extra="" 1.109 if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then 1.110 - subrepos="corba jaxp jaxws langtools jdk hotspot nashorn" 1.111 if [ -f .hg/hgrc ] ; then 1.112 pull_default=`hg paths default` 1.113 if [ "${pull_default}" = "" ] ; then 1.114 - echo "ERROR: Need initial clone with 'hg paths default' defined" 1.115 + echo "ERROR: Need initial clone with 'hg paths default' defined" > ${status_output} 1.116 exit 1 1.117 fi 1.118 fi 1.119 if [ "${pull_default}" = "" ] ; then 1.120 - echo "ERROR: Need initial repository to use this script" 1.121 + echo "ERROR: Need initial repository to use this script" > ${status_output} 1.122 exit 1 1.123 fi 1.124 for i in ${subrepos} ; do 1.125 @@ -87,10 +130,9 @@ 1.126 repos="${repos} ${i}" 1.127 fi 1.128 done 1.129 - if [ "${pull_extra_base}" != "" ] ; then 1.130 - subrepos_extra="jdk/src/closed jdk/make/closed jdk/test/closed hotspot/make/closed hotspot/src/closed hotspot/test/closed deploy install sponsors pubs" 1.131 + if [ "${repo_base}" != "" ] ; then 1.132 pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'` 1.133 - pull_extra="${pull_extra_base}/${pull_default_tail}" 1.134 + pull_extra="${repo_base}/${pull_default_tail}" 1.135 for i in ${subrepos_extra} ; do 1.136 if [ ! -f ${i}/.hg/hgrc ] ; then 1.137 repos_extra="${repos_extra} ${i}" 1.138 @@ -100,78 +142,111 @@ 1.139 at_a_time=2 1.140 # Any repos to deal with? 1.141 if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then 1.142 + echo "No repositories to process." > ${status_output} 1.143 exit 1.144 fi 1.145 else 1.146 - hgdirs=`ls -d ./.hg ./*/.hg ./*/*/.hg ./*/*/*/.hg ./*/*/*/*/.hg 2>/dev/null` 1.147 - # Derive repository names from the .hg directory locations 1.148 - for i in ${hgdirs} ; do 1.149 - repos="${repos} `echo ${i} | sed -e 's@/.hg$@@'`" 1.150 + for i in . ${subrepos} ${subrepos_extra} ; do 1.151 + if [ -d ${i}/.hg ] ; then 1.152 + repos="${repos} ${i}" 1.153 + fi 1.154 done 1.155 + 1.156 + # Any repos to deal with? 1.157 + if [ "${repos}" = "" ] ; then 1.158 + echo "No repositories to process." > ${status_output} 1.159 + exit 1.160 + fi 1.161 + 1.162 + # any of the repos locked? 1.163 for i in ${repos} ; do 1.164 if [ -h ${i}/.hg/store/lock -o -f ${i}/.hg/store/lock ] ; then 1.165 locked="${i} ${locked}" 1.166 fi 1.167 done 1.168 + if [ "${locked}" != "" ] ; then 1.169 + echo "ERROR: These repositories are locked: ${locked}" > ${status_output} 1.170 + exit 1 1.171 + fi 1.172 at_a_time=8 1.173 - # Any repos to deal with? 1.174 - if [ "${repos}" = "" ] ; then 1.175 - echo "No repositories to process." 1.176 - exit 1.177 - fi 1.178 - if [ "${locked}" != "" ] ; then 1.179 - echo "These repositories are locked: ${locked}" 1.180 - exit 1.181 - fi 1.182 fi 1.183 1.184 # Echo out what repositories we do a command on. 1.185 -echo "# Repositories: ${repos} ${repos_extra}" 1.186 -echo 1.187 +echo "# Repositories: ${repos} ${repos_extra}" > ${status_output} 1.188 1.189 -# Run the supplied command on all repos in parallel. 1.190 -n=0 1.191 -for i in ${repos} ${repos_extra} ; do 1.192 - n=`expr ${n} '+' 1` 1.193 - repopidfile=`echo ${i} | sed -e 's@./@@' -e 's@/@_@g'` 1.194 - reponame=`echo ${i} | sed -e :a -e 's/^.\{1,20\}$/ &/;ta'` 1.195 - pull_base="${pull_default}" 1.196 - for j in $repos_extra ; do 1.197 +if [ "${command}" = "serve" ] ; then 1.198 + # "serve" is run for all the repos. 1.199 + ( 1.200 + ( 1.201 + ( 1.202 + echo "[web]" 1.203 + echo "description = $(basename $(pwd))" 1.204 + echo "allow_push = *" 1.205 + echo "push_ssl = False" 1.206 + 1.207 + echo "[paths]" 1.208 + for i in ${repos} ${repos_extra} ; do 1.209 + if [ "${i}" != "." ] ; then 1.210 + echo "/$(basename $(pwd))/${i} = ${i}" 1.211 + else 1.212 + echo "/$(basename $(pwd)) = $(pwd)" 1.213 + fi 1.214 + done 1.215 + ) > ${tmp}/serve.web-conf 1.216 + 1.217 + echo "serving root repo $(basename $(pwd))" 1.218 + 1.219 + (PYTHONUNBUFFERED=true hg${global_opts} serve -A ${status_output} -E ${status_output} --pid-file ${tmp}/serve.pid --web-conf ${tmp}/serve.web-conf; echo "$?" > ${tmp}/serve.pid.rc ) 2>&1 & 1.220 + ) 2>&1 | sed -e "s@^@serve: @" > ${status_output} 1.221 + ) & 1.222 +else 1.223 + # Run the supplied command on all repos in parallel. 1.224 + n=0 1.225 + for i in ${repos} ${repos_extra} ; do 1.226 + n=`expr ${n} '+' 1` 1.227 + repopidfile=`echo ${i} | sed -e 's@./@@' -e 's@/@_@g'` 1.228 + reponame=`echo ${i} | sed -e :a -e 's/^.\{1,20\}$/ &/;ta'` 1.229 + pull_base="${pull_default}" 1.230 + for j in $repos_extra ; do 1.231 if [ "$i" = "$j" ] ; then 1.232 pull_base="${pull_extra}" 1.233 fi 1.234 + done 1.235 + ( 1.236 + ( 1.237 + if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then 1.238 + pull_newrepo="`echo ${pull_base}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`" 1.239 + echo "hg clone ${pull_newrepo} ${i}" > ${status_output} 1.240 + path="`dirname ${i}`" 1.241 + if [ "${path}" != "." ] ; then 1.242 + times=0 1.243 + while [ ! -d "${path}" ] ## nested repo, ensure containing dir exists 1.244 + do 1.245 + times=`expr ${times} '+' 1` 1.246 + if [ `expr ${times} '%' 10` -eq 0 ] ; then 1.247 + echo "${path} still not created, waiting..." > ${status_output} 1.248 + fi 1.249 + sleep 5 1.250 + done 1.251 + fi 1.252 + (PYTHONUNBUFFERED=true hg${global_opts} clone ${pull_newrepo} ${i}; echo "$?" > ${tmp}/${repopidfile}.pid.rc ) 2>&1 & 1.253 + else 1.254 + echo "cd ${i} && hg${global_opts} ${command} ${repo_base}" > ${status_output} 1.255 + cd ${i} && (PYTHONUNBUFFERED=true hg${global_opts} ${command} ${command_repo}; echo "$?" > ${tmp}/${repopidfile}.pid.rc ) 2>&1 & 1.256 + fi 1.257 + 1.258 + echo $! > ${tmp}/${repopidfile}.pid 1.259 + ) 2>&1 | sed -e "s@^@${reponame}: @" > ${status_output} 1.260 + ) & 1.261 + 1.262 + if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then 1.263 + sleep 2 1.264 + echo "Waiting 5 secs before spawning next background command." > ${status_output} 1.265 + sleep 3 1.266 + fi 1.267 done 1.268 - ( 1.269 - ( 1.270 - if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then 1.271 - pull_newrepo="`echo ${pull_base}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`" 1.272 - echo hg clone ${pull_newrepo} ${i} 1.273 - path="`dirname ${i}`" 1.274 - if [ "${path}" != "." ] ; then 1.275 - times=0 1.276 - while [ ! -d "${path}" ] ## nested repo, ensure containing dir exists 1.277 - do 1.278 - times=`expr ${times} '+' 1` 1.279 - if [ `expr ${times} '%' 10` -eq 0 ] ; then 1.280 - echo ${path} still not created, waiting... 1.281 - fi 1.282 - sleep 5 1.283 - done 1.284 - fi 1.285 - (PYTHONUNBUFFERED=true hg clone ${pull_newrepo} ${i}; echo "$?" > ${tmp}/${repopidfile}.pid.rc )& 1.286 - else 1.287 - echo "cd ${i} && hg $*" 1.288 - cd ${i} && (PYTHONUNBUFFERED=true hg "$@"; echo "$?" > ${tmp}/${repopidfile}.pid.rc )& 1.289 - fi 1.290 - echo $! > ${tmp}/${repopidfile}.pid 1.291 - ) 2>&1 | sed -e "s@^@${reponame}: @") & 1.292 +fi 1.293 1.294 - if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then 1.295 - sleep 2 1.296 - echo Waiting 5 secs before spawning next background command. 1.297 - sleep 3 1.298 - fi 1.299 -done 1.300 # Wait for all hg commands to complete 1.301 wait 1.302 1.303 @@ -181,7 +256,8 @@ 1.304 for rc in ${tmp}/*.pid.rc ; do 1.305 exit_code=`cat ${rc} | tr -d ' \n\r'` 1.306 if [ "${exit_code}" != "0" ] ; then 1.307 - echo "WARNING: ${rc} exited abnormally." 1.308 + repo="`echo ${rc} | sed -e s@^${tmp}@@ -e 's@/*\([^/]*\)\.pid\.rc$@\1@' -e 's@_@/@g'`" 1.309 + echo "WARNING: ${repo} exited abnormally." > ${status_output} 1.310 ec=1 1.311 fi 1.312 done