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