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