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