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%,}
91 # Diff projects have diff versions of repo. Find a compatible one.
92 local root
=$
(repo_root
)
94 # Use the manifest repo URL.
95 local manifest_dir
="${root}/.repo/manifests.git"
98 # Default to the local repo if it's there.
103 case $
(g
--git-dir="${manifest_dir}" config remote.origin.url
) in
113 ~
/chromiumos
/depot_tools
114 /usr
/local
/src
/depot_tools
119 for d
in "${search[@]}" ; do
120 if [[ -x ${d}/repo
]] ; then
126 # Fallback: use $PATH.
130 case ${acmd:-${cmd}} in
132 if [[ $1 == "all" ]] ; then
134 if [[ $# -eq 0 ]] ; then
135 eval $
(bash-colors
--env |
sed 's:^:export :')
138 while read -a line
; do
141 if ! cd "${root}/${dir}" ; then
146 out
=$
(env _proj
=${proj} r rb all .
2>&1)
147 if [[ -n ${out} ]] ; then
149 if [[ ${line} == "# "* ]] ; then
151 printf '%s### %s%-40s%s: %s\n' \
152 "${BRACKET}" "${GOOD}" "${line%%:*}" "${NORMAL}" "${line#*:}"
154 printf '%s### %s%-40s%s: ERROR: %s\n' \
155 "${BRACKET}" "${BAD}" "${dir}" "${NORMAL}" "${line}"
157 done < <(echo "${out}")
165 #exec r forall -p -c 'r rb all .' </dev/null
168 branches
=$
(g b |
awk '
170 if ($0 ~ "^[*] *[(]no branch[)]") {
172 } else if ($0 ~ "^[*] *[(](HEAD )?detached (from|at) ") {
174 } else if ($1 == "*") {
180 END { print list b }')
181 [[ -z ${branches} ]] && exit 0
183 [[ -z ${GOOD} ]] && eval $
(bash-colors
--env)
184 #echo "${GOOD}### ${PWD}${NORMAL}"
185 # Skip if rebase is in progress.
186 if [[ -e .git
/rebase-merge
/interactive
]] ; then
187 echo -e "# ${_proj}: ${WARN}skipping due to active rebase${NORMAL}"
190 for b
in ${branches} ; do
191 #echo " ${HILITE}### $b${NORMAL}"
193 if ! r rb
-q "$@" ; then
202 cd "${root}" ||
exit 1
204 while read -a line
; do
209 out
=$
(g clean
"$@" 2>&1)
210 if [[ -n ${out} ]] ; then
226 f|fetch
) sb_cmd
="fetch" ;;
227 *) err
"unknown sandbox command: $1"
233 cd "${root}" ||
exit 1
235 if [[ ! -e .repo
/sandbox-url
]] ; then
236 err
"Please configure remote url base in ${root}/.repo/sandbox-url"
238 remote
=$
(<.repo
/sandbox-url
) ||
exit 1
240 echo "pushing projects from ${root}"
242 # ssh servers do not like it when you hammer them :)
243 # Received disconnect from 74.125.248.80: 7: Too many concurrent connections
244 # fatal: The remote end hung up unexpectedly
248 tcnt
=$
(echo "${rlist}" |
wc -l)
253 export GIT_DIR
=${path}/.git
255 printf '### (%*i/%i %3i%%) %s\n' \
256 ${#tcnt} $((cnt++)) ${tcnt} $(( cnt * 100 / tcnt )) ${proj}
260 g l
-1 ${src} >& /dev
/null || src
=
261 mj_child g push
--force ${remote}/${proj} ${src}:refs/sandbox/${USER}/${sync_branch} >/dev
/null
266 mj_child g fetch
${remote}/${proj} refs/sandbox/${USER}/${sync_branch}:refs/remotes/sb/${sync_branch} >/dev
/null
269 done < <(echo "${rlist}")
275 # For the times when repo is being stupid, push directly to gerrit myself.
276 if ! branch
=$
(g symbolic-ref
-q HEAD
) ; then
277 err
"could not figure out active branch"
279 branch
=${branch#refs/heads/}
280 if ! remote_branch
=$
(g cfg
--get "branch.${branch}.merge") ; then
281 echo "could not figure out remote branch; using ${branch}"
282 remote_branch
=${branch}
284 if ! remote
=$
(g cfg
--get "branch.${branch}.remote") ; then
285 for remote
in cros-internal cros origin
; do
286 g cfg
--get "remote.${remote}.url" >/dev
/null
&& break
289 review
=$
(g cfg
--get "remote.${remote}.review")
290 remote_branch
=${remote_branch#refs/heads/}
294 while [[ $# -gt 0 ]] ; do
297 process_reviewers
"$2"
300 -n|
--dry-run|
--draft)
304 err
"unknown option: $1"
310 ref_spec
="${branch}:refs/for/${remote_branch}"
311 if [[ -n ${reviewers} ]] ; then
312 reviewers
=( ${reviewers//,/ } )
313 if [[ ${review} != ssh://* ]] ; then
314 gob_args
=$
(printf 'r=%s,' "${reviewers[@]}")
315 ref_spec
+="%${gob_args%,}"
317 git_args
+=( "--receive-pack=git receive-pack ${reviewers[*]/#/--reviewer=}" )
321 vr git push
"${git_args[@]}" ${remote} ${ref_spec} && exit
322 err "could not figure out remote to push to
"
329 while [[ $# -gt 0 ]] ; do
332 process_reviewers "$2"
333 args+=( --re "${reviewers}" )
344 email=${1:-${USER}@chromium.org}
347 git --git-dir="${root}/.repo
/manifests.git
" cfg user.email "${email}"
348 git --git-dir="${root}/.repo
/repo
/.git
" cfg user.email "${email}"
351 set -- -c "git cfg user.email
'${email}'"
355 exec python2 $(find_repo) ${acmd:-${cmd}} "$@
"