62 tmp=/tmp/forest.$$ |
62 tmp=/tmp/forest.$$ |
63 rm -f -r ${tmp} |
63 rm -f -r ${tmp} |
64 mkdir -p ${tmp} |
64 mkdir -p ${tmp} |
65 |
65 |
66 safe_interrupt () { |
66 safe_interrupt () { |
67 if [ -d ${tmp} ]; then |
67 if [ -d ${tmp} ]; then |
68 if [ "`ls ${tmp}`" != "" ]; then |
68 if [ "`ls ${tmp}/*.pid`" != "" ]; then |
69 echo "Waiting for processes ( `cat ${tmp}/* | tr '\n' ' '`) to terminate nicely!" |
69 echo "Waiting for processes ( `cat ${tmp}/*.pid | tr '\n' ' '`) to terminate nicely!" |
70 sleep 1 |
70 sleep 1 |
71 # Pipe stderr to dev/null to silence kill, that complains when trying to kill |
71 # Pipe stderr to dev/null to silence kill, that complains when trying to kill |
72 # a subprocess that has already exited. |
72 # a subprocess that has already exited. |
73 kill -TERM `cat ${tmp}/* | tr '\n' ' '` 2> /dev/null |
73 kill -TERM `cat ${tmp}/*.pid | tr '\n' ' '` 2> /dev/null |
74 wait |
74 wait |
75 echo Interrupt complete! |
75 echo Interrupt complete! |
76 fi |
76 fi |
77 fi |
77 fi |
78 rm -f -r ${tmp} |
78 rm -f -r ${tmp} |
79 exit 1 |
79 exit 1 |
80 } |
80 } |
81 |
81 |
82 nice_exit () { |
82 nice_exit () { |
83 if [ -d ${tmp} ]; then |
83 if [ -d ${tmp} ]; then |
84 if [ "`ls ${tmp}`" != "" ]; then |
84 if [ "`ls ${tmp}`" != "" ]; then |
85 wait |
85 wait |
86 fi |
86 fi |
87 fi |
87 fi |
88 rm -f -r ${tmp} |
88 rm -f -r ${tmp} |
89 } |
89 } |
90 |
90 |
91 trap 'safe_interrupt' INT QUIT |
91 trap 'safe_interrupt' INT QUIT |
92 trap 'nice_exit' EXIT |
92 trap 'nice_exit' EXIT |
93 |
93 |
94 # Only look in specific locations for possible forests (avoids long searches) |
94 # Only look in specific locations for possible forests (avoids long searches) |
95 pull_default="" |
95 pull_default="" |
96 repos="" |
96 repos="" |
97 repos_extra="" |
97 repos_extra="" |
98 if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then |
98 if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then |
170 ( |
170 ( |
171 ( |
171 ( |
172 if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then |
172 if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then |
173 pull_newrepo="`echo ${pull_base}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`" |
173 pull_newrepo="`echo ${pull_base}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`" |
174 echo ${hg} clone ${pull_newrepo} ${i} |
174 echo ${hg} clone ${pull_newrepo} ${i} |
175 ${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 not created, waiting... |
|
183 fi |
|
184 sleep 5 |
|
185 done |
|
186 fi |
|
187 (${hg} clone ${pull_newrepo} ${i}; echo "$?" > ${tmp}/${repopidfile}.pid.rc )& |
176 else |
188 else |
177 echo "cd ${i} && ${hg} $*" |
189 echo "cd ${i} && ${hg} $*" |
178 cd ${i} && ${hg} "$@" & |
190 cd ${i} && (${hg} "$@"; echo "$?" > ${tmp}/${repopidfile}.pid.rc )& |
179 fi |
191 fi |
180 echo $! > ${tmp}/${repopidfile}.pid |
192 echo $! > ${tmp}/${repopidfile}.pid |
181 ) 2>&1 | sed -e "s@^@${reponame}: @") & |
193 ) 2>&1 | sed -e "s@^@${reponame}: @") & |
182 |
194 |
183 if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then |
195 if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then |
184 sleep 2 |
196 sleep 2 |
185 echo Waiting 5 secs before spawning next background command. |
197 echo Waiting 5 secs before spawning next background command. |
186 sleep 3 |
198 sleep 3 |
187 fi |
199 fi |
188 done |
200 done |
189 # Wait for all hg commands to complete |
201 # Wait for all hg commands to complete |
190 wait |
202 wait |
191 |
203 |
192 # Terminate with exit 0 all the time (hard to know when to say "failed") |
204 # Terminate with exit 0 only if all subprocesses were successful |
193 exit 0 |
205 ec=0 |
194 |
206 if [ -d ${tmp} ]; then |
|
207 for rc in ${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} |