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
64 local owners
=$
(awk -F'@' '{list = list "," $1} END {print substr(list, 2)}' "${r}")
65 if [[ -z ${owners} ]] ; then
66 err
"cannot find OWNERS list"
68 echo "Auto setting reviewers to: ${owners}"
77 reviewers
=$
(printf '%s,' "${arr[@]}")
78 reviewers
=${reviewers%,}
81 case ${acmd:-${cmd}} in
83 if [[ $1 == "all" ]] ; then
85 if [[ $# -eq 0 ]] ; then
86 eval $
(bash-colors
--env |
sed 's:^:export :')
89 while read -a line
; do
94 out
=$
(env _proj
=${proj} r rb all .
2>&1)
95 if [[ -n ${out} ]] ; then
97 if [[ ${line} == "# "* ]] ; then
99 printf '%s### %s%-40s%s: %s\n' \
100 "${BRACKET}" "${GOOD}" "${line%%:*}" "${NORMAL}" "${line#*:}"
104 done < <(echo "${out}")
112 #exec r forall -p -c 'r rb all .' </dev/null
115 branches
=$
(g b |
awk '
117 if ($0 ~ "^[*] *[(]no branch[)]") {
119 } else if ($0 ~ "^[*] *[(]detached from ") {
121 } else if ($1 == "*") {
127 END { print list b }')
128 [[ -z ${branches} ]] && exit 0
130 [[ -z ${GOOD} ]] && eval $
(bash-colors
--env)
131 #echo "${GOOD}### ${PWD}${NORMAL}"
132 # Skip if rebase is in progress.
133 if [[ -e .git
/rebase-merge
/interactive
]] ; then
134 echo -e "# ${_proj}: ${WARN}skipping due to active rebase${NORMAL}"
137 for b
in ${branches} ; do
138 #echo " ${HILITE}### $b${NORMAL}"
140 if ! r rb
-q "$@" ; then
149 cd "${root}" ||
exit 1
151 while read -a line
; do
156 out
=$
(g clean
"$@" 2>&1)
157 if [[ -n ${out} ]] ; then
173 f|fetch
) sb_cmd
="fetch" ;;
174 *) err
"unknown sandbox command: $1"
180 cd "${root}" ||
exit 1
182 if [[ ! -e .repo
/sandbox-url
]] ; then
183 err
"Please configure remote url base in ${root}/.repo/sandbox-url"
185 remote
=$
(<.repo
/sandbox-url
) ||
exit 1
187 echo "pushing projects from ${root}"
189 # ssh servers do not like it when you hammer them :)
190 # Received disconnect from 74.125.248.80: 7: Too many concurrent connections
191 # fatal: The remote end hung up unexpectedly
195 tcnt
=$
(echo "${rlist}" |
wc -l)
200 export GIT_DIR
=${path}/.git
202 printf '### (%*i/%i %3i%%) %s\n' \
203 ${#tcnt} $((cnt++)) ${tcnt} $(( cnt * 100 / tcnt )) ${proj}
207 g l
-1 ${src} >& /dev
/null || src
=
208 mj_child g push
--force ${remote}/${proj} ${src}:refs/sandbox/${USER}/${sync_branch} >/dev
/null
213 mj_child g fetch
${remote}/${proj} refs/sandbox/${USER}/${sync_branch}:refs/remotes/sb/${sync_branch} >/dev
/null
216 done < <(echo "${rlist}")
222 # For the times when repo is being stupid, push directly to gerrit myself.
223 if ! branch
=$
(g symbolic-ref
-q HEAD
) ; then
224 err
"could not figure out active branch"
226 branch
=${branch#refs/heads/}
227 if ! remote_branch
=$
(g cfg
--get "branch.${branch}.merge") ; then
228 echo "could not figure out remote branch; using ${branch}"
229 remote_branch
=${branch}
231 if ! remote
=$
(g cfg
--get "branch.${branch}.remote") ; then
232 for remote
in cros-internal cros origin
; do
233 g cfg
--get "remote.${remote}.url" >/dev
/null
&& break
236 review
=$
(g cfg
--get "remote.${remote}.review")
237 remote_branch
=${remote_branch#refs/heads/}
241 while [[ $# -gt 0 ]] ; do
244 process_reviewers
"$2"
247 -n|
--dry-run|
--draft)
251 err
"unknown option: $1"
257 ref_spec
="${branch}:refs/for/${remote_branch}"
258 if [[ -n ${reviewers} ]] ; then
259 reviewers
=( ${reviewers//,/ } )
260 if [[ ${review} != ssh://* ]] ; then
261 gob_args
=$
(printf 'r=%s,' "${reviewers[@]}")
262 ref_spec
+="%${gob_args%,}"
264 git_args
+=( "--receive-pack=git receive-pack ${reviewers[*]/#/--reviewer=}" )
268 vr git push
"${git_args[@]}" ${remote} ${ref_spec} && exit
269 err "could not figure out remote to push to
"
276 while [[ $# -gt 0 ]] ; do
279 process_reviewers "$2"
280 args+=( --re "${reviewers}" )
291 email=${1:-${USER}@chromium.org}
293 set -- -c "git cfg user.email
${email}"
297 exec repo ${acmd:-${cmd}} "$@
"