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