3 err() { printf '%b\n' "$*" 1>&2; exit 1; }
4 vr() { echo "$@"; "$@"; }
19 acmd=$(git config --get "alias.${cmd}" | sed 's: -.*::')
27 exec {ctlfd}<>"${pipe}"
30 jobs_max=${1:-$(getconf _NPROCESSORS_ONLN)}
32 _mj_child() { echo ${BASHPID} $? >&${ctlfd} ; }
42 if [[ ${jobs} -eq ${jobs_max} ]] ; then
43 read -r -u ${ctlfd} pid ret
53 while [[ ! -d ${root}/.repo && ${root} != "/" ]] ; do
61 for r in ${*//,/ } ; do
66 ($2 == "chromium.org" || $2 == "google.com") {list = list "," $1}
67 END {print substr(list, 2)}
70 if [[ -z ${owners} ]] ; then
71 err "cannot find OWNERS list"
73 echo "Auto setting reviewers to: ${owners}"
82 reviewers=$(printf '%s,' "${arr[@]}")
83 reviewers=${reviewers%,}
86 case ${acmd:-${cmd}} in
88 if [[ $1 == "all" ]] ; then
90 if [[ $# -eq 0 ]] ; then
91 eval $(bash-colors --env | sed 's:^:export :')
94 while read -a line ; do
99 out=$(env _proj=${proj} r rb all . 2>&1)
100 if [[ -n ${out} ]] ; then
102 if [[ ${line} == "# "* ]] ; then
104 printf '%s### %s%-40s%s: %s\n' \
105 "${BRACKET}" "${GOOD}" "${line%%:*}" "${NORMAL}" "${line#*:}"
109 done < <(echo "${out}")
117 #exec r forall -p -c 'r rb all .' </dev/null
120 branches=$(g b | awk '
122 if ($0 ~ "^[*] *[(]no branch[)]") {
124 } else if ($0 ~ "^[*] *[(]detached from ") {
126 } else if ($1 == "*") {
132 END { print list b }')
133 [[ -z ${branches} ]] && exit 0
135 [[ -z ${GOOD} ]] && eval $(bash-colors --env)
136 #echo "${GOOD}### ${PWD}${NORMAL}"
137 # Skip if rebase is in progress.
138 if [[ -e .git/rebase-merge/interactive ]] ; then
139 echo -e "# ${_proj}: ${WARN}skipping due to active rebase${NORMAL}"
142 for b in ${branches} ; do
143 #echo " ${HILITE}### $b${NORMAL}"
145 if ! r rb -q "$@" ; then
154 cd "${root}" || exit 1
156 while read -a line ; do
161 out=$(g clean "$@" 2>&1)
162 if [[ -n ${out} ]] ; then
178 f|fetch) sb_cmd="fetch" ;;
179 *) err "unknown sandbox command: $1"
185 cd "${root}" || exit 1
187 if [[ ! -e .repo/sandbox-url ]] ; then
188 err "Please configure remote url base in ${root}/.repo/sandbox-url"
190 remote=$(<.repo/sandbox-url) || exit 1
192 echo "pushing projects from ${root}"
194 # ssh servers do not like it when you hammer them :)
195 # Received disconnect from 74.125.248.80: 7: Too many concurrent connections
196 # fatal: The remote end hung up unexpectedly
200 tcnt=$(echo "${rlist}" | wc -l)
205 export GIT_DIR=${path}/.git
207 printf '### (%*i/%i %3i%%) %s\n' \
208 ${#tcnt} $((cnt++)) ${tcnt} $(( cnt * 100 / tcnt )) ${proj}
212 g l -1 ${src} >& /dev/null || src=
213 mj_child g push --force ${remote}/${proj} ${src}:refs/sandbox/${USER}/${sync_branch} >/dev/null
218 mj_child g fetch ${remote}/${proj} refs/sandbox/${USER}/${sync_branch}:refs/remotes/sb/${sync_branch} >/dev/null
221 done < <(echo "${rlist}")
227 # For the times when repo is being stupid, push directly to gerrit myself.
228 if ! branch=$(g symbolic-ref -q HEAD) ; then
229 err "could not figure out active branch"
231 branch=${branch#refs/heads/}
232 if ! remote_branch=$(g cfg --get "branch.${branch}.merge") ; then
233 echo "could not figure out remote branch; using ${branch}"
234 remote_branch=${branch}
236 if ! remote=$(g cfg --get "branch.${branch}.remote") ; then
237 for remote in cros-internal cros origin ; do
238 g cfg --get "remote.${remote}.url" >/dev/null && break
241 review=$(g cfg --get "remote.${remote}.review")
242 remote_branch=${remote_branch#refs/heads/}
246 while [[ $# -gt 0 ]] ; do
249 process_reviewers "$2"
252 -n|--dry-run|--draft)
256 err "unknown option: $1"
262 ref_spec="${branch}:refs/for/${remote_branch}"
263 if [[ -n ${reviewers} ]] ; then
264 reviewers=( ${reviewers//,/ } )
265 if [[ ${review} != ssh://* ]] ; then
266 gob_args=$(printf 'r=%s,' "${reviewers[@]}")
267 ref_spec+="%${gob_args%,}"
269 git_args+=( "--receive-pack=git receive-pack ${reviewers[*]/#/--reviewer=}" )
273 vr git push "${git_args[@]}" ${remote} ${ref_spec} && exit
274 err "could not figure out remote to push to"
281 while [[ $# -gt 0 ]] ; do
284 process_reviewers "$2"
285 args+=( --re "${reviewers}" )
296 email=${1:-${USER}@chromium.org}
298 set -- -c "git cfg user.email ${email}"
302 exec repo ${acmd:-${cmd}} "$@"