err() { printf '%b\n' "$*" 1>&2; exit 1; }
vr() { echo "$@"; "$@"; }
+case $1 in
+-x) set -x; shift;;
+esac
+
case $1 in
""|-*) ;;
l)
cmd=sync
shift
;;
+rb-all)
+ cmd=rebase
+ shift
+ set -- all "$@"
+ ;;
*)
cmd=$1
shift
repo_root() {
local root=${PWD}
- while [[ ! -d ${root}/.repo && ${root} != "/" ]] ; do
+ while [[ ! -d ${root}/.repo && ${root:-/} != "/" ]] ; do
root=${root%/*}
done
echo "${root}"
local r arr=()
for r in ${*//,/ } ; do
case ${r} in
- *OWNERS)
- local owners=$(awk -F'@' '{list = list "," $1} END {print substr(list, 2)}' "${r}")
+ OWNERS*|*/OWNERS*)
+ local owners=$(
+ awk -F'@' '
+ ($2 == "chromium.org" || $2 == "google.com") {list = list "," $1}
+ END {print substr(list, 2)}
+ ' "${r}"
+ )
if [[ -z ${owners} ]] ; then
err "cannot find OWNERS list"
else
reviewers=${reviewers%,}
}
+find_repo() {
+ # Diff projects have diff versions of repo. Find a compatible one.
+ local root=$(repo_root)
+
+ # Use the manifest repo URL.
+ local manifest_dir="${root}/.repo/manifests.git"
+ local d
+
+ # Default to the local repo if it's there.
+ local search=(
+ "${root}/.repo/repo"
+ )
+
+ case $(g --git-dir="${manifest_dir}" config remote.origin.url) in
+ *android*)
+ search+=(
+ /usr/local/src/repo
+ ~/src/repo
+ )
+ ;;
+ *chromium*|*chrome*)
+ search+=(
+ ~/depot_tools
+ ~/chromiumos/depot_tools
+ /usr/local/src/depot_tools
+ ~/src/depot_tools
+ )
+ ;;
+ esac
+ for d in "${search[@]}" ; do
+ if [[ -x ${d}/repo ]] ; then
+ echo "${d}"/repo
+ return
+ fi
+ done
+
+ # Fallback: use $PATH.
+ type -P repo
+}
+
case ${acmd:-${cmd}} in
rebase)
if [[ $1 == "all" ]] ; then
shift
if [[ $# -eq 0 ]] ; then
- eval $(bash-colors --env | sed 's:^:export :')
+ eval "$(bash-colors --env | sed 's:^:export :')"
root=$(repo_root)
mj_init
while read -a line ; do
dir=${line[0]}
proj=${line[2]}
- cd "${root}/${dir}"
+ if ! cd "${root}/${dir}" ; then
+ echo "bad ${proj}"
+ continue
+ fi
(
- out=$(env _proj=${proj} r rb all . 2>&1)
+ out=$(r rb all . 2>&1)
if [[ -n ${out} ]] ; then
- while read line ; do
- if [[ ${line} == "# "* ]] ; then
- line="${line#[#] }"
- printf '%s### %s%-40s%s: %s\n' \
- "${BRACKET}" "${GOOD}" "${line%%:*}" "${NORMAL}" "${line#*:}"
- else
- echo "${line}"
- fi
- done < <(echo "${out}")
+ head=$(printf "%-40s" "${proj}")
+ echo "${out}" | sed "s:^:${head} :"
fi
_mj_child
) &
#exec r forall -p -c 'r rb all .' </dev/null
fi
- branches=$(g b | awk '
- {
- if ($0 ~ "^[*] *[(]no branch[)]") {
- next
- } else if ($0 ~ "^[*] *[(]detached from ") {
- next
- } else if ($1 == "*") {
- b = $2
- } else {
- list = list $1 " "
- }
- }
- END { print list b }')
- [[ -z ${branches} ]] && exit 0
-
- [[ -z ${GOOD} ]] && eval $(bash-colors --env)
- #echo "${GOOD}### ${PWD}${NORMAL}"
- # Skip if rebase is in progress.
- if [[ -e .git/rebase-merge/interactive ]] ; then
- echo -e "# ${_proj}: ${WARN}skipping due to active rebase${NORMAL}"
- exit 1
- fi
- for b in ${branches} ; do
- #echo " ${HILITE}### $b${NORMAL}"
- g co -q $b || exit 1
- if ! r rb -q "$@" ; then
- g rb-a
- fi
- done
- exit 0
+ exec git rb-all -q
fi
;;
clean)
;;
email)
email=${1:-${USER}@chromium.org}
+
+ root=$(repo_root)
+ git --git-dir="${root}/.repo/manifests.git" cfg user.email "${email}"
+ git --git-dir="${root}/.repo/repo/.git" cfg user.email "${email}"
+
cmd='forall'
- set -- -c "git cfg user.email ${email}"
+ set -- -c "git cfg user.email '${email}'"
;;
esac
-exec repo ${acmd:-${cmd}} "$@"
+exec python2 $(find_repo) ${acmd:-${cmd}} "$@"