What's cooking
[git] / GRADUATED
1 #!/bin/sh
2
3 # Older first!
4 old_maint='maint-1.6.0 maint-1.6.1'
5
6 _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
7 _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
8 LF='
9 '
10
11 # disable pager
12 GIT_PAGER=cat
13 export GIT_PAGER
14
15 find_last_tip () {
16         topic="$(git rev-parse --verify "$1")" integrate="$2"
17         git rev-list --first-parent --parents "$2" |
18         sed -n -e "
19                 /^$_x40 $_x40 $topic$/{
20                         s/^\($_x40\) $_x40 $topic$/\1/p
21                         q
22                 }
23         "
24 }
25
26
27 tmp=/tmp/GR.$$
28
29 trap 'rm -f "$tmp".*' 0
30
31 git branch --merged master | sed -n -e '/\//s/^. //p' | sort >"$tmp.master"
32
33 >"$tmp.known"
34 for m in $old_maint maint
35 do
36         git branch --merged $m | sed -n -e '/\//s/^. //p' | sort >"$tmp.$m"
37         comm -12 "$tmp.$m" "$tmp.master" >"$tmp.both0"
38         comm -23 "$tmp.both0" "$tmp.known" >"$tmp.both"
39         if test -s "$tmp.both"
40         then
41                 echo "# Graduated to both $m and master"
42                 while read branch
43                 do
44                         echo "$(git show -s --format='%ct' "$branch") $branch"
45                 done <"$tmp.both" |
46                 sort -r -n |
47                 sed -e 's/^[0-9]* //' \
48                     -e 's/^/git branch -d /'
49                 echo
50                 cat "$tmp.known" "$tmp.both" | sort >"$tmp.next"
51                 mv "$tmp.next" "$tmp.known"
52         fi
53 done
54
55 comm -13 "$tmp.maint" "$tmp.master" |
56 {
57         while read topic
58         do
59                 t=$(find_last_tip $topic master) &&
60                 test -n "$t" &&
61                 m=$(git rev-parse --verify "$t^1") &&
62                 test -n "$m" || continue
63
64                 # NEEDSWORK: this misses repeated merges
65                 #
66                 #        o---o---maint
67                 #       /
68                 #      .---o---o topic
69                 #     /     \   \
70                 # ---o---o---*---*---master
71
72                 tsize=$(git rev-list "$m..$topic" | wc -l)
73                 rsize=$(git rev-list "maint..$topic" | wc -l)
74
75                 if test $tsize -eq $rsize
76                 then
77                         s=$(git show -s --pretty="tformat:%ct %H" $t)
78                         echo "$s $topic"
79                 else
80                         s=$(git show -s --pretty="tformat:%ct %H" $t)
81                         echo >&3 "$s $topic"
82                 fi
83         done 3>"$tmp.unmergeable" >"$tmp.mergeable"
84
85         if test -s "$tmp.unmergeable"
86         then
87                 echo "# Graduated to master; unmergeable to maint"
88                 sort -n "$tmp.unmergeable" |
89                 while read timestamp merge topic
90                 do
91                         git show -s --pretty="format:# %h %cd" $merge
92                         echo "git branch -d $topic"
93                 done
94                 echo
95         fi
96         if test -s "$tmp.mergeable"
97         then
98                 sort -n  "$tmp.mergeable" |
99                 while read timestamp merge topic
100                 do
101                         {
102                                 git show -s --pretty="format:%h %cd" $merge
103                                 git log --pretty=oneline --abbrev-commit maint..$topic 
104                         } |
105                         sed -e 's/^/# /'
106                         echo "git checkout maint && git merge $topic"
107                         echo
108                 done
109         fi
110 }