]> git.wh0rd.org - home.git/commitdiff
improve parallel behavior
authorMike Frysinger <vapier@gentoo.org>
Sat, 9 Jun 2012 02:53:58 +0000 (22:53 -0400)
committerMike Frysinger <vapier@gentoo.org>
Sat, 9 Jun 2012 02:58:43 +0000 (22:58 -0400)
.bin/r

diff --git a/.bin/r b/.bin/r
index 6771348c705bcf90d1fb944f63b467d7282dbe02..d204eb1186964c89a57f577cc7c1a5dccc1ce76a 100755 (executable)
--- a/.bin/r
+++ b/.bin/r
@@ -20,7 +20,7 @@ rebase)
        if [[ $1 == "all" ]] ; then
                shift
                if [[ $# -eq 0 ]] ; then
-                       exec r forall -c 'r rb all .'
+                       exec r forall -p -c 'r rb all .'
                fi
 
                branches=$(g b | awk '
@@ -37,7 +37,7 @@ rebase)
                [[ -z ${branches} ]] && exit 0
 
                eval $(bash-colors --env)
-               echo "${GOOD}### ${PWD}${NORMAL}"
+               #echo "${GOOD}### ${PWD}${NORMAL}"
                for b in ${branches} ; do
                        echo " ${HILITE}### $b${NORMAL}"
                        g co -q $b || exit 1
@@ -64,7 +64,13 @@ sb-push)
 
        echo "pushing projects from ${root}"
 
-       pids=()
+       pipe=$(mktemp)
+       rm -f "${pipe}"
+       mkfifo "${pipe}"
+       exec {ctlfd}<>"${pipe}"
+       rm -f "${pipe}"
+       jobs=0
+
        rlist=$(r list)
        tcnt=$(echo "${rlist}" | wc -l)
        cnt=1
@@ -77,17 +83,20 @@ sb-push)
                        ${#tcnt} $((cnt++)) ${tcnt} $(( cnt * 100 / tcnt )) ${proj}
                src="${sync_branch}"
                g l -1 ${src} >& /dev/null || src=
-               ( g push --force ${remote}/${proj} ${src}:refs/sandbox/${USER}/${sync_branch} >/dev/null ) &
+               (
+               g push --force ${remote}/${proj} ${src}:refs/sandbox/${USER}/${sync_branch} >/dev/null
+               echo ${BASHPID} $? >&${ctlfd}
+               ) &
 
                # ssh servers do not like it when you hammer them :)
                #       Received disconnect from 74.125.248.80: 7: Too many concurrent connections
                #       fatal: The remote end hung up unexpectedly
-               pids+=( $! )
-               if [[ ${#pids[@]} -eq 20 ]] ; then
-                       wait ${pids[@]:0:3}
-                       pids=( ${pids[@]:3} )
+               : $(( ++jobs ))
+               if [[ ${jobs} -eq 16 ]] ; then
+                       read -r -u ${ctlfd} pid ret
+                       : $(( --jobs ))
                fi
-       done <<<"$(r list)"
+       done < <(r list)
        wait
 
        exit 0