Tue, 13 Sep 2011 08:37:34 -0700
Merge
ohair@276 | 1 | #!/bin/sh |
ohair@276 | 2 | |
ohair@276 | 3 | # |
ohair@276 | 4 | # Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. |
ohair@276 | 5 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ohair@276 | 6 | # |
ohair@276 | 7 | # This code is free software; you can redistribute it and/or modify it |
ohair@276 | 8 | # under the terms of the GNU General Public License version 2 only, as |
ohair@276 | 9 | # published by the Free Software Foundation. |
ohair@276 | 10 | # |
ohair@276 | 11 | # This code is distributed in the hope that it will be useful, but WITHOUT |
ohair@276 | 12 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ohair@276 | 13 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ohair@276 | 14 | # version 2 for more details (a copy is included in the LICENSE file that |
ohair@276 | 15 | # accompanied this code). |
ohair@276 | 16 | # |
ohair@276 | 17 | # You should have received a copy of the GNU General Public License version |
ohair@276 | 18 | # 2 along with this work; if not, write to the Free Software Foundation, |
ohair@276 | 19 | # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ohair@276 | 20 | # |
ohair@276 | 21 | # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@276 | 22 | # or visit www.oracle.com if you need additional information or have any |
ohair@276 | 23 | # questions. |
ohair@276 | 24 | # |
ohair@276 | 25 | |
ohair@276 | 26 | # Shell script for a fast parallel forest command |
ohair@276 | 27 | |
ohair@276 | 28 | tmp=/tmp/forest.$$ |
ohair@276 | 29 | rm -f -r ${tmp} |
ohair@276 | 30 | mkdir -p ${tmp} |
ohair@276 | 31 | |
ohair@276 | 32 | # Remove tmp area on A. B. Normal termination |
ohair@276 | 33 | trap 'rm -f -r ${tmp}' KILL |
ohair@276 | 34 | trap 'rm -f -r ${tmp}' EXIT |
ohair@276 | 35 | |
ohair@276 | 36 | # Only look in specific locations for possible forests (avoids long searches) |
ohair@276 | 37 | pull_default="" |
ohair@276 | 38 | if [ "$1" = "clone" -o "$1" = "fclone" ] ; then |
ohair@276 | 39 | subrepos="corba jaxp jaxws langtools jdk hotspot" |
ohair@276 | 40 | if [ -f .hg/hgrc ] ; then |
ohair@276 | 41 | pull_default=`hg paths default` |
ohair@276 | 42 | fi |
ohair@276 | 43 | if [ "${pull_default}" = "" ] ; then |
ohair@276 | 44 | echo "ERROR: Need initial clone with 'hg paths default' defined" |
ohair@276 | 45 | exit 1 |
ohair@276 | 46 | fi |
ohair@276 | 47 | repos="" |
ohair@276 | 48 | for i in ${subrepos} ; do |
ohair@276 | 49 | if [ ! -f ${i}/.hg/hgrc ] ; then |
ohair@276 | 50 | repos="${repos} ${i}" |
ohair@276 | 51 | fi |
ohair@276 | 52 | done |
ohair@276 | 53 | at_a_time=2 |
ohair@276 | 54 | else |
ohair@276 | 55 | hgdirs=`ls -d ./.hg ./*/.hg ./*/*/.hg ./*/*/*/.hg ./*/*/*/*/.hg 2>/dev/null` |
ohair@276 | 56 | # Derive repository names from the .hg directory locations |
ohair@276 | 57 | repos="" |
ohair@276 | 58 | for i in ${hgdirs} ; do |
ohair@276 | 59 | repos="${repos} `echo ${i} | sed -e 's@/.hg$@@'`" |
ohair@276 | 60 | done |
ohair@276 | 61 | at_a_time=8 |
ohair@276 | 62 | fi |
ohair@276 | 63 | |
ohair@276 | 64 | # Any repos to deal with? |
ohair@276 | 65 | if [ "${repos}" = "" ] ; then |
ohair@276 | 66 | echo "No repositories to process." |
ohair@276 | 67 | exit |
ohair@276 | 68 | fi |
ohair@276 | 69 | |
ohair@276 | 70 | # Echo out what repositories we will process |
ohair@276 | 71 | echo "# Repos: ${repos}" |
ohair@276 | 72 | |
ohair@276 | 73 | # Run the supplied command on all repos in parallel, save output until end |
ohair@276 | 74 | n=0 |
ohair@276 | 75 | for i in ${repos} ; do |
ohair@276 | 76 | echo "Starting on ${i}" |
ohair@276 | 77 | n=`expr ${n} '+' 1` |
ohair@276 | 78 | ( |
ohair@276 | 79 | ( |
ohair@276 | 80 | if [ "$1" = "clone" -o "$1" = "fclone" ] ; then |
ohair@276 | 81 | cline="hg $* ${pull_default}/${i} ${i}" |
ohair@276 | 82 | echo "# ${cline}" |
ohair@276 | 83 | ( eval "${cline}" ) |
ohair@276 | 84 | else |
ohair@276 | 85 | cline="hg $*" |
ohair@276 | 86 | echo "# cd ${i} && ${cline}" |
ohair@276 | 87 | ( cd ${i} && eval "${cline}" ) |
ohair@276 | 88 | fi |
ohair@276 | 89 | echo "# exit code $?" |
ohair@276 | 90 | ) > ${tmp}/repo.${n} 2>&1 ; cat ${tmp}/repo.${n} ) & |
ohair@276 | 91 | if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then |
ohair@276 | 92 | sleep 5 |
ohair@276 | 93 | fi |
ohair@276 | 94 | done |
ohair@276 | 95 | |
ohair@276 | 96 | # Wait for all hg commands to complete |
ohair@276 | 97 | wait |
ohair@276 | 98 | |
ohair@276 | 99 | # Cleanup |
ohair@276 | 100 | rm -f -r ${tmp} |
ohair@276 | 101 | |
ohair@276 | 102 | # Terminate with exit 0 all the time (hard to know when to say "failed") |
ohair@276 | 103 | exit 0 |
ohair@276 | 104 |