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