#!/bin/bash g() { git "$@"; } err() { printf '%b\n' "$*" 1>&2; exit 1; } case $1 in ""|-*) ;; l) cmd=list shift ;; *) cmd=$1 shift acmd=$(git config --get "alias.${cmd}") ;; esac case ${acmd:-${cmd}} in rebase) if [[ $1 == "all" ]] ; then shift if [[ $# -eq 0 ]] ; then exec r forall -c 'r rb all .' fi branches=$(g b | awk ' { if ($0 ~ "^[*] *[(]no branch[)]") { next } else if ($1 == "*") { b = $NF } else { list = list $NF " " } } END { print list b }') [[ -z ${branches} ]] && exit 0 eval $(bash-colors --env) echo "${GOOD}### ${PWD}${NORMAL}" for b in ${branches} ; do echo " ${HILITE}### $b${NORMAL}" g co -q $b || exit 1 if ! r rb "$@" ; then g rb-a fi done exit 0 fi ;; sb-push) sync_branch="v" root=${PWD} while [[ ! -d ${root}/.repo && ${root} != "/" ]] ; do root=${root%/*} done cd "${root}" || exit 1 if [[ ! -e .repo/sandbox-url ]] ; then err "Please configure remote url base in ${root}/.repo/sandbox-url" fi remote=$(<.repo/sandbox-url) || exit 1 echo "pushing projects from ${root}" pids=() 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 ) & # 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} ) fi done <<<"$(r list)" wait exit 0 ;; g-push) # For the times when repo is being stupid, push directly to gerrit myself. shift if [[ $# -ne 1 ]] ; then echo "Usage: r g-push " exit 1 fi exec g push cros-internal HEAD:refs/for/master ;; 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}} "$@"