From 8d60e3109a47b62fc78815e8c3e54da84b038429 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Mon, 14 May 2012 15:31:07 +0200 Subject: [PATCH] add a conflict detector that outputs to per-branchowner RSS feeds --- misc/tools/conflict-rss.sh | 126 +++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100755 misc/tools/conflict-rss.sh diff --git a/misc/tools/conflict-rss.sh b/misc/tools/conflict-rss.sh new file mode 100755 index 00000000..5b61861a --- /dev/null +++ b/misc/tools/conflict-rss.sh @@ -0,0 +1,126 @@ +#!/bin/sh + +set -e + +action=$1 +outdir=$2 +repodir=$3 + +branches() +{ + git for-each-ref 'refs/remotes' | grep -vE ' refs/remotes/([^/]*/HEAD|.*/archived/.*)$' +} + +escape_html() +{ + sed -e 's/&/\&/g; s//>/g' +} + +to_rss() +{ + outdir=$1 + name=$2 + hash=$3 + branch=$4 + + filename=$outdir/`echo -n "$name" | tr -c 'A-Za-z0-9' '_'`.xml + datetime=`date --rfc-2822` + branch=`echo "$branch" | escape_html` + + if ! [ -f "$filename" ]; then + cat >"$filename" < + + + Merge conflicts for $name + ... + ... + $datetime + 3600 +EOF + fi + cat >>"$filename" < + $branch ($hash) + ... + >"$filename" + + cat >>"$filename" < + +EOF +} + +finish_rss() +{ + cat <>"$1" + + +EOF +} + +if [ -z "$outdir" ]; then + set -- +fi + +case "$action" in + --init) + rm -rf "$outdir" + mkdir -p "$outdir" + ;; + --finish) + for f in "$outdir"/*; do + [ -f "$f" ] || continue + finish_rss "$f" + done + ;; + --add) + ( + if [ -n "$repodir" ]; then + cd "$repodir" + fi + branches + ) | while read -r HASH TYPE REFNAME; do + echo >&2 -n "$repodir $REFNAME..." + out=$( ( + if [ -n "$repodir" ]; then + cd "$repodir" + fi + git reset --hard >/dev/null 2>&1 + if out=`git merge --no-commit -- "$REFNAME" 2>&1`; then + good=true + else + good=false + echo "$out" + fi + git reset --hard >/dev/null 2>&1 + ) ) + if [ -n "$out" ]; then + n=${REFNAME#refs/remotes/[^/]*/} + case "$n" in + */*) + b=${n#*/} + n=${n%%/*} + ;; + *) + b="/$n" + n=divVerent + ;; + esac + echo "$out" | to_rss "$outdir" "$n" "$HASH" "$b" + echo >&2 " CONFLICT" + else + echo >&2 " ok" + fi + done + ;; + *) + echo "Usage: $0 --init OUTDIR" + echo " $0 --add OUTDIR [REPODIR]" + echo " $0 --finish OUTDIR" + exit 1 + ;; +esac -- 2.39.2