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