From: Mike Frysinger Date: Sat, 20 Oct 2012 16:09:50 +0000 (-0400) Subject: parallelize rebasing of entire repo X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=1400d2cd095d832224fe5494980fb0d8d01056c2;p=home.git parallelize rebasing of entire repo --- diff --git a/.bin/r b/.bin/r index bbfbce2..e4c8399 100755 --- 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 .' &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 .' "${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 ;;