From: Rudolf Polzer Date: Thu, 3 Nov 2011 10:10:35 +0000 (+0100) Subject: add a tool to track open reverts X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=c4051be41322f489ade2835608e51b31b220fe15;p=xonotic%2Fdiv0-gittools.git add a tool to track open reverts --- diff --git a/git-open-reverts b/git-open-reverts new file mode 100755 index 0000000..2ad1c1f --- /dev/null +++ b/git-open-reverts @@ -0,0 +1,81 @@ +#!/bin/sh + +t=`mktemp` +git log --pretty=raw "$@" > "$t" + +allreverted= +reverts() +{ + commit=$1 + reverted=$2 + eval "reverts_in_$commit=\"\$reverts_in_$commit $reverted\"" + eval "reverts_$reverted=\"\$reverts_$reverted $commit\"" + allreverted="$allreverted $reverted" + #echo >&2 "Found: $commit reverts $reverted" +} + +# in the tree of reverters, look for any leaves of even depth + +reverters() +{ + eval "echo \$reverts_$1" +} + +whatreverts_inverted() +{ + local status reverter printme + status=false + printme=true + for reverter in `reverters "$1"`; do + if ! whatreverts "$reverter"; then + status=true + fi + printme=false + done + if $printme; then + echo "$1" + fi + $status +} + +whatreverts() +{ + local status reverter + status=false + for reverter in `reverters "$1"`; do + if ! whatreverts_inverted "$reverter"; then + status=true + fi + done + $status +} + +# pass 1: find which commit reverts which +while IFS= read -r L; do + case "$L" in + "commit "*) + commit="${L#commit }" + ;; + " This reverts commit "*) + reverted=${L# This reverts commit } + reverted=${reverted%.} + reverts "$commit" "$reverted" + ;; + esac +done < "$t" + +# pass 2: for all reverted commits, find their status and their latest revert +for commit in $allreverted; do + if eval "[ -n \"\$seen_$commit\" ]"; then + continue + fi + eval "seen_$commit=1" + if eval "[ -n \"\$reverts_in_$commit\" ]"; then + continue + fi + if revertedby=`whatreverts "$commit" | grep .`; then + echo "$commit got reverted by $revertedby" + fi +done + +rm -f "$t"