]> git.rm.cloudns.org Git - xonotic/div0-gittools.git/commitdiff
add a tool to track open reverts
authorRudolf Polzer <divverent@xonotic.org>
Thu, 3 Nov 2011 10:10:35 +0000 (11:10 +0100)
committerRudolf Polzer <divverent@xonotic.org>
Thu, 3 Nov 2011 10:10:35 +0000 (11:10 +0100)
git-open-reverts [new file with mode: 0755]

diff --git a/git-open-reverts b/git-open-reverts
new file mode 100755 (executable)
index 0000000..2ad1c1f
--- /dev/null
@@ -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"