48 49 if [ "#!" = "$has_hash_bang" ] ; then 50 python="`head -n 1 ${whichhg} | cut -b 3-`" 51 bpython="`basename "$python"`" 52 fi 53 54 if [ "python" = "$bpython" -a -x "$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 60 61 # Clean out the temporary directory that stores the pid files. 62 tmp=/tmp/forest.$$ 63 rm -f -r ${tmp} 64 mkdir -p ${tmp} 65 66 safe_interrupt () { 67 if [ -d ${tmp} ]; then 68 if [ "`ls ${tmp}`" != "" ]; then 69 echo "Waiting for processes ( `cat ${tmp}/* | tr '\n' ' '`) to terminate nicely!" 70 sleep 1 71 # Pipe stderr to dev/null to silence kill, that complains when trying to kill 72 # a subprocess that has already exited. 73 kill -TERM `cat ${tmp}/* | tr '\n' ' '` 2> /dev/null 74 wait 75 echo Interrupt complete! 76 fi 77 fi 78 rm -f -r ${tmp} 79 exit 1 80 } 81 82 nice_exit () { 83 if [ -d ${tmp} ]; then 84 if [ "`ls ${tmp}`" != "" ]; then 85 wait 86 fi 87 fi 88 rm -f -r ${tmp} 89 } 90 91 trap 'safe_interrupt' INT QUIT 92 trap 'nice_exit' EXIT 93 155 echo "# Repositories: ${repos} ${repos_extra}" 156 echo 157 158 # Run the supplied command on all repos in parallel. 159 n=0 160 for i in ${repos} ${repos_extra} ; do 161 n=`expr ${n} '+' 1` 162 repopidfile=`echo ${i} | sed -e 's@./@@' -e 's@/@_@g'` 163 reponame=`echo ${i} | sed -e :a -e 's/^.\{1,20\}$/ &/;ta'` 164 pull_base="${pull_default}" 165 for j in $repos_extra ; do 166 if [ "$i" = "$j" ] ; then 167 pull_base="${pull_extra}" 168 fi 169 done 170 ( 171 ( 172 if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then 173 pull_newrepo="`echo ${pull_base}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`" 174 echo ${hg} clone ${pull_newrepo} ${i} 175 ${hg} clone ${pull_newrepo} ${i} & 176 else 177 echo "cd ${i} && ${hg} $*" 178 cd ${i} && ${hg} "$@" & 179 fi 180 echo $! > ${tmp}/${repopidfile}.pid 181 ) 2>&1 | sed -e "s@^@${reponame}: @") & 182 183 if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then 184 sleep 2 185 echo Waiting 5 secs before spawning next background command. 186 sleep 3 187 fi 188 done 189 # Wait for all hg commands to complete 190 wait 191 192 # Terminate with exit 0 all the time (hard to know when to say "failed") 193 exit 0 194 | 48 49 if [ "#!" = "$has_hash_bang" ] ; then 50 python="`head -n 1 ${whichhg} | cut -b 3-`" 51 bpython="`basename "$python"`" 52 fi 53 54 if [ "python" = "$bpython" -a -x "$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 60 61 # Clean out the temporary directory that stores the pid files. 62 tmp=/tmp/forest.$$ 63 rm -f -r ${tmp} 64 mkdir -p ${tmp} 65 66 safe_interrupt () { 67 if [ -d ${tmp} ]; then 68 if [ "`ls ${tmp}/*.pid`" != "" ]; then 69 echo "Waiting for processes ( `cat ${tmp}/*.pid | tr '\n' ' '`) to terminate nicely!" 70 sleep 1 71 # Pipe stderr to dev/null to silence kill, that complains when trying to kill 72 # a subprocess that has already exited. 73 kill -TERM `cat ${tmp}/*.pid | tr '\n' ' '` 2> /dev/null 74 wait 75 echo Interrupt complete! 76 fi 77 fi 78 rm -f -r ${tmp} 79 exit 1 80 } 81 82 nice_exit () { 83 if [ -d ${tmp} ]; then 84 if [ "`ls ${tmp}`" != "" ]; then 85 wait 86 fi 87 fi 88 rm -f -r ${tmp} 89 } 90 91 trap 'safe_interrupt' INT QUIT 92 trap 'nice_exit' EXIT 93 155 echo "# Repositories: ${repos} ${repos_extra}" 156 echo 157 158 # Run the supplied command on all repos in parallel. 159 n=0 160 for i in ${repos} ${repos_extra} ; do 161 n=`expr ${n} '+' 1` 162 repopidfile=`echo ${i} | sed -e 's@./@@' -e 's@/@_@g'` 163 reponame=`echo ${i} | sed -e :a -e 's/^.\{1,20\}$/ &/;ta'` 164 pull_base="${pull_default}" 165 for j in $repos_extra ; do 166 if [ "$i" = "$j" ] ; then 167 pull_base="${pull_extra}" 168 fi 169 done 170 ( 171 ( 172 if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then 173 pull_newrepo="`echo ${pull_base}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`" 174 echo ${hg} clone ${pull_newrepo} ${i} 175 path="`dirname ${i}`" 176 if [ "${path}" != "." ] ; then 177 times=0 178 while [ ! -d "${path}" ] ## nested repo, ensure containing dir exists 179 do 180 times=`expr ${times} '+' 1` 181 if [ `expr ${times} '%' 10` -eq 0 ] ; then 182 echo ${path} still no created, waiting... 183 fi 184 sleep 5 185 done 186 fi 187 (${hg} clone ${pull_newrepo} ${i}; echo "$?" > ${tmp}/${repopidfile}.pid.rc )& 188 else 189 echo "cd ${i} && ${hg} $*" 190 cd ${i} && (${hg} "$@"; echo "$?" > ${tmp}/${repopidfile}.pid.rc )& 191 fi 192 echo $! > ${tmp}/${repopidfile}.pid 193 ) 2>&1 | sed -e "s@^@${reponame}: @") & 194 195 if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then 196 sleep 2 197 echo Waiting 5 secs before spawning next background command. 198 sleep 3 199 fi 200 done 201 # Wait for all hg commands to complete 202 wait 203 204 # Terminate with exit 0 only if all subprocesses were successful 205 ec=0 206 if [ -d ${tmp} ]; then 207 for rc in `ls ${tmp}/*.pid.rc` ; do 208 exit_code=`cat ${rc} | tr -d ' \n\r'` 209 if [ "${exit_code}" != "0" ] ; then 210 echo "WARNING: ${rc} exited abnormally." 211 ec=1 212 fi 213 done 214 fi 215 exit ${ec} |