]> git.wh0rd.org - home.git/blobdiff - .bin/r
custom-chroot: fix /dev/pts mounting on older kernels
[home.git] / .bin / r
diff --git a/.bin/r b/.bin/r
index 003121a4edd3fc6aaa2d45d6a7b2eec9df69ba67..dd4cd6b8e56670e078f247f563b767c6e3ca04b3 100755 (executable)
--- a/.bin/r
+++ b/.bin/r
@@ -3,6 +3,10 @@ g() { git "$@"; }
 err() { printf '%b\n' "$*" 1>&2; exit 1; }
 vr() { echo "$@"; "$@"; }
 
+case $1 in
+-x) set -x; shift;;
+esac
+
 case $1 in
 ""|-*) ;;
 l)
@@ -50,7 +54,7 @@ mj_finish() {
 
 repo_root() {
        local root=${PWD}
-       while [[ ! -d ${root}/.repo && ${root} != "/" ]] ; do
+       while [[ ! -d ${root}/.repo && ${root:-/} != "/" ]] ; do
                root=${root%/*}
        done
        echo "${root}"
@@ -61,7 +65,12 @@ process_reviewers() {
        for r in ${*//,/ } ; do
                case ${r} in
                *OWNERS)
-                       local owners=$(awk -F'@' '{list = list "," $1} END {print substr(list, 2)}' "${r}")
+                       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
@@ -78,6 +87,46 @@ process_reviewers() {
        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
@@ -89,7 +138,10 @@ rebase)
                        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)
                                if [[ -n ${out} ]] ; then
@@ -99,7 +151,8 @@ rebase)
                                                        printf '%s### %s%-40s%s: %s\n' \
                                                                "${BRACKET}" "${GOOD}" "${line%%:*}" "${NORMAL}" "${line#*:}"
                                                else
-                                                       echo "${line}"
+                                                       printf '%s### %s%-40s%s: ERROR: %s\n' \
+                                                               "${BRACKET}" "${BAD}" "${dir}" "${NORMAL}" "${line}"
                                                fi
                                        done < <(echo "${out}")
                                fi
@@ -116,7 +169,7 @@ rebase)
                        {
                                if ($0 ~ "^[*] *[(]no branch[)]") {
                                        next
-                               } else if ($0 ~ "^[*] *[(]detached from ") {
+                               } else if ($0 ~ "^[*] *[(](HEAD )?detached (from|at) ") {
                                        next
                                } else if ($1 == "*") {
                                        b = $2
@@ -165,7 +218,15 @@ clean)
        mj_finish
        exit
        ;;
-sb-push)
+sb)
+       sb_cmd=$1
+       case ${sb_cmd} in
+       pull) ;;
+       push) ;;
+       f|fetch) sb_cmd="fetch" ;;
+       *) err "unknown sandbox command: $1"
+       esac
+
        sync_branch="v"
 
        root=$(repo_root)
@@ -194,8 +255,17 @@ sb-push)
                printf '### (%*i/%i %3i%%) %s\n' \
                        ${#tcnt} $((cnt++)) ${tcnt} $(( cnt * 100 / tcnt )) ${proj}
                src="${sync_branch}"
-               g l -1 ${src} >& /dev/null || src=
-               mj_child g push --force ${remote}/${proj} ${src}:refs/sandbox/${USER}/${sync_branch} >/dev/null
+               case ${sb_cmd} in
+               push)
+                       g l -1 ${src} >& /dev/null || src=
+                       mj_child g push --force ${remote}/${proj} ${src}:refs/sandbox/${USER}/${sync_branch} >/dev/null
+                       ;;
+               pull)
+                       ;;
+               fetch)
+                       mj_child g fetch ${remote}/${proj} refs/sandbox/${USER}/${sync_branch}:refs/remotes/sb/${sync_branch} >/dev/null
+                       ;;
+               esac
        done < <(echo "${rlist}")
        mj_finish
 
@@ -272,9 +342,14 @@ upload)
        ;;
 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}} "$@"