]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/conflict-rss.sh
more RSS handling: <pre> tags
[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         branch=`echo -n "$branch" | escape_html`
34         repo=`echo -n "$repo" | escape_html`
35
36         if ! [ -f "$outfilename" ]; then
37                 datetime=`date --rfc-2822`
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         <ttl>3600</ttl>
46         <atom:link href="http://de.git.xonotic.org/conflicts/$filename" rel="self" type="application/rss+xml" />
47         <lastBuildDate>$datetime</lastBuildDate>
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         echo -n "<pre>" >>"$outfilename"
59         escape_html >>"$outfilename"
60         echo "</pre>" >>"$outfilename"
61
62         cat >>"$outfilename" <<EOF
63                 ]]></description>
64         </item>
65 EOF
66 }
67
68 clear_rss()
69 {
70         datetime=`date --rfc-2822`
71         sed -i -e '/<lastBuildDate>/,$d' "$1"
72         cat <<EOF >"$1"
73         <lastBuildDate>$datetime</lastBuildDate>
74 EOF
75 }
76
77 finish_rss()
78 {
79         cat <<EOF >>"$1"
80 </channel>
81 </rss>
82 EOF
83 }
84
85 if [ -z "$outdir" ]; then
86         set --
87 fi
88
89 case "$action" in
90         --init)
91                 mkdir -p "$outdir"
92                 for f in "$outdir"/*; do
93                         [ -f "$f" ] || continue
94                         clear_rss "$f"
95                 done
96                 ;;
97         --finish)
98                 for f in "$outdir"/*; do
99                         [ -f "$f" ] || continue
100                         finish_rss "$f"
101                 done
102                 ;;
103         --add)
104                 masterhash=$(
105                         (
106                                 if [ -n "$repodir" ]; then
107                                         cd "$repodir"
108                                 fi
109                                 git rev-parse HEAD
110                         )
111                 )
112                 (
113                         if [ -n "$repodir" ]; then
114                                 cd "$repodir"
115                         fi
116                         branches
117                 ) | while read -r HASH TYPE REFNAME; do
118                         echo >&2 -n "$repodir $REFNAME..."
119                         out=$(
120                                 (
121                                         if [ -n "$repodir" ]; then
122                                                 cd "$repodir"
123                                         fi
124                                         git reset --hard "$masterhash" >/dev/null 2>&1
125                                         if out=`git merge --no-commit -- "$REFNAME" 2>&1`; then
126                                                 good=true
127                                         else
128                                                 good=false
129                                                 echo "$out"
130                                         fi
131                                         git reset --hard "$masterhash" >/dev/null 2>&1
132                                 )
133                         )
134                         if [ -n "$out" ]; then
135                                 b=${REFNAME#refs/remotes/[^/]*/}
136                                 case "$b" in
137                                         */*)
138                                                 n=${b%%/*}
139                                                 ;;
140                                         *)
141                                                 n=divVerent
142                                                 ;;
143                                 esac
144                                 echo "$out" | to_rss "$outdir" "$n" "$masterhash" "$HASH" "$b" "$repodir"
145                                 echo >&2 " CONFLICT"
146                         else
147                                 echo >&2 " ok"
148                         fi
149                 done
150                 ;;
151         *)
152                 echo "Usage: $0 --init OUTDIR"
153                 echo "       $0 --add OUTDIR [REPODIR]"
154                 echo "       $0 --finish OUTDIR"
155                 exit 1
156                 ;;
157 esac