]> git.ozlabs.org Git - next-scripts/blob - find_branch
update to_build_host a bit
[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         echo "No such commit" 1>&2
11         exit 1
12 }
13
14 top=$2
15 [ "$top" ] || top=HEAD
16 tcommit=$(git rev-parse --verify "$top")
17 [ "$tcommit" ] || {
18         echo "Bad top tag" 1>&2
19         exit 1
20 }
21
22 linus=$3
23 [ "$linus" ] || linus=origin/master
24 lcommit=$(git rev-parse --verify "$linus")
25 [ "$lcommit" ] || {
26         echo "Bad linus branch" 1>&2
27         exit 1
28 }
29
30 base=$(git merge-base "$linus" "$top")
31
32 git log --first-parent --reverse --pretty='format:%H %P' "$base".."$top" |
33 while read m p1 p2
34 do
35         [ "$p1" = "$commit" ] && {
36                 git show -s --pretty="format:Commit:            %H%nAuthor:             %aN <%aE>%nAuthorDate:  %ad%nCommitter: %cN <%cE>%nCommitterDate:       %cd%nSubject:   %s" $p1
37                 break
38         }
39         [ "$p2" ] ||
40                 continue
41         git rev-list $base..$p2 | grep -q "$commit" || continue
42         git show -s --pretty="format:Commit:            %H%nAuthor:             %aN <%aE>%nAuthorDate:  %ad%nCommitter: %cN <%cE>%nCommitterDate:       %cd%nSubject:   %s" $m
43         break
44 done
45
46 exit 0