#!/bin/bash g() { git "$@"; } err() { printf '%b\n' "$*" 1>&2; exit 1; } vr() { echo "$@"; "$@"; } case $1 in ""|-*) ;; l) cmd=list shift ;; s) cmd=sync shift ;; *) cmd=$1 shift acmd=$(git config --get "alias.${cmd}" | sed 's: -.*::') ;; esac case ${acmd:-${cmd}} in rebase) if [[ $1 == "all" ]] ; then shift if [[ $# -eq 0 ]] ; then exec r forall -p -c 'r rb all .' "${pipe}" rm -f "${pipe}" jobs=0 rlist=$(r list) tcnt=$(echo "${rlist}" | wc -l) cnt=1 while read line ; do line=( ${line} ) path=${line[0]} export GIT_DIR=${path}/.git proj=${line[2]} printf '### (%*i/%i %3i%%) %s\n' \ ${#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 done < <(r list) wait exit 0 ;; g-push) # For the times when repo is being stupid, push directly to gerrit myself. if ! branch=$(g symbolic-ref -q HEAD) ; then err "could not figure out active branch" fi branch=${branch#refs/heads/} if ! remote_branch=$(g cfg --get "branch.${branch}.merge") ; then err "could not figure out remote branch" fi remote_branch=${remote_branch#refs/heads/} for remote in cros-internal cros origin ; do if g cfg --get "remote.${remote}.url" >/dev/null ; then vr git push ${remote} ${branch}:refs/for/${remote_branch} exit $? fi done err "could not figure out remote to push to" ;; sync) [[ $# -eq 0 ]] && set -- -j16 ;; upload) args=() while [[ $# -gt 0 ]] ; do case $1 in --re) if [[ $2 == *"OWNERS" ]] ; then owners=$(awk -F'@' '{list = list "," $1} END {print substr(list, 2)}' "$2") if [[ -z ${owners} ]] ; then err "cannot find OWNERS list" else echo "Auto setting reviewers to: ${owners}" fi args+=( --re "${owners}" ) shift 2 continue fi ;; esac args+=( "$1" ) shift done set -- "${args[@]}" ;; esac exec repo ${acmd:-${cmd}} "$@"