common/bin/hgforest.sh

changeset 845
3f9873789d44
parent 790
6d7f27953da6
child 902
d832f6171acd
equal deleted inserted replaced
844:fd3b32cc4b6e 845:3f9873789d44
1 #!/bin/sh 1 #!/bin/sh
2 2
3 # 3 #
4 # Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. 4 # Copyright (c) 2009, 2013, 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.
25 25
26 # Shell script for a fast parallel forest command 26 # Shell script for a fast parallel forest command
27 command="$1" 27 command="$1"
28 pull_extra_base="$2" 28 pull_extra_base="$2"
29 29
30 # Python always buffers stdout significantly, thus we will not see any output from hg clone jdk,
31 # until a lot of time has passed! By passing -u to python, we get incremental updates
32 # on stdout. Much nicer.
33 whichhg="`which hg 2> /dev/null | grep -v '^no hg in'`"
34
35 if [ "${whichhg}" = "" ] ; then
36 echo Cannot find hg!
37 exit 1
38 fi
39
40 if [ "" = "$command" ] ; then 30 if [ "" = "$command" ] ; then
41 echo No command to hg supplied! 31 echo No command to hg supplied!
42 exit 1 32 exit 1
43 fi
44
45 has_hash_bang="`head -n 1 "${whichhg}" | cut -b 1-2`"
46 python=""
47 bpython=""
48
49 if [ "#!" = "$has_hash_bang" ] ; then
50 python="`head -n 1 ${whichhg} | cut -b 3- | sed -e 's/^[ \t]*//;s/[ \t]*$//'`"
51 bpython="`basename "$python"`"
52 fi
53
54 if [ -x "$python" -a ! -d "$python" -a "`${python} -V 2>&1 | cut -f 1 -d ' '`" = "Python" ] ; then
55 hg="${python} -u ${whichhg}"
56 else
57 echo Cannot find python from hg launcher. Running plain hg, which probably has buffered stdout.
58 hg="hg"
59 fi 33 fi
60 34
61 # Clean out the temporary directory that stores the pid files. 35 # Clean out the temporary directory that stores the pid files.
62 tmp=/tmp/forest.$$ 36 tmp=/tmp/forest.$$
63 rm -f -r ${tmp} 37 rm -f -r ${tmp}
169 done 143 done
170 ( 144 (
171 ( 145 (
172 if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then 146 if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then
173 pull_newrepo="`echo ${pull_base}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`" 147 pull_newrepo="`echo ${pull_base}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`"
174 echo ${hg} clone ${pull_newrepo} ${i} 148 echo hg clone ${pull_newrepo} ${i}
175 path="`dirname ${i}`" 149 path="`dirname ${i}`"
176 if [ "${path}" != "." ] ; then 150 if [ "${path}" != "." ] ; then
177 times=0 151 times=0
178 while [ ! -d "${path}" ] ## nested repo, ensure containing dir exists 152 while [ ! -d "${path}" ] ## nested repo, ensure containing dir exists
179 do 153 do
182 echo ${path} still not created, waiting... 156 echo ${path} still not created, waiting...
183 fi 157 fi
184 sleep 5 158 sleep 5
185 done 159 done
186 fi 160 fi
187 (${hg} clone ${pull_newrepo} ${i}; echo "$?" > ${tmp}/${repopidfile}.pid.rc )& 161 (PYTHONUNBUFFERED=true hg clone ${pull_newrepo} ${i}; echo "$?" > ${tmp}/${repopidfile}.pid.rc )&
188 else 162 else
189 echo "cd ${i} && ${hg} $*" 163 echo "cd ${i} && hg $*"
190 cd ${i} && (${hg} "$@"; echo "$?" > ${tmp}/${repopidfile}.pid.rc )& 164 cd ${i} && (PYTHONUNBUFFERED=true hg "$@"; echo "$?" > ${tmp}/${repopidfile}.pid.rc )&
191 fi 165 fi
192 echo $! > ${tmp}/${repopidfile}.pid 166 echo $! > ${tmp}/${repopidfile}.pid
193 ) 2>&1 | sed -e "s@^@${reponame}: @") & 167 ) 2>&1 | sed -e "s@^@${reponame}: @") &
194 168
195 if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then 169 if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then

mercurial