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