3 err
() { printf '%b\n' "$*" 1>&2; exit 1; }
4 vr
() { echo "$@"; "$@"; }
23 acmd
=$
(git config
--get "alias.${cmd}" |
sed 's: -.*::')
31 exec {ctlfd
}<>"${pipe}"
34 jobs_max
=${1:-$(getconf _NPROCESSORS_ONLN)}
36 _mj_child
() { echo ${BASHPID} $? >&${ctlfd} ; }
46 if [[ ${jobs} -eq ${jobs_max} ]] ; then
47 read -r -u ${ctlfd} pid ret
57 while [[ ! -d ${root}/.repo
&& ${root} != "/" ]] ; do
65 for r
in ${*//,/ } ; do
70 ($2 == "chromium.org" || $2 == "google.com") {list = list "," $1}
71 END {print substr(list, 2)}
74 if [[ -z ${owners} ]] ; then
75 err
"cannot find OWNERS list"
77 echo "Auto setting reviewers to: ${owners}"
86 reviewers
=$
(printf '%s,' "${arr[@]}")
87 reviewers
=${reviewers%,}
90 case ${acmd:-${cmd}} in
92 if [[ $1 == "all" ]] ; then
94 if [[ $# -eq 0 ]] ; then
95 eval $
(bash-colors
--env |
sed 's:^:export :')
98 while read -a line
; do
101 if ! cd "${root}/${dir}" ; then
106 out
=$
(env _proj
=${proj} r rb all .
2>&1)
107 if [[ -n ${out} ]] ; then
109 if [[ ${line} == "# "* ]] ; then
111 printf '%s### %s%-40s%s: %s\n' \
112 "${BRACKET}" "${GOOD}" "${line%%:*}" "${NORMAL}" "${line#*:}"
114 printf '%s### %s%-40s%s: ERROR: %s\n' \
115 "${BRACKET}" "${BAD}" "${dir}" "${NORMAL}" "${line}"
117 done < <(echo "${out}")
125 #exec r forall -p -c 'r rb all .' </dev/null
128 branches
=$
(g b |
awk '
130 if ($0 ~ "^[*] *[(]no branch[)]") {
132 } else if ($0 ~ "^[*] *[(](HEAD )?detached (from|at) ") {
134 } else if ($1 == "*") {
140 END { print list b }')
141 [[ -z ${branches} ]] && exit 0
143 [[ -z ${GOOD} ]] && eval $
(bash-colors
--env)
144 #echo "${GOOD}### ${PWD}${NORMAL}"
145 # Skip if rebase is in progress.
146 if [[ -e .git
/rebase-merge
/interactive
]] ; then
147 echo -e "# ${_proj}: ${WARN}skipping due to active rebase${NORMAL}"
150 for b
in ${branches} ; do
151 #echo " ${HILITE}### $b${NORMAL}"
153 if ! r rb
-q "$@" ; then
162 cd "${root}" ||
exit 1
164 while read -a line
; do
169 out
=$
(g clean
"$@" 2>&1)
170 if [[ -n ${out} ]] ; then
186 f|fetch
) sb_cmd
="fetch" ;;
187 *) err
"unknown sandbox command: $1"
193 cd "${root}" ||
exit 1
195 if [[ ! -e .repo
/sandbox-url
]] ; then
196 err
"Please configure remote url base in ${root}/.repo/sandbox-url"
198 remote
=$
(<.repo
/sandbox-url
) ||
exit 1
200 echo "pushing projects from ${root}"
202 # ssh servers do not like it when you hammer them :)
203 # Received disconnect from 74.125.248.80: 7: Too many concurrent connections
204 # fatal: The remote end hung up unexpectedly
208 tcnt
=$
(echo "${rlist}" |
wc -l)
213 export GIT_DIR
=${path}/.git
215 printf '### (%*i/%i %3i%%) %s\n' \
216 ${#tcnt} $((cnt++)) ${tcnt} $(( cnt * 100 / tcnt )) ${proj}
220 g l
-1 ${src} >& /dev
/null || src
=
221 mj_child g push
--force ${remote}/${proj} ${src}:refs/sandbox/${USER}/${sync_branch} >/dev
/null
226 mj_child g fetch
${remote}/${proj} refs/sandbox/${USER}/${sync_branch}:refs/remotes/sb/${sync_branch} >/dev
/null
229 done < <(echo "${rlist}")
235 # For the times when repo is being stupid, push directly to gerrit myself.
236 if ! branch
=$
(g symbolic-ref
-q HEAD
) ; then
237 err
"could not figure out active branch"
239 branch
=${branch#refs/heads/}
240 if ! remote_branch
=$
(g cfg
--get "branch.${branch}.merge") ; then
241 echo "could not figure out remote branch; using ${branch}"
242 remote_branch
=${branch}
244 if ! remote
=$
(g cfg
--get "branch.${branch}.remote") ; then
245 for remote
in cros-internal cros origin
; do
246 g cfg
--get "remote.${remote}.url" >/dev
/null
&& break
249 review
=$
(g cfg
--get "remote.${remote}.review")
250 remote_branch
=${remote_branch#refs/heads/}
254 while [[ $# -gt 0 ]] ; do
257 process_reviewers
"$2"
260 -n|
--dry-run|
--draft)
264 err
"unknown option: $1"
270 ref_spec
="${branch}:refs/for/${remote_branch}"
271 if [[ -n ${reviewers} ]] ; then
272 reviewers
=( ${reviewers//,/ } )
273 if [[ ${review} != ssh://* ]] ; then
274 gob_args
=$
(printf 'r=%s,' "${reviewers[@]}")
275 ref_spec
+="%${gob_args%,}"
277 git_args
+=( "--receive-pack=git receive-pack ${reviewers[*]/#/--reviewer=}" )
281 vr git push
"${git_args[@]}" ${remote} ${ref_spec} && exit
282 err "could not figure out remote to push to
"
289 while [[ $# -gt 0 ]] ; do
292 process_reviewers "$2"
293 args+=( --re "${reviewers}" )
304 email=${1:-${USER}@chromium.org}
306 set -- -c "git cfg user.email
${email}"
310 exec repo ${acmd:-${cmd}} "$@
"