ohair@276: #!/bin/sh ohair@276: ohair@276: # ohair@436: # Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. ohair@276: # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ohair@276: # ohair@276: # This code is free software; you can redistribute it and/or modify it ohair@276: # under the terms of the GNU General Public License version 2 only, as ohair@276: # published by the Free Software Foundation. ohair@276: # ohair@276: # This code is distributed in the hope that it will be useful, but WITHOUT ohair@276: # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ohair@276: # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ohair@276: # version 2 for more details (a copy is included in the LICENSE file that ohair@276: # accompanied this code). ohair@276: # ohair@276: # You should have received a copy of the GNU General Public License version ohair@276: # 2 along with this work; if not, write to the Free Software Foundation, ohair@276: # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ohair@276: # ohair@276: # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@276: # or visit www.oracle.com if you need additional information or have any ohair@276: # questions. ohair@276: # ohair@276: ohair@276: # Shell script for a fast parallel forest command ohair@436: command="$1" ohair@436: pull_extra_base="$2" ohair@276: ohair@276: tmp=/tmp/forest.$$ ohair@276: rm -f -r ${tmp} ohair@276: mkdir -p ${tmp} ohair@276: ohair@276: # Remove tmp area on A. B. Normal termination ohair@276: trap 'rm -f -r ${tmp}' KILL ohair@276: trap 'rm -f -r ${tmp}' EXIT ohair@276: ohair@276: # Only look in specific locations for possible forests (avoids long searches) ohair@276: pull_default="" ohair@436: repos="" ohair@436: repos_extra="" ohair@436: if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then jjg@645: subrepos="corba jaxp jaxws langtools jdk hotspot nashorn" ohair@276: if [ -f .hg/hgrc ] ; then ohair@276: pull_default=`hg paths default` ohair@436: if [ "${pull_default}" = "" ] ; then ohair@436: echo "ERROR: Need initial clone with 'hg paths default' defined" ohair@436: exit 1 ohair@436: fi ohair@276: fi ohair@276: if [ "${pull_default}" = "" ] ; then ohair@436: echo "ERROR: Need initial repository to use this script" ohair@276: exit 1 ohair@276: fi ohair@276: for i in ${subrepos} ; do ohair@276: if [ ! -f ${i}/.hg/hgrc ] ; then ohair@276: repos="${repos} ${i}" ohair@276: fi ohair@276: done ohair@436: if [ "${pull_extra_base}" != "" ] ; then jcoomes@475: subrepos_extra="jdk/src/closed jdk/make/closed jdk/test/closed hotspot/make/closed hotspot/src/closed hotspot/test/closed deploy install sponsors pubs" ohair@437: pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'` ohair@437: pull_extra="${pull_extra_base}/${pull_default_tail}" ohair@436: for i in ${subrepos_extra} ; do ohair@436: if [ ! -f ${i}/.hg/hgrc ] ; then ohair@436: repos_extra="${repos_extra} ${i}" ohair@436: fi ohair@436: done ohair@436: fi ohair@276: at_a_time=2 ohair@436: # Any repos to deal with? ohair@436: if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then ohair@436: echo "No repositories to clone." ohair@436: exit ohair@436: fi ohair@276: else ohair@276: hgdirs=`ls -d ./.hg ./*/.hg ./*/*/.hg ./*/*/*/.hg ./*/*/*/*/.hg 2>/dev/null` ohair@276: # Derive repository names from the .hg directory locations ohair@276: for i in ${hgdirs} ; do ohair@276: repos="${repos} `echo ${i} | sed -e 's@/.hg$@@'`" ohair@276: done ohair@276: at_a_time=8 ohair@436: # Any repos to deal with? ohair@436: if [ "${repos}" = "" ] ; then ohair@436: echo "No repositories to process." ohair@436: exit ohair@436: fi ohair@276: fi ohair@276: ohair@436: # Echo out what repositories we will clone ohair@436: echo "# Repos: ${repos} ${repos_extra}" ohair@276: ohair@276: # Run the supplied command on all repos in parallel, save output until end ohair@276: n=0 ohair@276: for i in ${repos} ; do ohair@276: echo "Starting on ${i}" ohair@276: n=`expr ${n} '+' 1` ohair@276: ( ohair@276: ( ohair@436: if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then ohair@462: pull_newrepo="`echo ${pull_default}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`" ohair@462: cline="hg clone ${pull_newrepo} ${i}" ohair@276: echo "# ${cline}" ohair@276: ( eval "${cline}" ) ohair@276: else ohair@276: cline="hg $*" ohair@276: echo "# cd ${i} && ${cline}" ohair@276: ( cd ${i} && eval "${cline}" ) ohair@276: fi ohair@276: echo "# exit code $?" ohair@276: ) > ${tmp}/repo.${n} 2>&1 ; cat ${tmp}/repo.${n} ) & ohair@276: if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then ohair@276: sleep 5 ohair@276: fi ohair@276: done ohair@446: # Wait for all hg commands to complete ohair@446: wait ohair@446: ohair@436: if [ "${repos_extra}" != "" ] ; then ohair@436: for i in ${repos_extra} ; do ohair@436: echo "Starting on ${i}" ohair@436: n=`expr ${n} '+' 1` ohair@436: ( ohair@436: ( ohair@462: pull_newextrarepo="`echo ${pull_extra}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`" ohair@462: cline="hg clone ${pull_newextrarepo} ${i}" ohair@436: echo "# ${cline}" ohair@436: ( eval "${cline}" ) ohair@436: echo "# exit code $?" ohair@436: ) > ${tmp}/repo.${n} 2>&1 ; cat ${tmp}/repo.${n} ) & ohair@436: if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then ohair@436: sleep 5 ohair@436: fi ohair@436: done ohair@446: # Wait for all hg commands to complete ohair@446: wait ohair@436: fi ohair@276: ohair@276: # Cleanup ohair@276: rm -f -r ${tmp} ohair@276: ohair@276: # Terminate with exit 0 all the time (hard to know when to say "failed") ohair@276: exit 0 ohair@276: