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