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