--- /dev/null
+#!/bin/bash
+
+commit=$1
+[ "$commit" ] || {
+ echo "$0: <commit id> [<top tag> [<linus branch>]]" 1>&2
+ exit 1
+}
+
+top=$2
+[ "$top" ] || top=HEAD
+
+linus=$3
+[ "$linus" ] || linus=origin/master
+
+base=$(git merge-base "$linus" "$top")
+
+git log --first-parent --pretty='format:%H %P' "$base".."$top" |
+while read m p1 p2
+do
+ [ "$p2" ] || continue
+ git rev-list $base..$p2 | grep -q "$commit" || continue
+ branch=$(git show $m | sed -n "s/[ ]*Merge .* '\([^']*\)'/\1/p")
+ tree=${branch%%/*}
+ [ "$tree" = "quilt" ] && tree=${branch##*/}
+ echo "$tree"
+ break
+done
+
+exit 0