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