3 err
() { printf '%b\n' "$*" 1>&2; exit 1; }
4 vr
() { echo "$@"; "$@"; }
28 acmd
=$
(git config
--get "alias.${cmd}" |
sed 's: -.*::')
36 exec {ctlfd
}<>"${pipe}"
39 jobs_max
=${1:-$(getconf _NPROCESSORS_ONLN)}
41 _mj_child
() { echo ${BASHPID} $? >&${ctlfd} ; }
51 if [[ ${jobs} -eq ${jobs_max} ]] ; then
52 read -r -u ${ctlfd} pid ret
62 while [[ ! -d ${root}/.repo
&& ${root:-/} != "/" ]] ; do
70 for r
in ${*//,/ } ; do
75 ($2 == "chromium.org" || $2 == "google.com") {list = list "," $1}
76 END {print substr(list, 2)}
79 if [[ -z ${owners} ]] ; then
80 err
"cannot find OWNERS list"
82 echo "Auto setting reviewers to: ${owners}"
91 reviewers
=$
(printf '%s,' "${arr[@]}")
92 reviewers
=${reviewers%,}
96 # Diff projects have diff versions of repo. Find a compatible one.
97 local root
=$
(repo_root
)
99 # Use the manifest repo URL.
100 local manifest_dir
="${root}/.repo/manifests.git"
103 # Default to the local repo if it's there.
108 case $
(g
--git-dir="${manifest_dir}" config remote.origin.url
) in
118 ~
/chromiumos
/depot_tools
119 /usr
/local
/src
/depot_tools
124 for d
in "${search[@]}" ; do
125 if [[ -x ${d}/repo
]] ; then
131 # Fallback: use $PATH.
135 case ${acmd:-${cmd}} in
137 if [[ $1 == "all" ]] ; then
139 if [[ $# -eq 0 ]] ; then
140 eval $
(bash-colors
--env |
sed 's:^:export :')
143 while read -a line
; do
146 if ! cd "${root}/${dir}" ; then
151 out
=$
(env _proj
=${proj} r rb all .
2>&1)
152 if [[ -n ${out} ]] ; then
155 "Fast-forwarded "*) ;;
158 printf '%s### %s%-40s%s: %s\n' \
159 "${BRACKET}" "${GOOD}" "${line%%:*}" "${NORMAL}" "${line#*:}"
162 printf '%s### %s%-40s%s: ERROR: %s\n' \
163 "${BRACKET}" "${BAD}" "${dir}" "${NORMAL}" "${line}"
166 done < <(echo "${out}")
174 #exec r forall -p -c 'r rb all .' </dev/null
177 branches
=$
(g b |
awk '
179 if ($0 ~ "^[*] *[(]no branch[)]") {
181 } else if ($0 ~ "^[*] *[(](HEAD )?detached (from|at) ") {
183 } else if ($1 == "*") {
189 END { print list b }')
190 [[ -z ${branches} ]] && exit 0
192 [[ -z ${GOOD} ]] && eval $
(bash-colors
--env)
193 #echo "${GOOD}### ${PWD}${NORMAL}"
194 # Skip if rebase is in progress.
195 if [[ -e .git
/rebase-merge
/interactive
]] ; then
196 echo -e "# ${_proj}: ${WARN}skipping due to active rebase${NORMAL}"
199 for b
in ${branches} ; do
200 #echo " ${HILITE}### $b${NORMAL}"
202 if ! r rb
-q "$@" ; then
211 cd "${root}" ||
exit 1
213 while read -a line
; do
218 out
=$
(g clean
"$@" 2>&1)
219 if [[ -n ${out} ]] ; then
235 f|fetch
) sb_cmd
="fetch" ;;
236 *) err
"unknown sandbox command: $1"
242 cd "${root}" ||
exit 1
244 if [[ ! -e .repo
/sandbox-url
]] ; then
245 err
"Please configure remote url base in ${root}/.repo/sandbox-url"
247 remote
=$
(<.repo
/sandbox-url
) ||
exit 1
249 echo "pushing projects from ${root}"
251 # ssh servers do not like it when you hammer them :)
252 # Received disconnect from 74.125.248.80: 7: Too many concurrent connections
253 # fatal: The remote end hung up unexpectedly
257 tcnt
=$
(echo "${rlist}" |
wc -l)
262 export GIT_DIR
=${path}/.git
264 printf '### (%*i/%i %3i%%) %s\n' \
265 ${#tcnt} $((cnt++)) ${tcnt} $(( cnt * 100 / tcnt )) ${proj}
269 g l
-1 ${src} >& /dev
/null || src
=
270 mj_child g push
--force ${remote}/${proj} ${src}:refs/sandbox/${USER}/${sync_branch} >/dev
/null
275 mj_child g fetch
${remote}/${proj} refs/sandbox/${USER}/${sync_branch}:refs/remotes/sb/${sync_branch} >/dev
/null
278 done < <(echo "${rlist}")
284 # For the times when repo is being stupid, push directly to gerrit myself.
285 if ! branch
=$
(g symbolic-ref
-q HEAD
) ; then
286 err
"could not figure out active branch"
288 branch
=${branch#refs/heads/}
289 if ! remote_branch
=$
(g cfg
--get "branch.${branch}.merge") ; then
290 echo "could not figure out remote branch; using ${branch}"
291 remote_branch
=${branch}
293 if ! remote
=$
(g cfg
--get "branch.${branch}.remote") ; then
294 for remote
in cros-internal cros origin
; do
295 g cfg
--get "remote.${remote}.url" >/dev
/null
&& break
298 review
=$
(g cfg
--get "remote.${remote}.review")
299 remote_branch
=${remote_branch#refs/heads/}
303 while [[ $# -gt 0 ]] ; do
306 process_reviewers
"$2"
309 -n|
--dry-run|
--draft)
313 err
"unknown option: $1"
319 ref_spec
="${branch}:refs/for/${remote_branch}"
320 if [[ -n ${reviewers} ]] ; then
321 reviewers
=( ${reviewers//,/ } )
322 if [[ ${review} != ssh://* ]] ; then
323 gob_args
=$
(printf 'r=%s,' "${reviewers[@]}")
324 ref_spec
+="%${gob_args%,}"
326 git_args
+=( "--receive-pack=git receive-pack ${reviewers[*]/#/--reviewer=}" )
330 vr git push
"${git_args[@]}" ${remote} ${ref_spec} && exit
331 err "could not figure out remote to push to
"
338 while [[ $# -gt 0 ]] ; do
341 process_reviewers "$2"
342 args+=( --re "${reviewers}" )
353 email=${1:-${USER}@chromium.org}
356 git --git-dir="${root}/.repo
/manifests.git
" cfg user.email "${email}"
357 git --git-dir="${root}/.repo
/repo
/.git
" cfg user.email "${email}"
360 set -- -c "git cfg user.email
'${email}'"
364 exec python2 $(find_repo) ${acmd:-${cmd}} "$@
"