75 ;; |
75 ;; |
76 esac |
76 esac |
77 shift |
77 shift |
78 done |
78 done |
79 |
79 |
|
80 # debug mode |
|
81 if [ "${HGFOREST_DEBUG:-false}" = "true" ] ; then |
|
82 global_opts="${global_opts} --debug" |
|
83 fi |
|
84 |
80 # silence standard output? |
85 # silence standard output? |
81 if [ ${qflag} = "true" ] ; then |
86 if [ ${qflag} = "true" ] ; then |
82 global_opts="${global_opts} -q" |
87 global_opts="${global_opts} -q" |
83 status_output="/dev/null" |
88 status_output="/dev/null" |
84 fi |
89 fi |
87 if [ ${vflag} = "true" ] ; then |
92 if [ ${vflag} = "true" ] ; then |
88 global_opts="${global_opts} -v" |
93 global_opts="${global_opts} -v" |
89 fi |
94 fi |
90 |
95 |
91 # Make sure we have a command. |
96 # Make sure we have a command. |
92 if [ $# -lt 1 -o -z "${1:-}" ] ; then |
97 if [ ${#} -lt 1 -o -z "${1:-}" ] ; then |
93 echo "ERROR: No command to hg supplied!" |
98 echo "ERROR: No command to hg supplied!" > ${status_output} |
94 usage |
99 usage > ${status_output} |
95 fi |
100 fi |
96 |
101 |
97 command="$1"; shift |
102 # grab command |
|
103 command="${1}"; shift |
|
104 |
|
105 if [ ${vflag} = "true" ] ; then |
|
106 echo "# Mercurial command: ${command}" > ${status_output} |
|
107 fi |
|
108 |
|
109 |
|
110 # capture command options and arguments (if any) |
98 command_args="${@:-}" |
111 command_args="${@:-}" |
|
112 |
|
113 if [ ${vflag} = "true" ] ; then |
|
114 echo "# Mercurial command arguments: ${command_args}" > ${status_output} |
|
115 fi |
99 |
116 |
100 # Clean out the temporary directory that stores the pid files. |
117 # Clean out the temporary directory that stores the pid files. |
101 tmp=/tmp/forest.$$ |
118 tmp=/tmp/forest.$$ |
102 rm -f -r ${tmp} |
119 rm -f -r ${tmp} |
103 mkdir -p ${tmp} |
120 mkdir -p ${tmp} |
104 |
121 |
105 |
122 |
106 if [ "${HGFOREST_DEBUG:-false}" = "true" ] ; then |
123 if [ "${HGFOREST_DEBUG:-false}" = "true" ] ; then |
107 echo "DEBUG: temp files are in: ${tmp}" |
124 # ignores redirection. |
|
125 echo "DEBUG: temp files are in: ${tmp}" >&2 |
108 fi |
126 fi |
109 |
127 |
110 # Check if we can use fifos for monitoring sub-process completion. |
128 # Check if we can use fifos for monitoring sub-process completion. |
111 echo "1" > ${tmp}/read |
129 echo "1" > ${tmp}/read |
112 while_subshell=1 |
130 while_subshell=1 |
375 completed="`(ls -a1 ${tmp}/*.pid.rc 2> /dev/null | wc -l) || echo 0`" |
393 completed="`(ls -a1 ${tmp}/*.pid.rc 2> /dev/null | wc -l) || echo 0`" |
376 done |
394 done |
377 fi |
395 fi |
378 fi |
396 fi |
379 done |
397 done |
|
398 |
|
399 if [ ${have_fifos} = "true" ]; then |
|
400 # done with the fifo |
|
401 exec 3>&- |
|
402 fi |
380 fi |
403 fi |
381 |
404 |
382 # Wait for all subprocesses to complete |
405 # Wait for all subprocesses to complete |
383 wait |
406 wait |
384 |
407 |
385 # Terminate with exit 0 only if all subprocesses were successful |
408 # Terminate with exit 0 only if all subprocesses were successful |
|
409 # Terminate with highest exit code of subprocesses |
386 ec=0 |
410 ec=0 |
387 if [ -d ${tmp} ]; then |
411 if [ -d ${tmp} ]; then |
388 rcfiles="`(ls -a ${tmp}/*.pid.rc 2> /dev/null) || echo ''`" |
412 rcfiles="`(ls -a ${tmp}/*.pid.rc 2> /dev/null) || echo ''`" |
389 for rc in ${rcfiles} ; do |
413 for rc in ${rcfiles} ; do |
390 exit_code=`cat ${rc} | tr -d ' \n\r'` |
414 exit_code=`cat ${rc} | tr -d ' \n\r'` |
391 if [ "${exit_code}" != "0" ] ; then |
415 if [ "${exit_code}" != "0" ] ; then |
|
416 if [ ${exit_code} -gt 1 ]; then |
|
417 # mercurial exit codes greater than "1" signal errors. |
392 repo="`echo ${rc} | sed -e 's@^'${tmp}'@@' -e 's@/*\([^/]*\)\.pid\.rc$@\1@' -e 's@_@/@g'`" |
418 repo="`echo ${rc} | sed -e 's@^'${tmp}'@@' -e 's@/*\([^/]*\)\.pid\.rc$@\1@' -e 's@_@/@g'`" |
393 echo "WARNING: ${repo} exited abnormally (${exit_code})" > ${status_output} |
419 echo "WARNING: ${repo} exited abnormally (${exit_code})" > ${status_output} |
394 ec=1 |
420 fi |
|
421 if [ ${exit_code} -gt ${ec} ]; then |
|
422 # assume that larger exit codes are more significant |
|
423 ec=${exit_code} |
|
424 fi |
395 fi |
425 fi |
396 done |
426 done |
397 fi |
427 fi |
398 exit ${ec} |
428 exit ${ec} |