]>
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 | |
19 | acmd=$(git config --get "alias.${cmd}") | |
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 == "*") { | |
36 | b = $NF | |
37 | } else { | |
38 | list = list $NF " " | |
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 | ||
120 | for remote in cros-internal cros origin ; do | |
121 | if g cfg --get "remote.${remote}.url" >/dev/null ; then | |
122 | vr git push ${remote} ${branch}:refs/for/${remote_branch} | |
123 | exit $? | |
124 | fi | |
125 | done | |
126 | err "could not figure out remote to push to" | |
17ff99a0 | 127 | ;; |
3c32f9b8 MF |
128 | sync) |
129 | [[ $# -eq 0 ]] && set -- -j16 | |
7dae893b | 130 | ;; |
8f20a215 MF |
131 | upload) |
132 | args=() | |
133 | while [[ $# -gt 0 ]] ; do | |
134 | case $1 in | |
135 | --re) | |
1d000f52 MF |
136 | if [[ $2 == *"OWNERS" ]] ; then |
137 | owners=$(awk -F'@' '{list = list "," $1} END {print substr(list, 2)}' "$2") | |
8f20a215 MF |
138 | if [[ -z ${owners} ]] ; then |
139 | err "cannot find OWNERS list" | |
140 | else | |
141 | echo "Auto setting reviewers to: ${owners}" | |
142 | fi | |
143 | args+=( --re "${owners}" ) | |
144 | shift 2 | |
145 | continue | |
146 | fi | |
147 | ;; | |
148 | esac | |
149 | args+=( "$1" ) | |
150 | shift | |
151 | done | |
152 | set -- "${args[@]}" | |
153 | ;; | |
35c220c5 MF |
154 | esac |
155 | ||
156 | exec repo ${acmd:-${cmd}} "$@" |