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