ohair@276: #!/bin/sh ohair@276: ohair@276: # ohair@276: # Copyright (c) 2009, 2010, 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@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@276: if [ "$1" = "clone" -o "$1" = "fclone" ] ; then ohair@276: subrepos="corba jaxp jaxws langtools jdk hotspot" ohair@276: if [ -f .hg/hgrc ] ; then ohair@276: pull_default=`hg paths default` ohair@276: fi ohair@276: if [ "${pull_default}" = "" ] ; then ohair@276: echo "ERROR: Need initial clone with 'hg paths default' defined" ohair@276: exit 1 ohair@276: fi ohair@276: repos="" 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@276: at_a_time=2 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: repos="" 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@276: fi ohair@276: ohair@276: # Any repos to deal with? ohair@276: if [ "${repos}" = "" ] ; then ohair@276: echo "No repositories to process." ohair@276: exit ohair@276: fi ohair@276: ohair@276: # Echo out what repositories we will process ohair@276: echo "# Repos: ${repos}" 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@276: if [ "$1" = "clone" -o "$1" = "fclone" ] ; then ohair@276: cline="hg $* ${pull_default}/${i} ${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@276: ohair@276: # Wait for all hg commands to complete ohair@276: wait 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: