]>
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 |
71b529c6 | 64 | eval $(bash-colors --env | sed 's:^:export :') |
1400d2cd MF |
65 | root=$(repo_root) |
66 | mj_init | |
67 | while read -a line ; do | |
68 | dir=${line[0]} | |
69 | proj=${line[2]} | |
70 | cd "${root}/${dir}" | |
71 | ( | |
63717a62 | 72 | out=$(env _proj=${proj} r rb all . 2>&1) |
71b529c6 MF |
73 | if [[ -n ${out} ]] ; then |
74 | while read line ; do | |
75 | if [[ ${line} == "# "* ]] ; then | |
76 | line="${line#[#] }" | |
77 | printf '%s### %s%-40s%s: %s\n' \ | |
78 | "${BRACKET}" "${GOOD}" "${line%%:*}" "${NORMAL}" "${line#*:}" | |
79 | else | |
80 | echo "${line}" | |
81 | fi | |
82 | done < <(echo "${out}") | |
83 | fi | |
1400d2cd MF |
84 | _mj_child |
85 | ) & | |
86 | mj_post_child | |
87 | done < <(r l) | |
88 | mj_finish | |
89 | exit 0 | |
90 | #exec r forall -p -c 'r rb all .' </dev/null | |
e051dd74 MF |
91 | fi |
92 | ||
e947e1df MF |
93 | branches=$(g b | awk ' |
94 | { | |
95 | if ($0 ~ "^[*] *[(]no branch[)]") { | |
96 | next | |
35da3f7e MF |
97 | } else if ($0 ~ "^[*] *[(]detached from ") { |
98 | next | |
e947e1df | 99 | } else if ($1 == "*") { |
04aedbbd | 100 | b = $2 |
e947e1df | 101 | } else { |
04aedbbd | 102 | list = list $1 " " |
e947e1df MF |
103 | } |
104 | } | |
105 | END { print list b }') | |
e051dd74 MF |
106 | [[ -z ${branches} ]] && exit 0 |
107 | ||
71b529c6 | 108 | [[ -z ${GOOD} ]] && eval $(bash-colors --env) |
b5092d38 | 109 | #echo "${GOOD}### ${PWD}${NORMAL}" |
63717a62 MF |
110 | # Skip if rebase is in progress. |
111 | if [[ -e .git/rebase-merge/interactive ]] ; then | |
71b529c6 | 112 | echo -e "# ${_proj}: ${WARN}skipping due to active rebase${NORMAL}" |
63717a62 MF |
113 | exit 1 |
114 | fi | |
e947e1df | 115 | for b in ${branches} ; do |
1400d2cd | 116 | #echo " ${HILITE}### $b${NORMAL}" |
17ff99a0 | 117 | g co -q $b || exit 1 |
1400d2cd | 118 | if ! r rb -q "$@" ; then |
e051dd74 MF |
119 | g rb-a |
120 | fi | |
35c220c5 MF |
121 | done |
122 | exit 0 | |
123 | fi | |
124 | ;; | |
7ba91d1a MF |
125 | clean) |
126 | root=$(repo_root) | |
127 | cd "${root}" || exit 1 | |
128 | mj_init | |
129 | while read -a line ; do | |
130 | dir=${line[0]} | |
131 | proj=${line[2]} | |
132 | cd "${root}/${dir}" | |
133 | ( | |
134 | out=$(g clean "$@" 2>&1) | |
135 | if [[ -n ${out} ]] ; then | |
136 | echo "### ${proj}" | |
137 | echo "${out}" | |
138 | fi | |
139 | _mj_child | |
140 | ) & | |
141 | mj_post_child | |
142 | done < <(r l) | |
143 | mj_finish | |
144 | exit | |
145 | ;; | |
955eb9e8 MF |
146 | sb-push) |
147 | sync_branch="v" | |
148 | ||
1400d2cd | 149 | root=$(repo_root) |
955eb9e8 MF |
150 | cd "${root}" || exit 1 |
151 | ||
152 | if [[ ! -e .repo/sandbox-url ]] ; then | |
8f20a215 | 153 | err "Please configure remote url base in ${root}/.repo/sandbox-url" |
955eb9e8 MF |
154 | fi |
155 | remote=$(<.repo/sandbox-url) || exit 1 | |
156 | ||
157 | echo "pushing projects from ${root}" | |
158 | ||
1400d2cd MF |
159 | # ssh servers do not like it when you hammer them :) |
160 | # Received disconnect from 74.125.248.80: 7: Too many concurrent connections | |
161 | # fatal: The remote end hung up unexpectedly | |
162 | mj_init 16 | |
b5092d38 | 163 | |
7ba91d1a | 164 | rlist=$(r l) |
955eb9e8 MF |
165 | tcnt=$(echo "${rlist}" | wc -l) |
166 | cnt=1 | |
167 | while read line ; do | |
168 | line=( ${line} ) | |
169 | path=${line[0]} | |
170 | export GIT_DIR=${path}/.git | |
171 | proj=${line[2]} | |
172 | printf '### (%*i/%i %3i%%) %s\n' \ | |
173 | ${#tcnt} $((cnt++)) ${tcnt} $(( cnt * 100 / tcnt )) ${proj} | |
174 | src="${sync_branch}" | |
175 | g l -1 ${src} >& /dev/null || src= | |
1400d2cd | 176 | mj_child g push --force ${remote}/${proj} ${src}:refs/sandbox/${USER}/${sync_branch} >/dev/null |
7ba91d1a | 177 | done < <(echo "${rlist}") |
1400d2cd | 178 | mj_finish |
955eb9e8 MF |
179 | |
180 | exit 0 | |
181 | ;; | |
17ff99a0 MF |
182 | g-push) |
183 | # For the times when repo is being stupid, push directly to gerrit myself. | |
e3be8889 MF |
184 | if ! branch=$(g symbolic-ref -q HEAD) ; then |
185 | err "could not figure out active branch" | |
186 | fi | |
187 | branch=${branch#refs/heads/} | |
188 | if ! remote_branch=$(g cfg --get "branch.${branch}.merge") ; then | |
189 | err "could not figure out remote branch" | |
190 | fi | |
8a21037a MF |
191 | if ! remote=$(g cfg --get "branch.${branch}.remote") ; then |
192 | for remote in cros-internal cros origin ; do | |
193 | g cfg --get "remote.${remote}.url" >/dev/null && break | |
194 | done | |
195 | fi | |
e3be8889 MF |
196 | remote_branch=${remote_branch#refs/heads/} |
197 | ||
eacd89fe | 198 | git_args=() |
36fb4856 MF |
199 | reviewers="" |
200 | while [[ $# -gt 0 ]] ; do | |
201 | case $1 in | |
202 | --re) | |
203 | reviewers=$2 | |
204 | shift | |
205 | ;; | |
eacd89fe MF |
206 | -n|--dry-run) |
207 | git_args+=( $1 ) | |
208 | ;; | |
36fb4856 MF |
209 | *) |
210 | err "unknown option: $1" | |
211 | ;; | |
212 | esac | |
213 | shift | |
214 | done | |
215 | ||
36fb4856 MF |
216 | if [[ -n ${reviewers} ]] ; then |
217 | reviewers=( ${reviewers//,/ } ) | |
e96d1ec9 | 218 | git_args+=( "--receive-pack=git receive-pack ${reviewers[*]/#/--reviewer=}" ) |
36fb4856 MF |
219 | fi |
220 | ||
8a21037a | 221 | vr git push "${git_args[@]}" ${remote} ${branch}:refs/for/${remote_branch} && exit |
e3be8889 | 222 | err "could not figure out remote to push to" |
17ff99a0 | 223 | ;; |
3c32f9b8 | 224 | sync) |
35da3f7e | 225 | set -- -j16 -c "$@" |
7dae893b | 226 | ;; |
8f20a215 MF |
227 | upload) |
228 | args=() | |
229 | while [[ $# -gt 0 ]] ; do | |
230 | case $1 in | |
231 | --re) | |
1d000f52 MF |
232 | if [[ $2 == *"OWNERS" ]] ; then |
233 | owners=$(awk -F'@' '{list = list "," $1} END {print substr(list, 2)}' "$2") | |
8f20a215 MF |
234 | if [[ -z ${owners} ]] ; then |
235 | err "cannot find OWNERS list" | |
236 | else | |
237 | echo "Auto setting reviewers to: ${owners}" | |
238 | fi | |
239 | args+=( --re "${owners}" ) | |
240 | shift 2 | |
241 | continue | |
242 | fi | |
243 | ;; | |
244 | esac | |
245 | args+=( "$1" ) | |
246 | shift | |
247 | done | |
248 | set -- "${args[@]}" | |
249 | ;; | |
35da3f7e MF |
250 | email) |
251 | email=${1:-${USER}@chromium.org} | |
252 | cmd='forall' | |
253 | set -- -c "git cfg user.email ${email}" | |
254 | ;; | |
35c220c5 MF |
255 | esac |
256 | ||
257 | exec repo ${acmd:-${cmd}} "$@" |