]>
Commit | Line | Data |
---|---|---|
35c220c5 MF |
1 | #!/bin/bash |
2 | g() { git "$@"; } | |
8f20a215 | 3 | err() { printf '%b\n' "$*" 1>&2; exit 1; } |
e3be8889 | 4 | vr() { echo "$@"; "$@"; } |
955eb9e8 | 5 | |
765bb138 MF |
6 | case $1 in |
7 | ""|-*) ;; | |
17ff99a0 MF |
8 | l) |
9 | cmd=list | |
10 | shift | |
11 | ;; | |
3c32f9b8 MF |
12 | s) |
13 | cmd=sync | |
14 | shift | |
15 | ;; | |
765bb138 MF |
16 | *) |
17 | cmd=$1 | |
18 | shift | |
11233988 | 19 | acmd=$(git config --get "alias.${cmd}" | sed 's: -.*::') |
765bb138 MF |
20 | ;; |
21 | esac | |
35c220c5 | 22 | |
1400d2cd MF |
23 | mj_init() { |
24 | pipe=$(mktemp) | |
25 | rm -f "${pipe}" | |
26 | mkfifo "${pipe}" | |
27 | exec {ctlfd}<>"${pipe}" | |
28 | rm -f "${pipe}" | |
29 | jobs=0 | |
30 | jobs_max=${1:-$(getconf _NPROCESSORS_ONLN)} | |
31 | } | |
32 | _mj_child() { echo ${BASHPID} $? >&${ctlfd} ; } | |
33 | mj_child() { | |
34 | ( | |
35 | "$@" | |
36 | _mj_child | |
37 | ) & | |
38 | mj_post_child | |
39 | } | |
40 | mj_post_child() { | |
41 | : $(( ++jobs )) | |
42 | if [[ ${jobs} -eq ${jobs_max} ]] ; then | |
43 | read -r -u ${ctlfd} pid ret | |
44 | : $(( --jobs )) | |
45 | fi | |
46 | } | |
47 | mj_finish() { | |
48 | wait | |
49 | } | |
50 | ||
51 | repo_root() { | |
52 | local root=${PWD} | |
53 | while [[ ! -d ${root}/.repo && ${root} != "/" ]] ; do | |
54 | root=${root%/*} | |
55 | done | |
56 | echo "${root}" | |
57 | } | |
58 | ||
955eb9e8 | 59 | case ${acmd:-${cmd}} in |
35c220c5 MF |
60 | rebase) |
61 | if [[ $1 == "all" ]] ; then | |
e947e1df | 62 | shift |
e051dd74 | 63 | if [[ $# -eq 0 ]] ; then |
1400d2cd MF |
64 | root=$(repo_root) |
65 | mj_init | |
66 | while read -a line ; do | |
67 | dir=${line[0]} | |
68 | proj=${line[2]} | |
69 | cd "${root}/${dir}" | |
70 | ( | |
71 | out=$(r rb all . 2>&1) | |
72 | [[ -n ${out} ]] && echo "${out}" | |
73 | _mj_child | |
74 | ) & | |
75 | mj_post_child | |
76 | done < <(r l) | |
77 | mj_finish | |
78 | exit 0 | |
79 | #exec r forall -p -c 'r rb all .' </dev/null | |
e051dd74 MF |
80 | fi |
81 | ||
e947e1df MF |
82 | branches=$(g b | awk ' |
83 | { | |
84 | if ($0 ~ "^[*] *[(]no branch[)]") { | |
85 | next | |
86 | } else if ($1 == "*") { | |
04aedbbd | 87 | b = $2 |
e947e1df | 88 | } else { |
04aedbbd | 89 | list = list $1 " " |
e947e1df MF |
90 | } |
91 | } | |
92 | END { print list b }') | |
e051dd74 MF |
93 | [[ -z ${branches} ]] && exit 0 |
94 | ||
95 | eval $(bash-colors --env) | |
b5092d38 | 96 | #echo "${GOOD}### ${PWD}${NORMAL}" |
e947e1df | 97 | for b in ${branches} ; do |
1400d2cd | 98 | #echo " ${HILITE}### $b${NORMAL}" |
17ff99a0 | 99 | g co -q $b || exit 1 |
1400d2cd | 100 | if ! r rb -q "$@" ; then |
e051dd74 MF |
101 | g rb-a |
102 | fi | |
35c220c5 MF |
103 | done |
104 | exit 0 | |
105 | fi | |
106 | ;; | |
955eb9e8 MF |
107 | sb-push) |
108 | sync_branch="v" | |
109 | ||
1400d2cd | 110 | root=$(repo_root) |
955eb9e8 MF |
111 | cd "${root}" || exit 1 |
112 | ||
113 | if [[ ! -e .repo/sandbox-url ]] ; then | |
8f20a215 | 114 | err "Please configure remote url base in ${root}/.repo/sandbox-url" |
955eb9e8 MF |
115 | fi |
116 | remote=$(<.repo/sandbox-url) || exit 1 | |
117 | ||
118 | echo "pushing projects from ${root}" | |
119 | ||
1400d2cd MF |
120 | # ssh servers do not like it when you hammer them :) |
121 | # Received disconnect from 74.125.248.80: 7: Too many concurrent connections | |
122 | # fatal: The remote end hung up unexpectedly | |
123 | mj_init 16 | |
b5092d38 | 124 | |
955eb9e8 MF |
125 | rlist=$(r list) |
126 | tcnt=$(echo "${rlist}" | wc -l) | |
127 | cnt=1 | |
128 | while read line ; do | |
129 | line=( ${line} ) | |
130 | path=${line[0]} | |
131 | export GIT_DIR=${path}/.git | |
132 | proj=${line[2]} | |
133 | printf '### (%*i/%i %3i%%) %s\n' \ | |
134 | ${#tcnt} $((cnt++)) ${tcnt} $(( cnt * 100 / tcnt )) ${proj} | |
135 | src="${sync_branch}" | |
136 | g l -1 ${src} >& /dev/null || src= | |
1400d2cd | 137 | mj_child g push --force ${remote}/${proj} ${src}:refs/sandbox/${USER}/${sync_branch} >/dev/null |
b5092d38 | 138 | done < <(r list) |
1400d2cd | 139 | mj_finish |
955eb9e8 MF |
140 | |
141 | exit 0 | |
142 | ;; | |
17ff99a0 MF |
143 | g-push) |
144 | # For the times when repo is being stupid, push directly to gerrit myself. | |
e3be8889 MF |
145 | if ! branch=$(g symbolic-ref -q HEAD) ; then |
146 | err "could not figure out active branch" | |
147 | fi | |
148 | branch=${branch#refs/heads/} | |
149 | if ! remote_branch=$(g cfg --get "branch.${branch}.merge") ; then | |
150 | err "could not figure out remote branch" | |
151 | fi | |
152 | remote_branch=${remote_branch#refs/heads/} | |
153 | ||
36fb4856 MF |
154 | reviewers="" |
155 | while [[ $# -gt 0 ]] ; do | |
156 | case $1 in | |
157 | --re) | |
158 | reviewers=$2 | |
159 | shift | |
160 | ;; | |
161 | *) | |
162 | err "unknown option: $1" | |
163 | ;; | |
164 | esac | |
165 | shift | |
166 | done | |
167 | ||
168 | git_args=() | |
169 | if [[ -n ${reviewers} ]] ; then | |
170 | reviewers=( ${reviewers//,/ } ) | |
e96d1ec9 | 171 | git_args+=( "--receive-pack=git receive-pack ${reviewers[*]/#/--reviewer=}" ) |
36fb4856 MF |
172 | fi |
173 | ||
e3be8889 MF |
174 | for remote in cros-internal cros origin ; do |
175 | if g cfg --get "remote.${remote}.url" >/dev/null ; then | |
36fb4856 | 176 | vr git push "${git_args[@]}" ${remote} ${branch}:refs/for/${remote_branch} |
e3be8889 MF |
177 | exit $? |
178 | fi | |
179 | done | |
180 | err "could not figure out remote to push to" | |
17ff99a0 | 181 | ;; |
3c32f9b8 | 182 | sync) |
7ca95a02 | 183 | set -- -j16 "$@" |
7dae893b | 184 | ;; |
8f20a215 MF |
185 | upload) |
186 | args=() | |
187 | while [[ $# -gt 0 ]] ; do | |
188 | case $1 in | |
189 | --re) | |
1d000f52 MF |
190 | if [[ $2 == *"OWNERS" ]] ; then |
191 | owners=$(awk -F'@' '{list = list "," $1} END {print substr(list, 2)}' "$2") | |
8f20a215 MF |
192 | if [[ -z ${owners} ]] ; then |
193 | err "cannot find OWNERS list" | |
194 | else | |
195 | echo "Auto setting reviewers to: ${owners}" | |
196 | fi | |
197 | args+=( --re "${owners}" ) | |
198 | shift 2 | |
199 | continue | |
200 | fi | |
201 | ;; | |
202 | esac | |
203 | args+=( "$1" ) | |
204 | shift | |
205 | done | |
206 | set -- "${args[@]}" | |
207 | ;; | |
35c220c5 MF |
208 | esac |
209 | ||
210 | exec repo ${acmd:-${cmd}} "$@" |