]> git.wh0rd.org Git - home.git/commitdiff
parallelize rebasing of entire repo
authorMike Frysinger <vapier@gentoo.org>
Sat, 20 Oct 2012 16:09:50 +0000 (12:09 -0400)
committerMike Frysinger <vapier@gentoo.org>
Sat, 20 Oct 2012 16:09:50 +0000 (12:09 -0400)
.bin/r

diff --git a/.bin/r b/.bin/r
index bbfbce2814d8a73e5e4c504a73b890a6321df6a8..e4c83991a14f9181cc5d9fe00675ae05290889ef 100755 (executable)
--- a/.bin/r
+++ b/.bin/r
@@ -20,12 +20,63 @@ s)
        ;;
 esac
 
+mj_init() {
+       pipe=$(mktemp)
+       rm -f "${pipe}"
+       mkfifo "${pipe}"
+       exec {ctlfd}<>"${pipe}"
+       rm -f "${pipe}"
+       jobs=0
+       jobs_max=${1:-$(getconf _NPROCESSORS_ONLN)}
+}
+_mj_child() { echo ${BASHPID} $? >&${ctlfd} ; }
+mj_child() {
+       (
+       "$@"
+       _mj_child
+       ) &
+       mj_post_child
+}
+mj_post_child() {
+       : $(( ++jobs ))
+       if [[ ${jobs} -eq ${jobs_max} ]] ; then
+               read -r -u ${ctlfd} pid ret
+               : $(( --jobs ))
+       fi
+}
+mj_finish() {
+       wait
+}
+
+repo_root() {
+       local root=${PWD}
+       while [[ ! -d ${root}/.repo && ${root} != "/" ]] ; do
+               root=${root%/*}
+       done
+       echo "${root}"
+}
+
 case ${acmd:-${cmd}} in
 rebase)
        if [[ $1 == "all" ]] ; then
                shift
                if [[ $# -eq 0 ]] ; then
-                       exec r forall -p -c 'r rb all .' </dev/null
+                       root=$(repo_root)
+                       mj_init
+                       while read -a line ; do
+                               dir=${line[0]}
+                               proj=${line[2]}
+                               cd "${root}/${dir}"
+                               (
+                               out=$(r rb all . 2>&1)
+                               [[ -n ${out} ]] && echo "${out}"
+                               _mj_child
+                               ) &
+                               mj_post_child
+                       done < <(r l)
+                       mj_finish
+                       exit 0
+                       #exec r forall -p -c 'r rb all .' </dev/null
                fi
 
                branches=$(g b | awk '
@@ -44,9 +95,9 @@ rebase)
                eval $(bash-colors --env)
                #echo "${GOOD}### ${PWD}${NORMAL}"
                for b in ${branches} ; do
-                       echo " ${HILITE}### $b${NORMAL}"
+                       #echo " ${HILITE}### $b${NORMAL}"
                        g co -q $b || exit 1
-                       if ! r rb "$@" ; then
+                       if ! r rb -q "$@" ; then
                                g rb-a
                        fi
                done
@@ -56,10 +107,7 @@ rebase)
 sb-push)
        sync_branch="v"
 
-       root=${PWD}
-       while [[ ! -d ${root}/.repo && ${root} != "/" ]] ; do
-               root=${root%/*}
-       done
+       root=$(repo_root)
        cd "${root}" || exit 1
 
        if [[ ! -e .repo/sandbox-url ]] ; then
@@ -69,12 +117,10 @@ sb-push)
 
        echo "pushing projects from ${root}"
 
-       pipe=$(mktemp)
-       rm -f "${pipe}"
-       mkfifo "${pipe}"
-       exec {ctlfd}<>"${pipe}"
-       rm -f "${pipe}"
-       jobs=0
+       # 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
+       mj_init 16
 
        rlist=$(r list)
        tcnt=$(echo "${rlist}" | wc -l)
@@ -88,21 +134,9 @@ 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
-               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
-               : $(( ++jobs ))
-               if [[ ${jobs} -eq 16 ]] ; then
-                       read -r -u ${ctlfd} pid ret
-                       : $(( --jobs ))
-               fi
+               mj_child g push --force ${remote}/${proj} ${src}:refs/sandbox/${USER}/${sync_branch} >/dev/null
        done < <(r list)
-       wait
+       mj_finish
 
        exit 0
        ;;