]>
Commit | Line | Data |
---|---|---|
35c220c5 MF |
1 | #!/bin/bash |
2 | g() { git "$@"; } | |
8f20a215 | 3 | err() { printf '%b\n' "$*" 1>&2; exit 1; } |
955eb9e8 | 4 | |
765bb138 MF |
5 | case $1 in |
6 | ""|-*) ;; | |
17ff99a0 MF |
7 | l) |
8 | cmd=list | |
9 | shift | |
10 | ;; | |
3c32f9b8 MF |
11 | s) |
12 | cmd=sync | |
13 | shift | |
14 | ;; | |
765bb138 MF |
15 | *) |
16 | cmd=$1 | |
17 | shift | |
18 | acmd=$(git config --get "alias.${cmd}") | |
19 | ;; | |
20 | esac | |
35c220c5 | 21 | |
955eb9e8 | 22 | case ${acmd:-${cmd}} in |
35c220c5 MF |
23 | rebase) |
24 | if [[ $1 == "all" ]] ; then | |
e947e1df | 25 | shift |
e051dd74 | 26 | if [[ $# -eq 0 ]] ; then |
7dae893b | 27 | exec r forall -p -c 'r rb all .' </dev/null |
e051dd74 MF |
28 | fi |
29 | ||
e947e1df MF |
30 | branches=$(g b | awk ' |
31 | { | |
32 | if ($0 ~ "^[*] *[(]no branch[)]") { | |
33 | next | |
34 | } else if ($1 == "*") { | |
35 | b = $NF | |
36 | } else { | |
37 | list = list $NF " " | |
38 | } | |
39 | } | |
40 | END { print list b }') | |
e051dd74 MF |
41 | [[ -z ${branches} ]] && exit 0 |
42 | ||
43 | eval $(bash-colors --env) | |
b5092d38 | 44 | #echo "${GOOD}### ${PWD}${NORMAL}" |
e947e1df | 45 | for b in ${branches} ; do |
e051dd74 | 46 | echo " ${HILITE}### $b${NORMAL}" |
17ff99a0 | 47 | g co -q $b || exit 1 |
e051dd74 MF |
48 | if ! r rb "$@" ; then |
49 | g rb-a | |
50 | fi | |
35c220c5 MF |
51 | done |
52 | exit 0 | |
53 | fi | |
54 | ;; | |
955eb9e8 MF |
55 | sb-push) |
56 | sync_branch="v" | |
57 | ||
58 | root=${PWD} | |
59 | while [[ ! -d ${root}/.repo && ${root} != "/" ]] ; do | |
60 | root=${root%/*} | |
61 | done | |
62 | cd "${root}" || exit 1 | |
63 | ||
64 | if [[ ! -e .repo/sandbox-url ]] ; then | |
8f20a215 | 65 | err "Please configure remote url base in ${root}/.repo/sandbox-url" |
955eb9e8 MF |
66 | fi |
67 | remote=$(<.repo/sandbox-url) || exit 1 | |
68 | ||
69 | echo "pushing projects from ${root}" | |
70 | ||
b5092d38 MF |
71 | pipe=$(mktemp) |
72 | rm -f "${pipe}" | |
73 | mkfifo "${pipe}" | |
74 | exec {ctlfd}<>"${pipe}" | |
75 | rm -f "${pipe}" | |
76 | jobs=0 | |
77 | ||
955eb9e8 MF |
78 | rlist=$(r list) |
79 | tcnt=$(echo "${rlist}" | wc -l) | |
80 | cnt=1 | |
81 | while read line ; do | |
82 | line=( ${line} ) | |
83 | path=${line[0]} | |
84 | export GIT_DIR=${path}/.git | |
85 | proj=${line[2]} | |
86 | printf '### (%*i/%i %3i%%) %s\n' \ | |
87 | ${#tcnt} $((cnt++)) ${tcnt} $(( cnt * 100 / tcnt )) ${proj} | |
88 | src="${sync_branch}" | |
89 | g l -1 ${src} >& /dev/null || src= | |
b5092d38 MF |
90 | ( |
91 | g push --force ${remote}/${proj} ${src}:refs/sandbox/${USER}/${sync_branch} >/dev/null | |
92 | echo ${BASHPID} $? >&${ctlfd} | |
93 | ) & | |
955eb9e8 MF |
94 | |
95 | # ssh servers do not like it when you hammer them :) | |
96 | # Received disconnect from 74.125.248.80: 7: Too many concurrent connections | |
97 | # fatal: The remote end hung up unexpectedly | |
b5092d38 MF |
98 | : $(( ++jobs )) |
99 | if [[ ${jobs} -eq 16 ]] ; then | |
100 | read -r -u ${ctlfd} pid ret | |
101 | : $(( --jobs )) | |
955eb9e8 | 102 | fi |
b5092d38 | 103 | done < <(r list) |
955eb9e8 MF |
104 | wait |
105 | ||
106 | exit 0 | |
107 | ;; | |
17ff99a0 MF |
108 | g-push) |
109 | # For the times when repo is being stupid, push directly to gerrit myself. | |
a7fa11f7 | 110 | exec git push origin HEAD:refs/for/master |
17ff99a0 | 111 | ;; |
3c32f9b8 MF |
112 | sync) |
113 | [[ $# -eq 0 ]] && set -- -j16 | |
7dae893b | 114 | ;; |
8f20a215 MF |
115 | upload) |
116 | args=() | |
117 | while [[ $# -gt 0 ]] ; do | |
118 | case $1 in | |
119 | --re) | |
1d000f52 MF |
120 | if [[ $2 == *"OWNERS" ]] ; then |
121 | owners=$(awk -F'@' '{list = list "," $1} END {print substr(list, 2)}' "$2") | |
8f20a215 MF |
122 | if [[ -z ${owners} ]] ; then |
123 | err "cannot find OWNERS list" | |
124 | else | |
125 | echo "Auto setting reviewers to: ${owners}" | |
126 | fi | |
127 | args+=( --re "${owners}" ) | |
128 | shift 2 | |
129 | continue | |
130 | fi | |
131 | ;; | |
132 | esac | |
133 | args+=( "$1" ) | |
134 | shift | |
135 | done | |
136 | set -- "${args[@]}" | |
137 | ;; | |
35c220c5 MF |
138 | esac |
139 | ||
140 | exec repo ${acmd:-${cmd}} "$@" |