]> git.wh0rd.org Git - home.git/blob - .bin/r
support pushing to user sandbox
[home.git] / .bin / r
1 #!/bin/bash
2 g() { git "$@"; }
3
4 cmd=$1
5 shift
6 [[ -n ${cmd} ]] && acmd=$(git config --get "alias.${cmd}")
7
8 case ${acmd:-${cmd}} in
9 rebase)
10         if [[ $1 == "all" ]] ; then
11                 shift
12                 branches=$(g b | awk '
13                         {
14                                 if ($0 ~ "^[*] *[(]no branch[)]") {
15                                         next
16                                 } else if ($1 == "*") {
17                                         b = $NF
18                                 } else {
19                                         list = list $NF " "
20                                 }
21                         }
22                         END { print list b }')
23                 for b in ${branches} ; do
24                         echo " ### $b"
25                         g co $b || exit 1
26                         r rb "$@" || exit 1
27                 done
28                 exit 0
29         fi
30         ;;
31 sb-push)
32         sync_branch="v"
33
34         root=${PWD}
35         while [[ ! -d ${root}/.repo && ${root} != "/" ]] ; do
36                 root=${root%/*}
37         done
38         cd "${root}" || exit 1
39
40         if [[ ! -e .repo/sandbox-url ]] ; then
41                 echo "Please configure remote url base in ${root}/.repo/sandbox-url"
42                 exit 1
43         fi
44         remote=$(<.repo/sandbox-url) || exit 1
45
46         echo "pushing projects from ${root}"
47
48         pids=()
49         rlist=$(r list)
50         tcnt=$(echo "${rlist}" | wc -l)
51         cnt=1
52         while read line ; do
53                 line=( ${line} )
54                 path=${line[0]}
55                 export GIT_DIR=${path}/.git
56                 proj=${line[2]}
57                 printf '### (%*i/%i %3i%%) %s\n' \
58                         ${#tcnt} $((cnt++)) ${tcnt} $(( cnt * 100 / tcnt )) ${proj}
59                 src="${sync_branch}"
60                 g l -1 ${src} >& /dev/null || src=
61                 ( g push --force ${remote}/${proj} ${src}:refs/sandbox/${USER}/${sync_branch} >/dev/null ) &
62
63                 # ssh servers do not like it when you hammer them :)
64                 #       Received disconnect from 74.125.248.80: 7: Too many concurrent connections
65                 #       fatal: The remote end hung up unexpectedly
66                 pids+=( $! )
67                 if [[ ${#pids[@]} -eq 20 ]] ; then
68                         wait ${pids[@]:0:3}
69                         pids=( ${pids[@]:3} )
70                 fi
71         done <<<"$(r list)"
72         wait
73
74         exit 0
75         ;;
76 esac
77
78 exec repo ${acmd:-${cmd}} "$@"