disable fteqcc compilation
[xonotic/xonotic.git] / misc / tools / conflict-watch.sh
1 #!/bin/sh
2
3 set -e
4
5 action=$1
6 outdir=$2
7 repodir=$3
8
9 branches()
10 {
11         git for-each-ref 'refs/remotes' | grep -vE '    refs/remotes/([^/]*/HEAD|.*/archived/.*)$'
12 }
13
14 escape_html()
15 {
16         sed -e 's/&/\&amp;/g; s/</&lt;/g; s/>/&gt;/g'
17 }
18
19 to_rss()
20 {
21         outdir=$1
22         name=$2
23         masterhash=$3
24         masterbranch=$4
25         hash=$5
26         branch=$6
27         repo=$7
28
29         filename=`echo -n "$name" | tr -c 'A-Za-z0-9' '_'`.rss
30         outfilename="$outdir/$filename"
31         masterbranch=`echo -n "$masterbranch" | escape_html`
32         branch=`echo -n "$branch" | escape_html`
33         repo=`echo -n "$repo" | escape_html`
34
35         if [ -n "$repo" ]; then
36                 repotxt=" in $repo"
37         else
38                 repotxt=
39         fi
40         against="$masterbranch at $masterhash"
41
42         if ! [ -f "$outfilename" ]; then
43                 datetime=`date --rfc-2822`
44                 cat >"$outfilename" <<EOF
45 <?xml version="1.0" encoding="UTF-8" ?>
46 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
47 <channel>
48         <title>XonCW: $name</title>
49         <link>http://git.xonotic.org/</link>
50         <description>Xonotic Conflict Watch for branches by $name</description>
51         <ttl>10800</ttl>
52         <atom:link href="http://nl.git.xonotic.org/xoncw/$filename" rel="self" type="application/rss+xml" />
53         <lastBuildDate>$datetime</lastBuildDate>
54 EOF
55         fi
56         cat >>"$outfilename" <<EOF
57         <item>
58                 <title>$branch$repotxt</title>
59                 <link>http://git.xonotic.org/?p=$repo;a=shortlog;h=refs/heads/$branch</link>
60                 <guid isPermaLink="false">http://nl.git.xonotic.org/xoncw/$filename#$hash</guid>
61                 <description><![CDATA[
62                 Conflicts of $branch at $hash against $against:
63 EOF
64  
65         echo -n "<pre>" >>"$outfilename"
66         escape_html >>"$outfilename"
67         echo "</pre>" >>"$outfilename"
68
69         cat >>"$outfilename" <<EOF
70                 ]]></description>
71         </item>
72 EOF
73 }
74
75 clear_rss()
76 {
77         datetime=`date --rfc-2822`
78         sed -i -e '/<lastBuildDate>/,$d' "$1"
79         cat <<EOF >>"$1"
80         <lastBuildDate>$datetime</lastBuildDate>
81 EOF
82 }
83
84 finish_rss()
85 {
86         cat <<EOF >>"$1"
87 </channel>
88 </rss>
89 EOF
90 }
91
92 if [ -z "$outdir" ]; then
93         set --
94 fi
95
96 repo=$(
97         (
98                 if [ -n "$repodir" ]; then
99                         cd "$repodir"
100                 fi
101                 git config remote.origin.url | cut -d / -f 4-
102         )
103 )
104
105 case "$action" in
106         --init)
107                 mkdir -p "$outdir"
108                 for f in "$outdir"/*; do
109                         [ -f "$f" ] || continue
110                         clear_rss "$f"
111                 done
112                 ;;
113         --finish)
114                 for f in "$outdir"/*; do
115                         [ -f "$f" ] || continue
116                         finish_rss "$f"
117                 done
118                 ;;
119         --add)
120                 masterhash=$(
121                         (
122                                 if [ -n "$repodir" ]; then
123                                         cd "$repodir"
124                                 fi
125                                 git rev-parse HEAD
126                         )
127                 )
128                 masterbranch=$(
129                         (
130                                 if [ -n "$repodir" ]; then
131                                         cd "$repodir"
132                                 fi
133                                 git symbolic-ref HEAD
134                         )
135                 )
136                 masterbranch=${masterbranch#refs/heads/}
137
138                 masterhash2=$(
139                         (
140                                 if [ -n "$repodir" ]; then
141                                         cd "$repodir"
142                                 fi
143                                 git rev-parse master
144                         )
145                 )
146                 masterbranch2=master
147
148                 (
149                         if [ -n "$repodir" ]; then
150                                 cd "$repodir"
151                         fi
152                         branches
153                 ) | while read -r HASH TYPE REFNAME; do
154                         echo >&2 -n "$repo $REFNAME..."
155                         case "$repo:$REFNAME" in
156                                 xonotic/netradiant.git:refs/remotes/origin/divVerent/zeroradiant) continue ;;
157                                 xonotic/netradiant.git:refs/remotes/origin/divVerent/zeroradiant-original) continue ;;
158                                 xonotic/netradiant.git:refs/remotes/origin/divVerent/zeroradiant-split-up-the-q3map2-commit) continue ;;
159                                 xonotic/netradiant.git:refs/remotes/origin/divVerent/zeroradiant-split-up-the-q3map2-commit-goal) continue ;;
160                                 xonotic/darkplaces.git:refs/remotes/origin/dp-mqc-render) continue ;;
161                         esac
162
163                         if [ x"$masterhash" = x"$masterhash2" ]; then
164                                 thismasterhash=$masterhash
165                                 thismasterbranch=$masterbranch
166                         else
167                                 l=$(
168                                         if [ -n "$repodir" ]; then
169                                                 cd "$repodir"
170                                         fi
171                                         git rev-list "$masterhash".."$REFNAME" | wc -l
172                                 )
173                                 l2=$(
174                                         if [ -n "$repodir" ]; then
175                                                 cd "$repodir"
176                                         fi
177                                         git rev-list "$masterhash2".."$REFNAME" | wc -l
178                                 )
179                                 if [ $l -gt $l2 ]; then
180                                         thismasterhash=$masterhash2
181                                         thismasterbranch=$masterbranch2
182                                 else
183                                         thismasterhash=$masterhash
184                                         thismasterbranch=$masterbranch
185                                 fi
186                         fi
187                                 
188                         out=$(
189                                 (
190                                         if [ -n "$repodir" ]; then
191                                                 cd "$repodir"
192                                         fi
193                                         git reset --hard "$thismasterhash" >/dev/null 2>&1
194                                         if out=`git merge --no-commit -- "$REFNAME" 2>&1`; then
195                                                 good=true
196                                         else
197                                                 good=false
198                                                 echo "$out"
199                                         fi
200                                         git reset --hard "$masterhash" >/dev/null 2>&1
201                                 )
202                         )
203                         if [ -n "$out" ]; then
204                                 b=${REFNAME#refs/remotes/[!/]*/}
205                                 case "$b" in
206                                         */*)
207                                                 n=${b%%/*}
208                                                 ;;
209                                         *)
210                                                 n=divVerent
211                                                 ;;
212                                 esac
213                                 echo "$out" | to_rss "$outdir" "$n" "$thismasterhash" "$thismasterbranch" "$HASH" "$b" "$repo"
214                                 echo >&2 " CONFLICT"
215                         else
216                                 echo >&2 " ok"
217                         fi
218                 done
219                 ;;
220         *)
221                 echo "Usage: $0 --init OUTDIR"
222                 echo "       $0 --add OUTDIR [REPODIR]"
223                 echo "       $0 --finish OUTDIR"
224                 exit 1
225                 ;;
226 esac