Tue, 18 Dec 2012 09:57:01 +0100
8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
Reviewed-by: ohair, erikj
common/bin/hgforest.sh | file | annotate | diff | comparison | revisions | |
get_source.sh | file | annotate | diff | comparison | revisions |
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/common/bin/hgforest.sh Tue Dec 18 09:57:01 2012 +0100 1.3 @@ -0,0 +1,194 @@ 1.4 +#!/bin/sh 1.5 + 1.6 +# 1.7 +# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. 1.8 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.9 +# 1.10 +# This code is free software; you can redistribute it and/or modify it 1.11 +# under the terms of the GNU General Public License version 2 only, as 1.12 +# published by the Free Software Foundation. 1.13 +# 1.14 +# This code is distributed in the hope that it will be useful, but WITHOUT 1.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 +# version 2 for more details (a copy is included in the LICENSE file that 1.18 +# accompanied this code). 1.19 +# 1.20 +# You should have received a copy of the GNU General Public License version 1.21 +# 2 along with this work; if not, write to the Free Software Foundation, 1.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 +# 1.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 +# or visit www.oracle.com if you need additional information or have any 1.26 +# questions. 1.27 +# 1.28 + 1.29 +# Shell script for a fast parallel forest command 1.30 +command="$1" 1.31 +pull_extra_base="$2" 1.32 + 1.33 +# Python always buffers stdout significantly, thus we will not see any output from hg clone jdk, 1.34 +# until a lot of time has passed! By passing -u to python, we get incremental updates 1.35 +# on stdout. Much nicer. 1.36 +whichhg="`which hg`" 1.37 + 1.38 +if [ "${whichhg}" = "" ] ; then 1.39 + echo Cannot find hg! 1.40 + exit 1 1.41 +fi 1.42 + 1.43 +if [ "" = "$command" ] ; then 1.44 + echo No command to hg supplied! 1.45 + exit 1 1.46 +fi 1.47 + 1.48 +has_hash_bang="`head -n 1 "${whichhg}" | cut -b 1-2`" 1.49 +python="" 1.50 +bpython="" 1.51 + 1.52 +if [ "#!" = "$has_hash_bang" ] ; then 1.53 + python="`head -n 1 ${whichhg} | cut -b 3-`" 1.54 + bpython="`basename "$python"`" 1.55 +fi 1.56 + 1.57 +if [ "python" = "$bpython" -a -x "$python" ] ; then 1.58 + hg="${python} -u ${whichhg}" 1.59 +else 1.60 + echo Cannot find python from hg launcher. Running plain hg, which probably has buffered stdout. 1.61 + hg="hg" 1.62 +fi 1.63 + 1.64 +# Clean out the temporary directory that stores the pid files. 1.65 +tmp=/tmp/forest.$$ 1.66 +rm -f -r ${tmp} 1.67 +mkdir -p ${tmp} 1.68 + 1.69 +safe_interrupt () { 1.70 + if [ -d ${tmp} ]; then 1.71 + if [ "`ls ${tmp}`" != "" ]; then 1.72 + echo "Waiting for processes ( `cat ${tmp}/* | tr '\n' ' '`) to terminate nicely!" 1.73 + sleep 1 1.74 + # Pipe stderr to dev/null to silence kill, that complains when trying to kill 1.75 + # a subprocess that has already exited. 1.76 + kill -TERM `cat ${tmp}/* | tr '\n' ' '` 2> /dev/null 1.77 + wait 1.78 + echo Interrupt complete! 1.79 + fi 1.80 + fi 1.81 + rm -f -r ${tmp} 1.82 + exit 1 1.83 +} 1.84 + 1.85 +nice_exit () { 1.86 + if [ -d ${tmp} ]; then 1.87 + if [ "`ls ${tmp}`" != "" ]; then 1.88 + wait 1.89 + fi 1.90 + fi 1.91 + rm -f -r ${tmp} 1.92 +} 1.93 + 1.94 +trap 'safe_interrupt' INT QUIT 1.95 +trap 'nice_exit' EXIT 1.96 + 1.97 +# Only look in specific locations for possible forests (avoids long searches) 1.98 +pull_default="" 1.99 +repos="" 1.100 +repos_extra="" 1.101 +if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then 1.102 + subrepos="corba jaxp jaxws langtools jdk hotspot" 1.103 + if [ -f .hg/hgrc ] ; then 1.104 + pull_default=`hg paths default` 1.105 + if [ "${pull_default}" = "" ] ; then 1.106 + echo "ERROR: Need initial clone with 'hg paths default' defined" 1.107 + exit 1 1.108 + fi 1.109 + fi 1.110 + if [ "${pull_default}" = "" ] ; then 1.111 + echo "ERROR: Need initial repository to use this script" 1.112 + exit 1 1.113 + fi 1.114 + for i in ${subrepos} ; do 1.115 + if [ ! -f ${i}/.hg/hgrc ] ; then 1.116 + repos="${repos} ${i}" 1.117 + fi 1.118 + done 1.119 + if [ "${pull_extra_base}" != "" ] ; then 1.120 + 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.121 + pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'` 1.122 + pull_extra="${pull_extra_base}/${pull_default_tail}" 1.123 + for i in ${subrepos_extra} ; do 1.124 + if [ ! -f ${i}/.hg/hgrc ] ; then 1.125 + repos_extra="${repos_extra} ${i}" 1.126 + fi 1.127 + done 1.128 + fi 1.129 + at_a_time=2 1.130 + # Any repos to deal with? 1.131 + if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then 1.132 + exit 1.133 + fi 1.134 +else 1.135 + hgdirs=`ls -d ./.hg ./*/.hg ./*/*/.hg ./*/*/*/.hg ./*/*/*/*/.hg 2>/dev/null` 1.136 + # Derive repository names from the .hg directory locations 1.137 + for i in ${hgdirs} ; do 1.138 + repos="${repos} `echo ${i} | sed -e 's@/.hg$@@'`" 1.139 + done 1.140 + for i in ${repos} ; do 1.141 + if [ -h ${i}/.hg/store/lock -o -f ${i}/.hg/store/lock ] ; then 1.142 + locked="${i} ${locked}" 1.143 + fi 1.144 + done 1.145 + at_a_time=8 1.146 + # Any repos to deal with? 1.147 + if [ "${repos}" = "" ] ; then 1.148 + echo "No repositories to process." 1.149 + exit 1.150 + fi 1.151 + if [ "${locked}" != "" ] ; then 1.152 + echo "These repositories are locked: ${locked}" 1.153 + exit 1.154 + fi 1.155 +fi 1.156 + 1.157 +# Echo out what repositories we do a command on. 1.158 +echo "# Repositories: ${repos} ${repos_extra}" 1.159 +echo 1.160 + 1.161 +# Run the supplied command on all repos in parallel. 1.162 +n=0 1.163 +for i in ${repos} ${repos_extra} ; do 1.164 + n=`expr ${n} '+' 1` 1.165 + repopidfile=`echo ${i} | sed -e 's@./@@' -e 's@/@_@g'` 1.166 + reponame=`echo ${i} | sed -e :a -e 's/^.\{1,20\}$/ &/;ta'` 1.167 + pull_base="${pull_default}" 1.168 + for j in $repos_extra ; do 1.169 + if [ "$i" = "$j" ] ; then 1.170 + pull_base="${pull_extra}" 1.171 + fi 1.172 + done 1.173 + ( 1.174 + ( 1.175 + if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then 1.176 + pull_newrepo="`echo ${pull_base}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`" 1.177 + echo ${hg} clone ${pull_newrepo} ${i} 1.178 + ${hg} clone ${pull_newrepo} ${i} & 1.179 + else 1.180 + echo "cd ${i} && ${hg} $*" 1.181 + cd ${i} && ${hg} "$@" & 1.182 + fi 1.183 + echo $! > ${tmp}/${repopidfile}.pid 1.184 + ) 2>&1 | sed -e "s@^@${reponame}: @") & 1.185 + 1.186 + if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then 1.187 + sleep 2 1.188 + echo Waiting 5 secs before spawning next background command. 1.189 + sleep 3 1.190 + fi 1.191 +done 1.192 +# Wait for all hg commands to complete 1.193 +wait 1.194 + 1.195 +# Terminate with exit 0 all the time (hard to know when to say "failed") 1.196 +exit 0 1.197 +
2.1 --- a/get_source.sh Wed Dec 12 13:19:32 2012 -0800 2.2 +++ b/get_source.sh Tue Dec 18 09:57:01 2012 +0100 2.3 @@ -26,8 +26,8 @@ 2.4 # 2.5 2.6 # Get clones of all nested repositories 2.7 -sh ./make/scripts/hgforest.sh clone $* 2.8 +sh ./common/bin/hgforest.sh clone "$@" 2.9 2.10 # Update all existing repositories to the latest sources 2.11 -sh ./make/scripts/hgforest.sh pull -u 2.12 +sh ./common/bin/hgforest.sh pull -u 2.13