]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/all/repos.subr
align :)
[xonotic/xonotic.git] / misc / tools / all / repos.subr
1 allmirrors()
2 {
3         "$@" git  ''   git://git.xonotic.org/xonotic/      ''
4         "$@" http ''   http://git.xonotic.org/xonotic/     ''
5         "$@" ssh  ''   ssh://xonotic@git.xonotic.org/      ''
6
7         "$@" ssh  push ssh://xonotic@push.git.xonotic.org/ ''
8
9         "$@" git  de   git://de.git.xonotic.org/xonotic/   ''
10         "$@" http de   http://de.git.xonotic.org/xonotic/  ''
11
12         "$@" git  nl   git://nl.git.xonotic.org/xonotic/   '*3/2'
13         "$@" http nl   http://nl.git.xonotic.org/xonotic/  '*3/2'
14
15         "$@" git  us   git://us.git.xonotic.org/xonotic/   ''
16         "$@" http us   http://us.git.xonotic.org/xonotic/  ''
17 }
18
19 allrepos()
20 {
21         "$@" .                             xonotic.git                  master         ""
22         "$@" data/xonotic-data.pk3dir      xonotic-data.pk3dir.git      master         ""
23         "$@" data/xonotic-music.pk3dir     xonotic-music.pk3dir.git     master         ""
24         "$@" data/xonotic-nexcompat.pk3dir xonotic-nexcompat.pk3dir.git master         "no"
25         "$@" darkplaces                    darkplaces.git               div0-stable    "svn"
26         "$@" netradiant                    netradiant.git               master         ""
27         "$@" div0-gittools                 div0-gittools.git            master         "no"
28         "$@" d0_blind_id                   d0_blind_id.git              master         ""
29         "$@" data/xonotic-maps.pk3dir      xonotic-maps.pk3dir.git      master         ""
30         "$@" mediasource                   mediasource.git              master         "no"
31         "$@" fteqcc                        fteqcc.git                   xonotic-stable "noautocrlf"
32 }
33
34 mirrorspeed()
35 {
36         if ! { time -p true; } >/dev/null 2>&1; then
37                 echo 0
38                 return
39         fi
40         # first result is to be ignored, but we use it to check status
41         git ls-remote "$1" refs/heads/master >/dev/null 2>&1 || return 1
42         # now actually time it
43         (
44                 set +x
45                 { time -p git ls-remote "$1" refs/heads/master; } 2>&1 >/dev/null | head -n 1 | cut -d ' ' -f 2 | tr -d . | sed 's,^0*,,' | grep . || echo 0
46                         # unit: clock ticks (depends on what "time" returns
47         )
48 }
49 bestmirror()
50 {
51         oldurl="$1"
52         newprotocol="$2"
53         newlocation="$3"
54         oldprotocol=
55         oldlocation=
56         testrepo=
57         bestmirror_firstrepo()
58         {
59                 if [ -z "$testrepo" ]; then
60                         testrepo=$2
61                 fi
62         }
63         allrepos bestmirror_firstrepo
64         bestmirror_findold()
65         {
66                 if [ x"$oldurl" = x"$3" ]; then
67                         oldprotocol=$1
68                         oldlocation=$2
69                 fi
70         }
71         allmirrors bestmirror_findold
72         besturl=
73         bestlocation=
74         besttime=
75         bestcount=
76         bestmirror_benchmark()
77         {
78                 if [ -z "$2" ]; then
79                         # empty location is not allowed
80                         return
81                 fi
82                 if [ x"$1" != x"$newprotocol" ]; then
83                         return
84                 fi
85                 # only working mirrors
86                 if ! thistime=`mirrorspeed "$3$testrepo"`; then
87                         return
88                 fi
89                 thistime=$(($thistime $4))
90                 # anything is better than nothing
91                 if [ -z "$besttime" ]; then
92                         besturl=$3
93                         bestlocation=$2
94                         besttime=$thistime
95                         bestcount=1
96                         return
97                 fi
98                 # prefer location match
99                 if [ x"$2" = x"$newlocation" ]; then
100                         if [ x"$bestlocation" != x"$newlocation" ]; then
101                                 besturl=$3
102                                 bestlocation=$2
103                                 besttime=$thistime
104                                 bestcount=1
105                                 return
106                         fi
107                 else
108                         if [ x"$bestlocation" = x"$newlocation" ]; then
109                                 return
110                         fi
111                 fi
112                 # if we get here, we must compare mirror speed as we have more than one match
113                 if [ $thistime -gt $besttime ]; then
114                         return
115                 elif [ $thistime -lt $besttime ]; then
116                         besturl=$3
117                         besttime=$thistime
118                         bestcount=1
119                         return
120                 fi
121                 # both location and time match. Random decision.
122                 bestcount=$(($bestcount + 1))
123                 if [ $((($RANDOM + 0) % $bestcount)) -eq 0 ]; then
124                         besturl=$3
125                 fi
126         }
127         allmirrors bestmirror_benchmark
128         echo "$besturl"
129 }
130