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