]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/conflict-rss.sh
f92fd5e31aa36e984077ac168b91ed0e4e6363b6
[xonotic/xonotic.git] / misc / tools / conflict-rss.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         hash=$4
25         branch=$5
26         repo=$6
27         if [ -n "$repo" ]; then
28                 repo=" in $repo"
29         fi
30
31         filename=`echo -n "$name" | tr -c 'A-Za-z0-9' '_'`.rss
32         outfilename="$outdir/$filename"
33         datetime=`date --rfc-2822`
34         branch=`echo "$branch" | escape_html`
35         repo=`echo "$repo" | escape_html`
36
37         if ! [ -f "$outfilename" ]; then
38                 cat >"$outfilename" <<EOF
39 <?xml version="1.0" encoding="UTF-8" ?>
40 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
41 <channel>
42         <title>Merge conflicts for $name</title>
43         <link>http://git.xonotic.org/</link>
44         <description>...</description>
45         <lastBuildDate>$datetime</lastBuildDate>
46         <ttl>3600</ttl>
47         <atom:link href="http://de.git.xonotic.org/conflicts/$filename" rel="self" type="application/rss+xml" />
48 EOF
49         fi
50         cat >>"$outfilename" <<EOF
51         <item>
52                 <title>$branch$repo ($hash)</title>
53                 <link>http://git.xonotic.org/?p=xonotic/netradiant.git;a=shortlog;h=refs/heads/$name/$branch</link>
54                 <guid isPermaLink="false">http://de.git.xonotic.org/conflicts/$filename#$hash-$masterhash</guid>
55                 <description><![CDATA[
56 EOF
57
58         escape_html >>"$outfilename"
59
60         cat >>"$outfilename" <<EOF
61                 ]]></description>
62         </item>
63 EOF
64 }
65
66 clear_rss()
67 {
68         sed -i -e '/<item>/,$d' "$1"
69 }
70
71 finish_rss()
72 {
73         cat <<EOF >>"$1"
74 </channel>
75 </rss>
76 EOF
77 }
78
79 if [ -z "$outdir" ]; then
80         set --
81 fi
82
83 case "$action" in
84         --init)
85                 mkdir -p "$outdir"
86                 for f in "$outdir"/*; do
87                         [ -f "$f" ] || continue
88                         clear_rss "$f"
89                 done
90                 ;;
91         --finish)
92                 for f in "$outdir"/*; do
93                         [ -f "$f" ] || continue
94                         finish_rss "$f"
95                 done
96                 ;;
97         --add)
98                 masterhash=$(
99                         (
100                                 if [ -n "$repodir" ]; then
101                                         cd "$repodir"
102                                 fi
103                                 git rev-parse HEAD
104                         )
105                 )
106                 (
107                         if [ -n "$repodir" ]; then
108                                 cd "$repodir"
109                         fi
110                         branches
111                 ) | while read -r HASH TYPE REFNAME; do
112                         echo >&2 -n "$repodir $REFNAME..."
113                         out=$(
114                                 (
115                                         if [ -n "$repodir" ]; then
116                                                 cd "$repodir"
117                                         fi
118                                         git reset --hard "$masterhash" >/dev/null 2>&1
119                                         if out=`git merge --no-commit -- "$REFNAME" 2>&1`; then
120                                                 good=true
121                                         else
122                                                 good=false
123                                                 echo "$out"
124                                         fi
125                                         git reset --hard "$masterhash" >/dev/null 2>&1
126                                 )
127                         )
128                         if [ -n "$out" ]; then
129                                 b=${REFNAME#refs/remotes/[^/]*/}
130                                 case "$b" in
131                                         */*)
132                                                 n=${b%%/*}
133                                                 ;;
134                                         *)
135                                                 n=divVerent
136                                                 ;;
137                                 esac
138                                 echo "$out" | to_rss "$outdir" "$n" "$masterhash" "$HASH" "$b" "$repodir"
139                                 echo >&2 " CONFLICT"
140                         else
141                                 echo >&2 " ok"
142                         fi
143                 done
144                 ;;
145         *)
146                 echo "Usage: $0 --init OUTDIR"
147                 echo "       $0 --add OUTDIR [REPODIR]"
148                 echo "       $0 --finish OUTDIR"
149                 exit 1
150                 ;;
151 esac