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