also make key_0 accessible to merlijn
[xonotic/xonotic.git] / all
1 #!/bin/sh
2 # vim: filetype=zsh
3
4 set -e
5
6 # I use this in EVERY shell script ;)
7 LF="
8 "
9
10 d00=`pwd`
11 while ! [ -f ./all ]; do
12         if [ x"`pwd`" = x"/" ]; then
13                 echo "Cannot find myself."
14                 echo "Please run this script with the working directory inside a Xonotic checkout."
15                 exit 1
16         fi
17         cd ..
18 done
19 d0=`pwd`
20 SELF="$d0/all"
21
22 # If we are on WINDOWS:
23 case "$0" in
24         all|*/all)
25                 case "`uname`" in
26                         MINGW*|Win*)
27                                 # Windows hates users. So this script has to copy itself elsewhere first...
28                                 tname=
29                                 cp "$SELF" ../all.xonotic.sh
30                                 export WE_HATE_OUR_USERS=1
31                                 exec ../all.xonotic.sh "$@"
32                                 ;;
33                 esac
34                 ;;
35 esac
36
37 msg()
38 {
39         echo "\e[1m$*\e[m"
40 }
41
42 self=`git hash-object "$SELF"`
43 checkself()
44 {
45         self_new=`git hash-object "$SELF"`
46         if [ x"$self" != x"$self_new" ]; then
47                 msg "./all has changed."
48                 if [ -z "$XONOTIC_FORBID_RERUN_ALL" ]; then
49                         msg "Rerunning the requested operation to make sure."
50                         export XONOTIC_FORBID_RERUN_ALL=1
51                         exec "$SELF" "$@"
52                 else
53                         msg "Please try $SELF update, and then retry your requested operation."
54                         exit 1
55                 fi
56         fi
57         return 0
58 }
59
60 verbose()
61 {
62         msg "+ $*"
63         "$@"
64 }
65
66 visible_repo_name()
67 {
68         case "$1" in
69                 .)
70                         echo "the root directory"
71                         ;;
72                 *)
73                         echo "\"$1\""
74                         ;;
75         esac
76 }
77
78 check_mergeconflict()
79 {
80         if git ls-files -u | grep ' 1   '; then
81                 echo
82                 echo "MERGE CONFLICT."
83                 echo "change into the \"$1\" project directory, and then:"
84                 echo "- edit the files mentioned above with your favorite editor,"
85                 echo "  and fix the conflicts (marked with <<<<<<< blocks)"
86                 echo "- for binary files, you can select the files using"
87                 echo "  git checkout --ours or git checkout --theirs"
88                 echo "- when done with a file, 'git add' the file"
89                 echo "- when done, 'git commit'"
90                 echo
91                 exit 1
92         fi
93 }
94
95 yesno()
96 {
97         yesno=
98         while [ x"$yesno" != x"y" -a x"$yesno" != x"n" ]; do
99                 eval "$2"
100                 echo "$1"
101                 IFS= read -r yesno
102         done
103         [ x"$yesno" = x"y" ]
104 }
105
106 enter()
107 {
108         $2 cd "$1"
109         check_mergeconflict "$1"
110 }
111
112 repos_urls="
113 .                             |                                                   | master      |
114 data/xonotic-data.pk3dir      |                                                   | master      |
115 data/xonotic-maps.pk3dir      |                                                   | master      |
116 data/xonotic-music.pk3dir     |                                                   | master      |
117 data/xonotic-nexcompat.pk3dir |                                                   | master      |
118 mediasource                   |                                                   | master      |
119 darkplaces                    |                                                   | div0-stable | svn
120 fteqcc                        | git://github.com/Blub/qclib.git                   | master      |
121 div0-gittools                 | git://git.icculus.org/divverent/div0-gittools.git | master      |
122 netradiant                    |                                                   | master      |
123 d0_blind_id                   | http://github.com/divVerent/d0_blind_id.git       | master      |
124 "
125 # todo: in darkplaces, change repobranch to div0-stable
126
127 repos=`echo "$repos_urls" | grep . | cut -d '|' -f 1 | tr -d ' '`
128
129 base=`git config remote.origin.url`
130 case "$base" in
131         */xonotic.git)
132                 base=${base%xonotic.git}
133                 ;;
134         *)
135                 echo "The main repo is not xonotic.git, what have you done?"
136                 exit 1
137                 ;;
138 esac
139
140 repourl()
141 {
142         repo_t=`echo "$repos_urls" | grep "^$1 " | cut -d '|' -f 2 | tr -d ' '`
143         if [ -n "$repo_t" ]; then
144                 case "$repo_t" in
145                         *://*)
146                                 echo "$repo_t"
147                                 ;;
148                         *)
149                                 echo "$base$repo_t"
150                                 ;;
151                 esac
152         else
153                 if [ x"$1" = x"." ]; then
154                         echo "$base""xonotic.git"
155                 else
156                         echo "$base${1##*/}.git"
157                 fi
158         fi
159 }
160
161 repobranch()
162 {
163         repo_t=`echo "$repos_urls" | grep "^$1 " | cut -d '|' -f 3 | tr -d ' '`
164         if [ -n "$repo_t" ]; then
165                 echo "$repo_t"
166         else
167                 echo "master"
168         fi
169 }
170
171 repoflags()
172 {
173         echo "$repos_urls" | grep "^$1 " | cut -d '|' -f 4 | tr -d ' '
174 }
175
176 repos=`for d in $repos; do
177         p="${d%dir}"
178         if [ x"$p" = x"$d" ] || [ -d "$d" ] || ! { [ -f "$d.no" ] || [ -f "$p" ]; }; then
179                 echo "$d"
180         fi
181 done`
182
183 if [ "$#" = 0 ]; then
184         set -- help
185 fi
186 cmd=$1
187 shift
188
189 case "$cmd" in
190         update|pull)
191                 allow_pull=true
192                 if [ x"$1" = x"-N" ]; then
193                         allow_pull=false
194                 fi
195                 for d in $repos; do
196                         url=`repourl "$d"`
197                         branch=`repobranch "$d"`
198                         if [ -d "$d0/$d" ]; then
199                                 if $allow_pull; then
200                                         enter "$d0/$d" verbose
201                                         verbose git config remote.origin.url "$url"
202                                         verbose git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
203
204                                         r=`git symbolic-ref HEAD`
205                                         r=${r#refs/heads/}
206                                         if git config branch.$r.remote >/dev/null 2>&1; then
207                                                 if ! verbose git pull; then
208                                                         check_mergeconflict "$d"
209                                                         echo "Pulling failed. Press ENTER to continue, or Ctrl-C to abort."
210                                                         read -r DUMMY
211                                                 fi
212                                         fi
213
214                                         cd "$d00"
215                                         checkself "$cmd" "$@"
216                                         cd "$d0/$d"
217                                         verbose git remote prune origin
218                                         cd "$d0"
219                                 fi
220                         else
221                                 verbose git clone "$url" "$d0/$d"
222                                 enter "$d0/$d" verbose
223                                 if [ "$branch" != "master" ]; then
224                                         verbose git checkout --track -b "$branch" origin/"$branch"
225                                 fi
226                                 cd "$d0"
227                         fi
228                 done
229                 ;;
230         update-maps)
231                 misc/tools/xonotic-map-compiler-autobuild download
232                 ;;
233         checkout|switch)
234                 remote=$1
235                 branch=$2
236                 if [ -z "$branch" ]; then
237                         case "$remote" in
238                                 origin/*)
239                                         branch=${remote#origin/}
240                                         remote=origin
241                                         ;;
242                                 *)
243                                         branch=$remote
244                                         remote=origin
245                                         ;;
246                         esac
247                 fi
248                 exists=false
249                 for d in $repos; do
250                         enter "$d0/$d" verbose
251                         b=$branch
252                         if [ -n "$b" ] && git rev-parse "refs/heads/$b" >/dev/null 2>&1; then
253                                 exists=true
254                                 verbose git checkout "$b"
255                         elif [ -n "$b" ] && git rev-parse "refs/remotes/$remote/$b" >/dev/null 2>&1; then
256                                 exists=true
257                                 verbose git checkout --track -b "$b" "$remote/$b"
258                         else
259                                 b=`repobranch "$d"`
260                                 if git rev-parse "refs/heads/$b" >/dev/null 2>&1; then
261                                         exists=true
262                                         verbose git checkout "$b"
263                                 elif git rev-parse "refs/remotes/$remote/$b" >/dev/null 2>&1; then
264                                         exists=true
265                                         verbose git checkout --track -b "$b" "$remote/$b"
266                                 else
267                                         echo "WTF? Not even branch $b doesn't exist in $d"
268                                         exit 1
269                                 fi
270                         fi
271                         cd "$d00"
272                         checkself "$cmd" "$@"
273                         cd "$d0"
274                 done
275                 if ! $exists; then
276                         echo "The requested branch was not found in any repository."
277                 fi
278                 exec "$SELF" branch
279                 ;;
280         branch)
281                 remote=$1
282                 branch=$2
283                 srcbranch=$3
284                 if [ -z "$branch" ]; then
285                         branch=$remote
286                         remote=origin
287                 fi
288                 if [ -z "$branch" ]; then
289                         for d in $repos; do
290                                 enter "$d0/$d"
291                                 r=`git symbolic-ref HEAD`
292                                 r=${r#refs/heads/}
293                                 echo "$d is at $r"
294                                 cd "$d0"
295                         done
296                 else
297                         for d in $repos; do
298                                 dv=`visible_repo_name "$d"`
299                                 enter "$d0/$d" verbose
300                                 if git rev-parse "refs/heads/$branch" >/dev/null 2>&1; then
301                                         echo "Already having this branch in $dv."
302                                 else
303                                         if yesno "Branch in $dv?"; then
304                                                 if [ -n "$srcbranch" ]; then
305                                                         b=$srcbranch
306                                                 else
307                                                         b=origin/"`repobranch "$d"`"
308                                                         verbose git fetch origin || true
309                                                 fi
310                                                 # TODO do this without pushing
311                                                 verbose git checkout -b "$branch" "$b"
312                                                 verbose git config "branch.$branch.remote" "$remote"
313                                                 verbose git config "branch.$branch.merge" "refs/heads/$branch"
314                                         fi
315                                 fi
316                                 cd "$d0"
317                         done
318                         "$SELF" branch
319                 fi
320                 ;;
321         branches)
322                 for d in $repos; do
323                         cd "$d0/$d" # am in a pipe, shouldn't use enter
324                         git branch -a -v -v | cut -c 3- | sed "s,^,$d ,"
325                         cd "$d0"
326                 done | {
327                         branches_list=
328                         # branches_repos_*=
329                         while read -r d BRANCH REV UPSTREAM TEXT; do
330                                 if [ x"$BRANCH" = x"`repobranch "$d"`" ]; then
331                                         continue
332                                 fi
333                                 case "$UPSTREAM" in
334                                         \[*)
335                                                 UPSTREAM=${UPSTREAM#\[}
336                                                 UPSTREAM=${UPSTREAM%\]}
337                                                 UPSTREAM=${UPSTREAM%:*}
338                                                 ;;
339                                         *)
340                                                 TEXT="$UPSTREAM $TEXT"
341                                                 UPSTREAM=
342                                                 ;;
343                                 esac
344                                 if [ x"$REV" = x"->" ]; then
345                                         continue
346                                 fi
347                                 BRANCH=${BRANCH#remotes/}
348                                 ID=`echo "$BRANCH" | tr -c "A-Za-z0-9." "_"`
349                                 branches_list="$branches_list $BRANCH" # TEH SORT MAKEZ IT UNIEQ
350                                 eval "r=\$branches_repos_$ID"
351                                 case "$UPSTREAM" in
352                                         '')
353                                                 r="$r $d"
354                                                 ;;
355                                         *)
356                                                 r="$r $d:$UPSTREAM"
357                                                 ;;
358                                 esac
359                                 eval "branches_repos_$ID=\$r"
360                         done
361                         echo -n "$branches_list" | xargs -n 1 echo | sort -u | while IFS= read -r BRANCH; do
362                                 ID=`echo "$BRANCH" | tr -c "A-Za-z0-9." "_"`
363                                 eval "r=\$branches_repos_$ID"
364                                 printf "%-60s %s\n" "$BRANCH" "$r"
365                                 #echo "$BRANCH: $r"
366                         done
367                 }
368                 ;;
369         merge)
370                 for d in $repos; do
371                         dv=`visible_repo_name "$d"`
372                         enter "$d0/$d" verbose
373                         r=`git symbolic-ref HEAD`
374                         r=${r#refs/heads/}
375                         if git log HEAD..origin/"`repobranch "$d"`" | grep .; then
376                                 # we have uncommitted changes
377                                 if yesno "Could merge from \"`repobranch "$d"`\" into \"$r\" in $dv. Do it?"; then
378                                         if ! verbose git merge origin/"`repobranch "$d"`"; then
379                                                 check_mergeconflict "$d"
380                                                 exit 1 # this should ALWAYS be fatal
381                                         fi
382                                 fi
383                         fi
384                         cd "$d0"
385                 done
386                 ;;
387         push|commit)
388                 submit=$1
389                 for d in $repos; do
390                         dv=`visible_repo_name "$d"`
391                         enter "$d0/$d" verbose
392                         r=`git symbolic-ref HEAD`
393                         r=${r#refs/heads/}
394                         diffdata=`git diff --color HEAD`
395                         if [ -n "$diffdata" ]; then
396                                 # we have uncommitted changes
397                                 if yesno "Uncommitted changes in \"$r\" in $dv. Commit?" 'echo "$diffdata" | less -r'; then
398                                         verbose git commit -a
399                                 fi
400                         fi
401                         rem=`git config "branch.$r.remote" || echo origin`
402                         bra=`git config "branch.$r.merge" || echo "$r"`
403                         upstream="$rem/$bra"
404                         if ! git rev-parse "$upstream" >/dev/null 2>&1; then
405                                 upstream="origin/`repobranch "$d"`"
406                         fi
407                         logdata=`git log --color "$upstream".."$r"`
408                         if [ -n "$logdata" ]; then
409                                 if yesno "Push \"$r\" in $dv?" 'echo "$logdata" | less -r'; then
410                                         verbose git push "$rem" HEAD
411                                 fi
412                         fi
413                         if [ x"$submit" = x"-s" ]; then
414                                 case "$r" in
415                                         */*)
416                                                 verbose git push "$rem" HEAD:"${bra%%/*}/finished/${bra#*/}"
417                                                 ;;
418                                 esac
419                         fi
420                         cd "$d0"
421                 done
422                 ;;
423         compile)
424                 if [ -n "$WE_HATE_OUR_USERS" ]; then
425                         TARGETS="sv-debug cl-debug"
426                         if [ -z "$CC" ]; then
427                                 export CC=gcc
428                         fi
429                 elif [ x"`uname`" = x"Darwin" ] && { [ -d /Library/Frameworks/SDL.framework ] || [ -d "$HOME/Library/Frameworks/SDL.framework" ]; }; then
430                         # AGL is broken in Snow Leopard, so let's default to SDL if it is available.
431                         TARGETS="sv-debug sdl-debug"
432                 else
433                         TARGETS="sv-debug cl-debug sdl-debug"
434                 fi
435                 case "$1" in
436                         -c)
437                                 cleandp=true
438                                 cleanqcc=true
439                                 cleanqc=true
440                                 shift
441                                 ;;
442                         -n)
443                                 cleandp=false
444                                 cleanqcc=false
445                                 cleanqc=false
446                                 shift
447                                 ;;
448                         *)
449                                 cleandp=false
450                                 cleanqcc=false
451                                 cleanqc=true # version info
452                                 ;;
453                 esac
454                 if [ -n "$1" ]; then
455                         TARGETS=
456                         for X in $1; do
457                                 case "$X" in
458                                         sdl)
459                                                 TARGETS="sdl-debug $TARGETS"
460                                                 ;;
461                                         glx|agl|wgl)
462                                                 TARGETS="cl-debug $TARGETS"
463                                                 ;;
464                                         dedicated)
465                                                 TARGETS="sv-debug $TARGETS"
466                                                 ;;
467                                 esac
468                         done
469                         shift
470                 fi
471                 if [ -z "$MAKEFLAGS" ]; then
472                         if [ -f /proc/cpuinfo ]; then
473                                 ncpus=$((`grep -c '^processor   :' /proc/cpuinfo`+0))
474                                 if [ $ncpus -gt 1 ]; then
475                                         MAKEFLAGS=-j$ncpus
476                                 fi
477                         fi
478                         case "`uname`" in
479                                 Linux|*BSD)
480                                         MAKEFLAGS="$MAKEFLAGS DP_LINK_TO_LIBJPEG=1"
481                                         ;;
482                         esac
483                         if [ -n "$WE_HATE_OUR_USERS" ]; then
484                                 MAKEFLAGS="$MAKEFLAGS DP_MAKE_TARGET=mingw"
485                         fi
486                 fi
487
488                 enter "$d0/fteqcc" verbose
489                 if $cleanqcc; then
490                         verbose make $MAKEFLAGS clean
491                 fi
492                 verbose make $MAKEFLAGS
493
494                 enter "$d0/data/xonotic-data.pk3dir" verbose
495                 if $cleanqc; then
496                         verbose make FTEQCC="$d0/fteqcc/fteqcc.bin" "$@" $MAKEFLAGS clean
497                 fi
498                 verbose make FTEQCC="$d0/fteqcc/fteqcc.bin" "$@" $MAKEFLAGS
499
500                 enter "$d0/darkplaces" verbose
501                 if $cleandp; then
502                         verbose make $MAKEFLAGS clean
503                 fi
504                 for T in $TARGETS; do
505                         verbose make $MAKEFLAGS "$@" "$T"
506                 done
507
508                 verbose "$SELF" update-maps
509                 ;;
510         run)
511                 if [ -n "$WE_HATE_OUR_USERS" ]; then
512                         client=
513                         export PATH="$d0/misc/buildfiles/w32:$PATH"
514                 elif [ x"`uname`" = x"Darwin" ]; then
515                         export DYLD_LIBRARY_PATH="$d0/misc/buildfiles/osx/Xonotic-SDL.app/Contents/MacOS"
516                         client=-sdl
517                 else
518                         client=-sdl
519                 fi
520                 case "$1" in
521                         sdl|glx|agl|dedicated)
522                                 client=-$1
523                                 shift
524                                 ;;
525                         wgl)
526                                 client=
527                                 shift
528                                 ;;
529                 esac
530                 if ! [ -x "darkplaces/darkplaces$client" ]; then
531                         if [ -x "darkplaces/darkplaces$client.exe" ]; then
532                                 client=$client.exe
533                         else
534                                 echo "Client darkplaces/darkplaces$client not found, aborting"
535                                 exit 1
536                         fi
537                 fi
538                 set -- "darkplaces/darkplaces$client" -nexuiz -customgamename Xonotic -customgamedirname1 data -customgamedirname2 "" -customgamescreenshotname xonotic -customgameuserdirname xonotic "$@"
539
540                 # if pulseaudio is running: USE IT
541                 if [ -z "$SDL_AUDIODRIVER" ] && ! [ -n "$WE_HATE_OUR_USERS" ] && ! [ x"`uname`" = x"Darwin" ]; then
542                         if ps -C pulseaudio >/dev/null; then
543                                 if ldd /usr/lib/libSDL.so 2>/dev/null | grep pulse >/dev/null; then
544                                         export SDL_AUDIODRIVER=pulse
545                                 fi
546                         fi
547                 fi
548
549                 if [ -n "$USE_GDB" ]; then
550                         set -- gdb --args "$@"
551                 fi
552                 "$@"
553                 ;;
554         each|foreach)
555                 keep_going=false
556                 if [ x"$1" = x"-k" ]; then
557                         keep_going=true
558                         shift
559                 fi
560                 for d in $repos; do
561                         if verbose cd "$d0/$d"; then
562                                 if $keep_going; then
563                                         verbose "$@" || true
564                                 else
565                                         verbose "$@"
566                                 fi
567                                 cd "$d0"
568                         fi
569                 done
570                 ;;
571         save-patches)
572                 outfile=$1
573                 patchdir=`mktemp -d -t save-patches.XXXXXX`
574                 for d in $repos; do
575                         enter "$d0/$d" verbose
576                         git branch -v -v | cut -c 3- | {
577                                 i=0
578                                 while read -r BRANCH REV UPSTREAM TEXT; do
579                                         case "$UPSTREAM" in
580                                                 \[*)
581                                                         UPSTREAM=${UPSTREAM#\[}
582                                                         UPSTREAM=${UPSTREAM%\]}
583                                                         UPSTREAM=${UPSTREAM%:*}
584                                                         TRACK=true
585                                                         ;;
586                                                 *)
587                                                         UPSTREAM=origin/"`repobranch "$d"`"
588                                                         TRACK=false
589                                                         ;;
590                                         esac
591                                         if [ x"$REV" = x"->" ]; then
592                                                 continue
593                                         fi
594                                         if git format-patch -o "$patchdir/$i" "$UPSTREAM".."$BRANCH"; then
595                                                 echo "$d" > "$patchdir/$i/info.txt"
596                                                 echo "$BRANCH" >> "$patchdir/$i/info.txt"
597                                                 echo "$UPSTREAM" >> "$patchdir/$i/info.txt"
598                                                 echo "$TRACK" >> "$patchdir/$i/info.txt"
599                                                 i=$(($i+1))
600                                         else
601                                                 rm -rf "$patchdir/$i"
602                                         fi
603                                 done
604                         }
605                 done
606                 ( cd "$patchdir" && tar cvzf - . ) > "$outfile"
607                 rm -rf "$patchdir"
608                 ;;
609         restore-patches)
610                 infile=$1
611                 patchdir=`mktemp -d -t restore-patches.XXXXXX`
612                 ( cd "$patchdir" && tar xvzf - ) < "$infile"
613                 # detach the head
614                 for P in "$patchdir"/*/info.txt; do
615                         D=${P%/info.txt}
616                         exec 3<"$P"
617                         read -r d <&3
618                         read -r BRANCH <&3
619                         read -r UPSTREAM <&3
620                         read -r TRACK <&3
621                         verbose git checkout HEAD^0
622                         verbose git branch -D "$BRANCH"
623                         if [ x"$TRACK" = x"true" ]; then
624                                 verbose git checkout --track -b "$BRANCH" "$UPSTREAM"
625                         else
626                                 verbose git branch -b "$BRANCH" "$UPSTREAM"
627                         fi
628                         verbose git am "$D"
629                 done
630                 rm -rf "$patchdir"
631                 ;;
632         admin-merge)
633                 branch=$1
634                 t=`mktemp`
635                 report=""
636                 reportecho()
637                 {
638                         report=$report"$*$LF"
639                         echo "$*"
640                 }
641                 reportecho4()
642                 {
643                         report=$report"    $*$LF"
644                         echo "    $*"
645                 }
646                 reportdo4()
647                 {
648                         o=`"$@" | sed 's/^/    /' || true`
649                         reportecho "$o"
650                 }
651                 for d in $repos; do
652                         enter "$d0/$d" verbose
653                         base="`repobranch "$d"`"
654                         reportecho "In $d:"
655                         for ref in `git for-each-ref --format='%(refname)' refs/remotes/origin/`; do
656                                 case "${ref#refs/remotes/origin/}" in
657                                         "$base")
658                                                 continue
659                                                 ;;
660                                         HEAD|master)
661                                                 continue
662                                                 ;;
663                                         */*)
664                                                 ;;
665                                         *)
666                                                 continue
667                                                 ;;
668                                 esac
669                                 if [ -n "$branch" ]; then
670                                         if [ x"$branch" != x"${ref#refs/remotes/origin/}" ]; then
671                                                 continue
672                                         fi
673                                 fi
674                                 case "$base" in
675                                         master)
676                                                 realbase=$base
677                                                 ;;
678                                         *)
679                                                 l0=`git rev-list "$base".."$ref" | wc -l`
680                                                 l1=`git rev-list master.."$ref" | wc -l`
681                                                 if [ $l0 -gt $l1 ]; then
682                                                         realbase=master
683                                                 else
684                                                         realbase=$base
685                                                 fi
686                                                 ;;
687                                 esac
688                                 reportecho "  Branch $ref:"
689                                 note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
690                                 logdata=`git log --color "$realbase".."$ref"`
691                                 if [ -z "$logdata" ]; then
692                                         reportecho4 "--> not merging, no changes vs master"
693                                         if yesno "Branch \"$ref\" probably should get deleted. Do it?" ''; then
694                                                 git push origin :"${ref#refs/remotes/origin/}"
695                                                 reportecho4 "--> branch deleted"
696                                         fi
697                                 else
698                                         diffdata=`git diff --color --find-copies-harder --ignore-space-change "$realbase"..."$ref"`
699                                         if [ -z "$diffdata" ]; then
700                                                 reportecho4 "--> not merging, no changes vs master, branch contains redundant history"
701                                                 if yesno "Branch \"$ref\" probably should get deleted. Do it?" '{ echo "$logdata"; } | less -r'; then
702                                                         git push origin :"${ref#refs/remotes/origin/}"
703                                                         reportecho4 "--> branch deleted"
704                                                 fi
705                                         elif [ -n "$note" ]; then
706                                                 reportdo4 echo "$note"
707                                                 reportecho4 "--> not merging, already had this one rejected before"
708                                         elif yesno "Branch \"$ref\" may want to get merged. Do it?" '{ echo "$logdata"; echo "$diffdata"; } | less -r'; then
709                                                 git checkout "$realbase"
710                                                 org=`git rev-parse HEAD`
711                                                 if ! git merge "$ref" 2>&1 | tee "$t" && ! { git ls-files -u | grep ' 1   ' >/dev/null; }; then
712                                                         git reset --hard "$org"
713                                                         GIT_NOTES_REF=refs/notes/admin-merge git notes edit -m "Merge failed:$LF`cat "$t"`" "$ref"
714                                                         reportdo4 cat "$t"
715                                                         reportecho4 "--> merge failed"
716                                                 elif ! "$SELF" compile -n 2>&1 | tee "$t"; then
717                                                         git reset --hard "$org"
718                                                         GIT_NOTES_REF=refs/notes/admin-merge git notes edit -m "Compile failed:$LF`cat "$t"`" "$ref"
719                                                         reportdo4 cat "$t"
720                                                         reportecho4 "--> compile failed"
721                                                 elif ! yesno "Still merge \"$ref\" into `git symbolic-ref HEAD` of $d? Maybe you want to test first."; then
722                                                         git reset --hard "$org"
723                                                         git notes edit "$ref"
724                                                         note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
725                                                         if [ x"$note" = x"del" ]; then
726                                                                 git push origin :"${ref#refs/remotes/origin/}"
727                                                                 reportecho4 "--> test failed, branch deleted"
728                                                         elif [ -n "$note" ]; then
729                                                                 reportdo4 echo "$note"
730                                                                 reportecho4 "--> test failed"
731                                                         else
732                                                                 reportecho4 "--> test failed, postponed"
733                                                         fi
734                                                 else
735                                                         echo "MERGING"
736                                                         case ",`repoflags "$d"`," in
737                                                                 *,svn,*)
738                                                                         # we do quite a mess here... luckily we know $org
739                                                                         git fetch # svn needs to be current
740                                                                         git rebase -i --onto origin/master "$org"
741                                                                         git svn dcommit --add-author-from
742                                                                         git reset --hard "$org"
743                                                                         ;;
744                                                                 *)
745                                                                         git push origin HEAD
746                                                                         ;;
747                                                         esac
748                                                         reportecho4 "--> MERGED"
749                                                         if yesno "Delete original branch \"$ref\"?"; then
750                                                                 git push origin :"${ref#refs/remotes/origin/}"
751                                                                 reportecho4 "--> branch deleted"
752                                                         fi
753                                                 fi
754                                         else
755                                                 GIT_NOTES_REF=refs/notes/admin-merge git notes edit "$ref"
756                                                 note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
757                                                 if [ x"$note" = x"del" ]; then
758                                                         git push origin :"${ref#refs/remotes/origin/}"
759                                                         reportecho4 "--> branch deleted"
760                                                 elif [ -n "$note" ]; then
761                                                         reportdo4 echo "$note"
762                                                         reportecho4 "--> rejected"
763                                                 else
764                                                         reportecho4 "--> postponed"
765                                                 fi
766                                         fi
767                                 fi
768                                 reportecho ""
769                         done
770                         reportecho ""
771                 done
772                 rm -f "$t"
773                 echo "$report" | ssh nexuiz@rm.endoftheinternet.org cat '>>' public_html/xonotic-merge-notes.txt
774                 ;;
775
776         # release building goes here
777         release-mkdir)
778                 mkdir -p Xonotic/"$1"
779                 ;;
780         release-prepare)
781 #"$SELF" each git clean -fxd
782                 mkdir -p Xonotic
783                 "$SELF" release-copy Docs/
784                 "$SELF" release-copy misc/
785                 "$SELF" release-copy server/
786                 "$SELF" release-copy xonotic-linux-glx.sh
787                 "$SELF" release-copy xonotic-linux-sdl.sh
788                 "$SELF" release-mkdir data
789                 "$SELF" release-mkdir fteqcc
790                 ;;
791         release-copy)
792                 rsync --exclude=.git -vaSHPAX "$1" Xonotic/"$1"
793                 ;;
794         release-compile-run)
795                 host=$1
796                 buildpath=$2
797                 maketargets=$3
798                 makeflags=$4
799                 srcdir=$5
800                 targetfiles=$6
801                 rsync --delete -zvaSHPAX "$srcdir"/ "$host:$buildpath/"
802                 ssh "$host" ". ~/.profile && cd $buildpath && make clean $maketargets $makeflags"
803         for f in $targetfiles; do
804                         rsync -zvaSHPAX "$host:$buildpath/${f%:*}" "${f##*:}"
805                 done
806                 ;;
807         release-compile)
808                 suffix=$1
809                 makeflags=$2
810                 fteqcc_maketargets=$3
811                 fteqcc_files=$4
812                 darkplaces_maketargets=$5
813                 darkplaces_files=$6
814                 "$SELF" release-compile-run "xonotic-build-$suffix" /tmp/fteqcc.build."$suffix" "$fteqcc_maketargets" "$makeflags" "fteqcc" "$fteqcc_files"
815                 "$SELF" release-compile-run "xonotic-build-$suffix" /tmp/Darkplaces.build."$suffix" "$darkplaces_maketargets" "$makeflags" "fteqcc" "$darkplaces_files"
816                 ;;
817         release-engine-win32)
818                 rsync --exclude=.git -vaSHPAX Xonotic/misc/buildfiles/w32/* Xonotic/
819                 "$SELF" release-compile win32 \
820                         '"DP_MAKE_TARGET=mingw CC="i586-mingw32msvc-gcc -Wl,--dynamicbase -Wl,--nxcompat -g -DSUPPORTDIRECTX -DUSE_WSPIAPI_H -I$HOME/dp.win32/include -L$HOME/db.win32/lib" WINDRES="i586-mingw32msvc-windres" SDL_CONFIG="$HOME/dp.win32/bin/sdl-config"' \
821                         win 'fteqcc.exe:Xonotic/fteqcc/fteqcc.exe' \
822                         debug 'darkplaces.exe:xonotic.exe darkplaces-sdl.exe:xonotic-sdl.exe darkplaces-dedicated.exe:xonotic-dedicated.exe'
823                 ;;
824         release-engine-win64)
825                 rsync --exclude=.git -vaSHPAX Xonotic/misc/buildfiles/w32/* Xonotic/
826                 "$SELF" release-compile win32 \
827                         '"DP_MAKE_TARGET=mingw CC="amd64-mingw32msvc-gcc -Wl,--dynamicbase -Wl,--nxcompat -g -DSUPPORTDIRECTX -DUSE_WSPIAPI_H -I$HOME/dp.win64/include -L$HOME/db.win64/lib" WINDRES="amd64-mingw32msvc-windres" SDL_CONFIG="$HOME/dp.win64/bin/sdl-config"' \
828                         win 'fteqcc.exe:Xonotic/fteqcc/fteqcc.exe' \
829                         debug 'darkplaces.exe:xonotic-64.exe darkplaces-sdl.exe:xonotic-sdl-64.exe darkplaces-dedicated.exe:xonotic-dedicated-64.exe'
830                 ;;
831         release-engine-osx)
832                 rsync --exclude=.git -vaSHPAX Xonotic/misc/buildfiles/osx/* Xonotic/
833                 "$SELF" release-compile osx \
834                         'CC="gcc -g -arch i386 -arch ppc -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -I$HOME/dp.osx/include -L$HOME/dp.osx/lib"' \
835                         all 'fteqcc.bin:Xonotic/fteqcc/fteqcc.osx' \
836                         sdl-debug 'darkplaces-sdl:Xonotic/Xonotic-SDL.app/Contents/MacOS/xonotic-osx-sdl-bin'
837                 ;;
838         release-engine-linux32)
839                 "$SELF" release-compile linux32 \
840                         'CC="gcc -m32 -g -Wl,--hash-style=sysv -I$HOME/dp.linux32/include -L$HOME/dp.linux32/lib" DP_MODPLUG_STATIC_LIBDIR=$HOME/dp.linux32/lib DP_LINK_TO_LIBJPEG=1' \
841                         all 'fteqcc.bin:Xonotic/fteqcc/fteqcc.linux32' \
842                         debug 'darkplaces-glx:Xonotic/xonotic-linux-linux32-glx darkplaces-sdl:Xonotic/xonotic-linux-linux32-sdl darkplaces-dedicated:Xonotic/xonotic-linux-linux32-dedicated'
843                 ;;
844         release-engine-linux64)
845                 "$SELF" release-compile linux64 \
846                         'CC="gcc -m64 -g -Wl,--hash-style=sysv -I$HOME/dp.linux64/include -L$HOME/dp.linux64/lib" DP_MODPLUG_STATIC_LIBDIR=$HOME/dp.linux64/lib DP_LINK_TO_LIBJPEG=1' \
847                         all 'fteqcc.bin:Xonotic/fteqcc/fteqcc.linux64' \
848                         debug 'darkplaces-glx:Xonotic/xonotic-linux-linux64-glx darkplaces-sdl:Xonotic/xonotic-linux-linux64-sdl darkplaces-dedicated:Xonotic/xonotic-linux-linux64-dedicated'
849                 ;;
850         release-engine)
851                 "$SELF" release-engine-win32 &
852                 "$SELF" release-engine-win64 &
853                 "$SELF" release-engine-osx &
854                 "$SELF" release-engine-linux32 &
855                 "$SELF" release-engine-linux64 &
856                 wait
857                 ;;
858         release-maps)
859                 "$SELF" update-maps
860                 for X in data/*-????????????????????????????????????????-????????????????????????????????????????.pk3; do
861                         if [ -f "$X" ]; then
862                                 cd Xonotic/data/xonotic-maps.pk3dir
863                                 unzip ../../../"$X"
864                                 cd ../../..
865                         fi
866                 done
867                 ;;
868         release-finish)
869                 # version numnber and stuff like that
870                 ;;
871         release-qc)
872                 verbose make -C Xonotic/data/xonotic-data.pk3dir FTEQCC="$d0/Xonotic/fteqcc/fteqcc.linux32" FTEQCCFLAGS_WATERMARK=
873                 ;;
874         release-buildpk3-transform-raw)
875                 dir=$1
876                 ;;
877         release-buildpk3-transform-normal)
878                 dir=$1
879                 cd "$dir"
880                 # texture: convert to jpeg and dds
881                 export do_jpeg=true
882                 export jpeg_qual_rgb=95
883                 export jpeg_qual_a=99
884                 export do_dds=true
885                 export dds_flags=
886                 export do_ogg=false
887                 find textures -type f -print0 | xargs -0 "$d0"/misc/tools/cached-converter.sh
888                 ;;
889         release-buildpk3-transform-low)
890                 dir=$1
891                 cd "$dir"
892                 # texture: convert to jpeg and dds
893                 # music: reduce bitrate
894                 export do_jpeg=true
895                 export jpeg_qual_rgb=95
896                 export jpeg_qual_a=99
897                 export do_dds=false
898                 export do_ogg=true
899                 export ogg_qual=1
900                 find textures sound/cdtracks -type f -print0 | xargs -0 "$d0"/misc/tools/cached-converter.sh
901                 ;;
902         release-buildpk3)
903                 src=$1
904                 dst=$2
905                 transform=$3
906                 case "$dst" in
907                         /*)
908                                 ;;
909                         */)
910                                 dst="$PWD/$dst"
911                                 ;;
912                 esac
913                 rm -rf Xonotic/temp
914                 rsync --exclude=.git -vaSHPAX "$src"/ "Xonotic/temp"
915                 "$SELF" release-buildpk3-transform-$transform "Xonotic/temp"
916                 cd Xonotic/temp
917                 zip -9r "../../$dst" . ########### 7za a -tzip -mx=9 "../../$dst" .
918                 cd ../..
919                 rm -rf Xonotic/temp
920                 ;;
921         release-buildpk3s)
922                 src=$1
923                 shift
924                 while [ "$#" -gt 1 ]; do
925                         "$SELF" release-buildpk3 "$src" "Xonotic/${src%.pk3dir}$2.pk3" "$1"
926                         shift
927                         shift
928                 done
929                 ;;
930         release-pack)
931                 "$SELF" release-buildpk3s data/font-dejavu.pk3dir                  raw ''
932                 "$SELF" release-buildpk3s data/xonotic-data.pk3dir       normal '' raw '-raw' low '-low'
933                 "$SELF" release-buildpk3s data/xonotic-maps.pk3dir       normal '' raw '-raw' low '-low'
934                 "$SELF" release-buildpk3s data/xonotic-music.pk3dir      normal '' raw '-raw' low '-low'
935                 "$SELF" release-buildpk3s data/xonotic-nexcompat.pk3dir                       low ''
936                 ;;
937         release)
938                 "$SELF" release-prepare
939                 "$SELF" release-maps
940                 "$SELF" release-finish
941                 "$SELF" release-qc
942                 "$SELF" release-pack
943                 "$SELF" release-engine
944                 ;;
945         *)
946                 echo "Usage:"
947                 echo "  $SELF pull"
948                 echo "  $SELF merge"
949                 echo "  $SELF push [-s]"
950                 echo "  $SELF branches"
951                 echo "  $SELF branch [<remote>] <branchname>"
952                 echo "  $SELF branch <remote> <branchname> <srcbranchname>"
953                 echo "  $SELF checkout [<remote>] <branchname>"
954                 echo "  $SELF compile [-c|-n] [<client>] <options>"
955                 echo "  $SELF run [<client>] <options>"
956                 echo "  $SELF each <command>"
957                 ;;
958 esac