]> git.ozlabs.org Git - next-scripts/blob - find_branch
Various updates I forgot to commit
[next-scripts] / find_branch
1 #!/bin/bash
2
3 commit=$1
4 [ "$commit" ] || {
5         echo "$0: <commit id> [<top tag> [<linus branch>]]" 1>&2
6         exit 1
7 }
8 commit=$(git rev-parse --verify "$commit")
9 [ "$commit" ] ||
10         exit 1
11
12 top=$2
13 [ "$top" ] || top=HEAD
14
15 linus=$3
16 [ "$linus" ] || linus=origin/master
17
18 base=$(git merge-base "$linus" "$top")
19
20 git log --first-parent --reverse --pretty='format:%H %P' "$base".."$top" |
21 while read m p1 p2
22 do
23         [ "$p1" = "$commit" ] && {
24                 echo "Directly committed"
25                 break
26         }
27         [ "$p2" ] ||
28                 continue
29         git rev-list $base..$p2 | grep -q "$commit" || continue
30         branch=$(git show $m | sed -n "s/[      ]*Merge .*'\([^']*\)'\( of \([^ ]*\).*\)*$/\1|\3/p")
31         tree=${branch##*|}
32         branch=${branch%%|*}
33         [ "$tree" ] || {
34                 tree=${branch%%/*}
35                 [ "$tree" = "quilt" ] && tree=${branch##*/}
36                 echo "$tree"
37                 break
38         }
39         echo "$tree#$branch"
40         break
41 done
42
43 exit 0