make/scripts/hgforest.sh

changeset 436
955a3e8ed4f0
parent 276
dc9eb519c6ed
child 437
8a4e92c10a9a
equal deleted inserted replaced
434:d939bd0ab13c 436:955a3e8ed4f0
1 #!/bin/sh 1 #!/bin/sh
2 2
3 # 3 #
4 # Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 4 # Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 # 6 #
7 # This code is free software; you can redistribute it and/or modify it 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 8 # under the terms of the GNU General Public License version 2 only, as
9 # published by the Free Software Foundation. 9 # published by the Free Software Foundation.
22 # or visit www.oracle.com if you need additional information or have any 22 # or visit www.oracle.com if you need additional information or have any
23 # questions. 23 # questions.
24 # 24 #
25 25
26 # Shell script for a fast parallel forest command 26 # Shell script for a fast parallel forest command
27 command="$1"
28 pull_extra_base="$2"
27 29
28 tmp=/tmp/forest.$$ 30 tmp=/tmp/forest.$$
29 rm -f -r ${tmp} 31 rm -f -r ${tmp}
30 mkdir -p ${tmp} 32 mkdir -p ${tmp}
31 33
33 trap 'rm -f -r ${tmp}' KILL 35 trap 'rm -f -r ${tmp}' KILL
34 trap 'rm -f -r ${tmp}' EXIT 36 trap 'rm -f -r ${tmp}' EXIT
35 37
36 # Only look in specific locations for possible forests (avoids long searches) 38 # Only look in specific locations for possible forests (avoids long searches)
37 pull_default="" 39 pull_default=""
38 if [ "$1" = "clone" -o "$1" = "fclone" ] ; then 40 repos=""
41 repos_extra=""
42 if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then
39 subrepos="corba jaxp jaxws langtools jdk hotspot" 43 subrepos="corba jaxp jaxws langtools jdk hotspot"
40 if [ -f .hg/hgrc ] ; then 44 if [ -f .hg/hgrc ] ; then
41 pull_default=`hg paths default` 45 pull_default=`hg paths default`
46 if [ "${pull_default}" = "" ] ; then
47 echo "ERROR: Need initial clone with 'hg paths default' defined"
48 exit 1
49 fi
42 fi 50 fi
43 if [ "${pull_default}" = "" ] ; then 51 if [ "${pull_default}" = "" ] ; then
44 echo "ERROR: Need initial clone with 'hg paths default' defined" 52 echo "ERROR: Need initial repository to use this script"
45 exit 1 53 exit 1
46 fi 54 fi
47 repos=""
48 for i in ${subrepos} ; do 55 for i in ${subrepos} ; do
49 if [ ! -f ${i}/.hg/hgrc ] ; then 56 if [ ! -f ${i}/.hg/hgrc ] ; then
50 repos="${repos} ${i}" 57 repos="${repos} ${i}"
51 fi 58 fi
52 done 59 done
60 if [ "${pull_extra_base}" != "" ] ; then
61 subrepos_extra="jdk/src/closed jdk/make/closed jdk/test/closed hotspot/src/closed hotspot/test/closed deploy install sponsors pubs"
62 pull_default_base=`echo ${pull_default} | sed -e 's@\(^.*://[^/]*\)/.*@\1@'`
63 pull_extra=`echo ${pull_default} | sed -e "s@${pull_default_base}@${pull_extra_base}@"`
64 for i in ${subrepos_extra} ; do
65 if [ ! -f ${i}/.hg/hgrc ] ; then
66 repos_extra="${repos_extra} ${i}"
67 fi
68 done
69 fi
53 at_a_time=2 70 at_a_time=2
71 # Any repos to deal with?
72 if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then
73 echo "No repositories to clone."
74 exit
75 fi
54 else 76 else
55 hgdirs=`ls -d ./.hg ./*/.hg ./*/*/.hg ./*/*/*/.hg ./*/*/*/*/.hg 2>/dev/null` 77 hgdirs=`ls -d ./.hg ./*/.hg ./*/*/.hg ./*/*/*/.hg ./*/*/*/*/.hg 2>/dev/null`
56 # Derive repository names from the .hg directory locations 78 # Derive repository names from the .hg directory locations
57 repos=""
58 for i in ${hgdirs} ; do 79 for i in ${hgdirs} ; do
59 repos="${repos} `echo ${i} | sed -e 's@/.hg$@@'`" 80 repos="${repos} `echo ${i} | sed -e 's@/.hg$@@'`"
60 done 81 done
61 at_a_time=8 82 at_a_time=8
83 # Any repos to deal with?
84 if [ "${repos}" = "" ] ; then
85 echo "No repositories to process."
86 exit
87 fi
62 fi 88 fi
63 89
64 # Any repos to deal with? 90 # Echo out what repositories we will clone
65 if [ "${repos}" = "" ] ; then 91 echo "# Repos: ${repos} ${repos_extra}"
66 echo "No repositories to process."
67 exit
68 fi
69
70 # Echo out what repositories we will process
71 echo "# Repos: ${repos}"
72 92
73 # Run the supplied command on all repos in parallel, save output until end 93 # Run the supplied command on all repos in parallel, save output until end
74 n=0 94 n=0
75 for i in ${repos} ; do 95 for i in ${repos} ; do
76 echo "Starting on ${i}" 96 echo "Starting on ${i}"
77 n=`expr ${n} '+' 1` 97 n=`expr ${n} '+' 1`
78 ( 98 (
79 ( 99 (
80 if [ "$1" = "clone" -o "$1" = "fclone" ] ; then 100 if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then
81 cline="hg $* ${pull_default}/${i} ${i}" 101 cline="hg clone ${pull_default}/${i} ${i}"
82 echo "# ${cline}" 102 echo "# ${cline}"
83 ( eval "${cline}" ) 103 ( eval "${cline}" )
84 else 104 else
85 cline="hg $*" 105 cline="hg $*"
86 echo "# cd ${i} && ${cline}" 106 echo "# cd ${i} && ${cline}"
90 ) > ${tmp}/repo.${n} 2>&1 ; cat ${tmp}/repo.${n} ) & 110 ) > ${tmp}/repo.${n} 2>&1 ; cat ${tmp}/repo.${n} ) &
91 if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then 111 if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then
92 sleep 5 112 sleep 5
93 fi 113 fi
94 done 114 done
115 if [ "${repos_extra}" != "" ] ; then
116 for i in ${repos_extra} ; do
117 echo "Starting on ${i}"
118 n=`expr ${n} '+' 1`
119 (
120 (
121 cline="hg clone ${pull_extra}/${i} ${i}"
122 echo "# ${cline}"
123 ( eval "${cline}" )
124 echo "# exit code $?"
125 ) > ${tmp}/repo.${n} 2>&1 ; cat ${tmp}/repo.${n} ) &
126 if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then
127 sleep 5
128 fi
129 done
130 fi
95 131
96 # Wait for all hg commands to complete 132 # Wait for all hg commands to complete
97 wait 133 wait
98 134
99 # Cleanup 135 # Cleanup

mercurial