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