]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/conflict-rss.sh
url fixes
[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>XonCW: $name</title>
43         <link>http://git.xonotic.org/</link>
44         <description>Xonotic Conflict Watch for branches by $name</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 "$repodir" in
90         '')
91                 repo=`git config remote.origin.url | cut -d / -f 4-`
92                 ;;
93         *)
94                 repo=$repodir # FIXME
95                 ;;
96 esac
97
98 case "$action" in
99         --init)
100                 mkdir -p "$outdir"
101                 for f in "$outdir"/*; do
102                         [ -f "$f" ] || continue
103                         clear_rss "$f"
104                 done
105                 ;;
106         --finish)
107                 for f in "$outdir"/*; do
108                         [ -f "$f" ] || continue
109                         finish_rss "$f"
110                 done
111                 ;;
112         --add)
113                 masterhash=$(
114                         (
115                                 if [ -n "$repodir" ]; then
116                                         cd "$repodir"
117                                 fi
118                                 git rev-parse HEAD
119                         )
120                 )
121                 (
122                         if [ -n "$repodir" ]; then
123                                 cd "$repodir"
124                         fi
125                         branches
126                 ) | while read -r HASH TYPE REFNAME; do
127                         echo >&2 -n "$repodir $REFNAME..."
128                         out=$(
129                                 (
130                                         if [ -n "$repodir" ]; then
131                                                 cd "$repodir"
132                                         fi
133                                         git reset --hard "$masterhash" >/dev/null 2>&1
134                                         if out=`git merge --no-commit -- "$REFNAME" 2>&1`; then
135                                                 good=true
136                                         else
137                                                 good=false
138                                                 echo "$out"
139                                         fi
140                                         git reset --hard "$masterhash" >/dev/null 2>&1
141                                 )
142                         )
143                         if [ -n "$out" ]; then
144                                 b=${REFNAME#refs/remotes/[^/]*/}
145                                 case "$b" in
146                                         */*)
147                                                 n=${b%%/*}
148                                                 ;;
149                                         *)
150                                                 n=divVerent
151                                                 ;;
152                                 esac
153                                 echo "$out" | to_rss "$outdir" "$n" "$masterhash" "$HASH" "$b" "$repo"
154                                 echo >&2 " CONFLICT"
155                         else
156                                 echo >&2 " ok"
157                         fi
158                 done
159                 ;;
160         *)
161                 echo "Usage: $0 --init OUTDIR"
162                 echo "       $0 --add OUTDIR [REPODIR]"
163                 echo "       $0 --finish OUTDIR"
164                 exit 1
165                 ;;
166 esac