]>
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 | |
24988ec0 MF |
6 | case $1 in |
7 | -x) set -x; shift;; | |
8 | esac | |
9 | ||
765bb138 | 10 | case $1 in |
dfe9b9cf MF |
11 | rb-all) |
12 | cmd=rebase | |
13 | shift | |
14 | set -- all "$@" | |
15 | ;; | |
765bb138 | 16 | esac |
35c220c5 | 17 | |
1400d2cd MF |
18 | mj_init() { |
19 | pipe=$(mktemp) | |
20 | rm -f "${pipe}" | |
21 | mkfifo "${pipe}" | |
22 | exec {ctlfd}<>"${pipe}" | |
23 | rm -f "${pipe}" | |
24 | jobs=0 | |
25 | jobs_max=${1:-$(getconf _NPROCESSORS_ONLN)} | |
26 | } | |
27 | _mj_child() { echo ${BASHPID} $? >&${ctlfd} ; } | |
28 | mj_child() { | |
29 | ( | |
30 | "$@" | |
31 | _mj_child | |
32 | ) & | |
33 | mj_post_child | |
34 | } | |
35 | mj_post_child() { | |
36 | : $(( ++jobs )) | |
37 | if [[ ${jobs} -eq ${jobs_max} ]] ; then | |
38 | read -r -u ${ctlfd} pid ret | |
39 | : $(( --jobs )) | |
40 | fi | |
41 | } | |
42 | mj_finish() { | |
43 | wait | |
44 | } | |
45 | ||
46 | repo_root() { | |
47 | local root=${PWD} | |
eee212f8 | 48 | while [[ ! -d ${root}/.repo && ${root:-/} != "/" ]] ; do |
1400d2cd MF |
49 | root=${root%/*} |
50 | done | |
51 | echo "${root}" | |
52 | } | |
53 | ||
003d4f70 MF |
54 | process_reviewers() { |
55 | local r arr=() | |
56 | for r in ${*//,/ } ; do | |
57 | case ${r} in | |
a5f629de | 58 | OWNERS*|*/OWNERS*) |
f8260dbd MF |
59 | local owners=$( |
60 | awk -F'@' ' | |
61 | ($2 == "chromium.org" || $2 == "google.com") {list = list "," $1} | |
62 | END {print substr(list, 2)} | |
63 | ' "${r}" | |
64 | ) | |
003d4f70 MF |
65 | if [[ -z ${owners} ]] ; then |
66 | err "cannot find OWNERS list" | |
67 | else | |
68 | echo "Auto setting reviewers to: ${owners}" | |
69 | fi | |
70 | arr+=( ${owners} ) | |
71 | ;; | |
72 | *) | |
73 | arr+=( "${r}" ) | |
74 | ;; | |
75 | esac | |
76 | done | |
77 | reviewers=$(printf '%s,' "${arr[@]}") | |
78 | reviewers=${reviewers%,} | |
79 | } | |
80 | ||
b4533091 MF |
81 | find_repo() { |
82 | # Diff projects have diff versions of repo. Find a compatible one. | |
83 | local root=$(repo_root) | |
84 | ||
85 | # Use the manifest repo URL. | |
86 | local manifest_dir="${root}/.repo/manifests.git" | |
87 | local d | |
88 | ||
89 | # Default to the local repo if it's there. | |
90 | local search=( | |
91 | "${root}/.repo/repo" | |
92 | ) | |
93 | ||
94 | case $(g --git-dir="${manifest_dir}" config remote.origin.url) in | |
95 | *android*) | |
96 | search+=( | |
97 | /usr/local/src/repo | |
98 | ~/src/repo | |
99 | ) | |
100 | ;; | |
101 | *chromium*|*chrome*) | |
102 | search+=( | |
103 | ~/depot_tools | |
104 | ~/chromiumos/depot_tools | |
105 | /usr/local/src/depot_tools | |
106 | ~/src/depot_tools | |
107 | ) | |
108 | ;; | |
109 | esac | |
110 | for d in "${search[@]}" ; do | |
111 | if [[ -x ${d}/repo ]] ; then | |
112 | echo "${d}"/repo | |
113 | return | |
114 | fi | |
115 | done | |
116 | ||
117 | # Fallback: use $PATH. | |
118 | type -P repo | |
119 | } | |
120 | ||
955eb9e8 | 121 | case ${acmd:-${cmd}} in |
35c220c5 MF |
122 | rebase) |
123 | if [[ $1 == "all" ]] ; then | |
e947e1df | 124 | shift |
e051dd74 | 125 | if [[ $# -eq 0 ]] ; then |
26580929 | 126 | eval "$(bash-colors --env | sed 's:^:export :')" |
1400d2cd MF |
127 | root=$(repo_root) |
128 | mj_init | |
129 | while read -a line ; do | |
130 | dir=${line[0]} | |
131 | proj=${line[2]} | |
24988ec0 MF |
132 | if ! cd "${root}/${dir}" ; then |
133 | echo "bad ${proj}" | |
134 | continue | |
135 | fi | |
1400d2cd | 136 | ( |
bc85e5e0 | 137 | out=$(r rb-all . 2>&1) |
71b529c6 | 138 | if [[ -n ${out} ]] ; then |
26580929 MF |
139 | head=$(printf "%-40s" "${proj}") |
140 | echo "${out}" | sed "s:^:${head} :" | |
71b529c6 | 141 | fi |
1400d2cd MF |
142 | _mj_child |
143 | ) & | |
144 | mj_post_child | |
145 | done < <(r l) | |
146 | mj_finish | |
147 | exit 0 | |
148 | #exec r forall -p -c 'r rb all .' </dev/null | |
e051dd74 MF |
149 | fi |
150 | ||
26580929 | 151 | exec git rb-all -q |
35c220c5 MF |
152 | fi |
153 | ;; | |
7ba91d1a MF |
154 | clean) |
155 | root=$(repo_root) | |
156 | cd "${root}" || exit 1 | |
157 | mj_init | |
158 | while read -a line ; do | |
159 | dir=${line[0]} | |
160 | proj=${line[2]} | |
161 | cd "${root}/${dir}" | |
162 | ( | |
163 | out=$(g clean "$@" 2>&1) | |
164 | if [[ -n ${out} ]] ; then | |
165 | echo "### ${proj}" | |
166 | echo "${out}" | |
167 | fi | |
168 | _mj_child | |
169 | ) & | |
170 | mj_post_child | |
171 | done < <(r l) | |
172 | mj_finish | |
173 | exit | |
174 | ;; | |
bf81de9c MF |
175 | sb) |
176 | sb_cmd=$1 | |
177 | case ${sb_cmd} in | |
178 | pull) ;; | |
179 | push) ;; | |
180 | f|fetch) sb_cmd="fetch" ;; | |
181 | *) err "unknown sandbox command: $1" | |
182 | esac | |
183 | ||
955eb9e8 MF |
184 | sync_branch="v" |
185 | ||
1400d2cd | 186 | root=$(repo_root) |
955eb9e8 MF |
187 | cd "${root}" || exit 1 |
188 | ||
189 | if [[ ! -e .repo/sandbox-url ]] ; then | |
8f20a215 | 190 | err "Please configure remote url base in ${root}/.repo/sandbox-url" |
955eb9e8 MF |
191 | fi |
192 | remote=$(<.repo/sandbox-url) || exit 1 | |
193 | ||
194 | echo "pushing projects from ${root}" | |
195 | ||
1400d2cd MF |
196 | # ssh servers do not like it when you hammer them :) |
197 | # Received disconnect from 74.125.248.80: 7: Too many concurrent connections | |
198 | # fatal: The remote end hung up unexpectedly | |
199 | mj_init 16 | |
b5092d38 | 200 | |
7ba91d1a | 201 | rlist=$(r l) |
955eb9e8 MF |
202 | tcnt=$(echo "${rlist}" | wc -l) |
203 | cnt=1 | |
204 | while read line ; do | |
205 | line=( ${line} ) | |
206 | path=${line[0]} | |
207 | export GIT_DIR=${path}/.git | |
208 | proj=${line[2]} | |
209 | printf '### (%*i/%i %3i%%) %s\n' \ | |
210 | ${#tcnt} $((cnt++)) ${tcnt} $(( cnt * 100 / tcnt )) ${proj} | |
211 | src="${sync_branch}" | |
bf81de9c MF |
212 | case ${sb_cmd} in |
213 | push) | |
214 | g l -1 ${src} >& /dev/null || src= | |
215 | mj_child g push --force ${remote}/${proj} ${src}:refs/sandbox/${USER}/${sync_branch} >/dev/null | |
216 | ;; | |
217 | pull) | |
218 | ;; | |
219 | fetch) | |
220 | mj_child g fetch ${remote}/${proj} refs/sandbox/${USER}/${sync_branch}:refs/remotes/sb/${sync_branch} >/dev/null | |
221 | ;; | |
222 | esac | |
7ba91d1a | 223 | done < <(echo "${rlist}") |
1400d2cd | 224 | mj_finish |
955eb9e8 MF |
225 | |
226 | exit 0 | |
227 | ;; | |
8f20a215 MF |
228 | upload) |
229 | args=() | |
230 | while [[ $# -gt 0 ]] ; do | |
231 | case $1 in | |
232 | --re) | |
003d4f70 MF |
233 | process_reviewers "$2" |
234 | args+=( --re "${reviewers}" ) | |
235 | shift 2 | |
236 | continue | |
8f20a215 MF |
237 | ;; |
238 | esac | |
239 | args+=( "$1" ) | |
240 | shift | |
241 | done | |
242 | set -- "${args[@]}" | |
243 | ;; | |
35da3f7e MF |
244 | email) |
245 | email=${1:-${USER}@chromium.org} | |
b4533091 MF |
246 | |
247 | root=$(repo_root) | |
248 | git --git-dir="${root}/.repo/manifests.git" cfg user.email "${email}" | |
249 | git --git-dir="${root}/.repo/repo/.git" cfg user.email "${email}" | |
250 | ||
35da3f7e | 251 | cmd='forall' |
b4533091 | 252 | set -- -c "git cfg user.email '${email}'" |
35da3f7e | 253 | ;; |
35c220c5 MF |
254 | esac |
255 | ||
0342453c | 256 | exec $(find_repo) ${acmd:-${cmd}} "$@" |