]> git.wh0rd.org - home.git/blob - .bin/r
support OWNERS in subdirs
[home.git] / .bin / r
1 #!/bin/bash
2 g() { git "$@"; }
3 err() { printf '%b\n' "$*" 1>&2; exit 1; }
4
5 case $1 in
6 ""|-*) ;;
7 *)
8 cmd=$1
9 shift
10 acmd=$(git config --get "alias.${cmd}")
11 ;;
12 esac
13
14 case ${acmd:-${cmd}} in
15 rebase)
16 if [[ $1 == "all" ]] ; then
17 shift
18 if [[ $# -eq 0 ]] ; then
19 exec r forall -c 'r rb all .'
20 fi
21
22 branches=$(g b | awk '
23 {
24 if ($0 ~ "^[*] *[(]no branch[)]") {
25 next
26 } else if ($1 == "*") {
27 b = $NF
28 } else {
29 list = list $NF " "
30 }
31 }
32 END { print list b }')
33 [[ -z ${branches} ]] && exit 0
34
35 eval $(bash-colors --env)
36 echo "${GOOD}### ${PWD}${NORMAL}"
37 for b in ${branches} ; do
38 echo " ${HILITE}### $b${NORMAL}"
39 g co $b || exit 1
40 if ! r rb "$@" ; then
41 g rb-a
42 fi
43 done
44 exit 0
45 fi
46 ;;
47 sb-push)
48 sync_branch="v"
49
50 root=${PWD}
51 while [[ ! -d ${root}/.repo && ${root} != "/" ]] ; do
52 root=${root%/*}
53 done
54 cd "${root}" || exit 1
55
56 if [[ ! -e .repo/sandbox-url ]] ; then
57 err "Please configure remote url base in ${root}/.repo/sandbox-url"
58 fi
59 remote=$(<.repo/sandbox-url) || exit 1
60
61 echo "pushing projects from ${root}"
62
63 pids=()
64 rlist=$(r list)
65 tcnt=$(echo "${rlist}" | wc -l)
66 cnt=1
67 while read line ; do
68 line=( ${line} )
69 path=${line[0]}
70 export GIT_DIR=${path}/.git
71 proj=${line[2]}
72 printf '### (%*i/%i %3i%%) %s\n' \
73 ${#tcnt} $((cnt++)) ${tcnt} $(( cnt * 100 / tcnt )) ${proj}
74 src="${sync_branch}"
75 g l -1 ${src} >& /dev/null || src=
76 ( g push --force ${remote}/${proj} ${src}:refs/sandbox/${USER}/${sync_branch} >/dev/null ) &
77
78 # ssh servers do not like it when you hammer them :)
79 # Received disconnect from 74.125.248.80: 7: Too many concurrent connections
80 # fatal: The remote end hung up unexpectedly
81 pids+=( $! )
82 if [[ ${#pids[@]} -eq 20 ]] ; then
83 wait ${pids[@]:0:3}
84 pids=( ${pids[@]:3} )
85 fi
86 done <<<"$(r list)"
87 wait
88
89 exit 0
90 ;;
91 upload)
92 args=()
93 while [[ $# -gt 0 ]] ; do
94 case $1 in
95 --re)
96 if [[ $2 == *"OWNERS" ]] ; then
97 owners=$(awk -F'@' '{list = list "," $1} END {print substr(list, 2)}' "$2")
98 if [[ -z ${owners} ]] ; then
99 err "cannot find OWNERS list"
100 else
101 echo "Auto setting reviewers to: ${owners}"
102 fi
103 args+=( --re "${owners}" )
104 shift 2
105 continue
106 fi
107 ;;
108 esac
109 args+=( "$1" )
110 shift
111 done
112 set -- "${args[@]}"
113 ;;
114 esac
115
116 exec repo ${acmd:-${cmd}} "$@"