提交 3f380d13 编写于 作者: C chegar

8007625: race with nested repos in /common/bin/hgforest.sh

Reviewed-by: dholmes, ohair, ohrstrom
上级 3f0b33d5
...@@ -64,33 +64,33 @@ rm -f -r ${tmp} ...@@ -64,33 +64,33 @@ rm -f -r ${tmp}
mkdir -p ${tmp} mkdir -p ${tmp}
safe_interrupt () { safe_interrupt () {
if [ -d ${tmp} ]; then if [ -d ${tmp} ]; then
if [ "`ls ${tmp}`" != "" ]; then if [ "`ls ${tmp}/*.pid`" != "" ]; then
echo "Waiting for processes ( `cat ${tmp}/* | tr '\n' ' '`) to terminate nicely!" echo "Waiting for processes ( `cat ${tmp}/*.pid | tr '\n' ' '`) to terminate nicely!"
sleep 1 sleep 1
# Pipe stderr to dev/null to silence kill, that complains when trying to kill # Pipe stderr to dev/null to silence kill, that complains when trying to kill
# a subprocess that has already exited. # a subprocess that has already exited.
kill -TERM `cat ${tmp}/* | tr '\n' ' '` 2> /dev/null kill -TERM `cat ${tmp}/*.pid | tr '\n' ' '` 2> /dev/null
wait wait
echo Interrupt complete! echo Interrupt complete!
fi fi
fi fi
rm -f -r ${tmp} rm -f -r ${tmp}
exit 1 exit 1
} }
nice_exit () { nice_exit () {
if [ -d ${tmp} ]; then if [ -d ${tmp} ]; then
if [ "`ls ${tmp}`" != "" ]; then if [ "`ls ${tmp}`" != "" ]; then
wait wait
fi fi
fi fi
rm -f -r ${tmp} rm -f -r ${tmp}
} }
trap 'safe_interrupt' INT QUIT trap 'safe_interrupt' INT QUIT
trap 'nice_exit' EXIT trap 'nice_exit' EXIT
# Only look in specific locations for possible forests (avoids long searches) # Only look in specific locations for possible forests (avoids long searches)
pull_default="" pull_default=""
repos="" repos=""
...@@ -172,14 +172,26 @@ for i in ${repos} ${repos_extra} ; do ...@@ -172,14 +172,26 @@ for i in ${repos} ${repos_extra} ; do
if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then
pull_newrepo="`echo ${pull_base}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`" pull_newrepo="`echo ${pull_base}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`"
echo ${hg} clone ${pull_newrepo} ${i} echo ${hg} clone ${pull_newrepo} ${i}
${hg} clone ${pull_newrepo} ${i} & path="`dirname ${i}`"
if [ "${path}" != "." ] ; then
times=0
while [ ! -d "${path}" ] ## nested repo, ensure containing dir exists
do
times=`expr ${times} '+' 1`
if [ `expr ${times} '%' 10` -eq 0 ] ; then
echo ${path} still not created, waiting...
fi
sleep 5
done
fi
(${hg} clone ${pull_newrepo} ${i}; echo "$?" > ${tmp}/${repopidfile}.pid.rc )&
else else
echo "cd ${i} && ${hg} $*" echo "cd ${i} && ${hg} $*"
cd ${i} && ${hg} "$@" & cd ${i} && (${hg} "$@"; echo "$?" > ${tmp}/${repopidfile}.pid.rc )&
fi fi
echo $! > ${tmp}/${repopidfile}.pid echo $! > ${tmp}/${repopidfile}.pid
) 2>&1 | sed -e "s@^@${reponame}: @") & ) 2>&1 | sed -e "s@^@${reponame}: @") &
if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then
sleep 2 sleep 2
echo Waiting 5 secs before spawning next background command. echo Waiting 5 secs before spawning next background command.
...@@ -189,6 +201,15 @@ done ...@@ -189,6 +201,15 @@ done
# Wait for all hg commands to complete # Wait for all hg commands to complete
wait wait
# Terminate with exit 0 all the time (hard to know when to say "failed") # Terminate with exit 0 only if all subprocesses were successful
exit 0 ec=0
if [ -d ${tmp} ]; then
for rc in ${tmp}/*.pid.rc ; do
exit_code=`cat ${rc} | tr -d ' \n\r'`
if [ "${exit_code}" != "0" ] ; then
echo "WARNING: ${rc} exited abnormally."
ec=1
fi
done
fi
exit ${ec}
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
# #
# Get clones of all nested repositories # Get clones of all nested repositories
sh ./common/bin/hgforest.sh clone "$@" sh ./common/bin/hgforest.sh clone "$@" || exit 1
# Update all existing repositories to the latest sources # Update all existing repositories to the latest sources
sh ./common/bin/hgforest.sh pull -u sh ./common/bin/hgforest.sh pull -u
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册