What's cooking (2012/09 #04)
[alt-git.git] / GRADUATED
blob45bf8b210236d624c06e46fe57d81402d867c033
1 #!/bin/sh
3 # Older first!
4 old_maint=$(
5 git for-each-ref --format='%(refname)' 'refs/heads/maint-*' |
6 sed -e 's|^refs/heads/||'
9 # Are older maint branches all included in newer ones?
10 and_or_thru=thru prev=
11 for m in $old_maint maint
13 if test -n "$prev"
14 then
15 test "$(git rev-list $m..$prev | wc -l)" = 0 || {
16 and_or_thru=and
17 break
20 prev=$m
21 done
23 _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
24 _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
25 LF='
28 # disable pager
29 GIT_PAGER=cat
30 export GIT_PAGER
32 find_last_tip () {
33 topic="$(git rev-parse --verify "$1")" integrate="$2"
34 git rev-list --first-parent --parents "$2" |
35 sed -n -e "
36 /^$_x40 $_x40 $topic$/{
37 s/^\($_x40\) $_x40 $topic$/\1/p
44 tmp=/tmp/GR.$$
46 trap 'rm -f "$tmp".*' 0
48 git branch --merged master | sed -n -e '/\//s/^. //p' | sort >"$tmp.master"
50 >"$tmp.known"
51 for m in $old_maint maint
53 git branch --merged $m | sed -n -e '/\//s/^. //p' | sort >"$tmp.$m"
54 comm -12 "$tmp.$m" "$tmp.master" >"$tmp.both0"
55 comm -23 "$tmp.both0" "$tmp.known" >"$tmp.both"
56 if test -s "$tmp.both"
57 then
58 echo "# Graduated to both $m $and_or_thru master"
59 while read branch
61 d=$(git describe $branch)
62 echo "$(git show -s --format='%ct' "$branch") $branch ;# $d"
63 done <"$tmp.both" |
64 sort -r -n |
65 sed -e 's/^[0-9]* //' \
66 -e 's/^/git branch -d /'
67 echo
68 cat "$tmp.known" "$tmp.both" | sort >"$tmp.next"
69 mv "$tmp.next" "$tmp.known"
71 done
73 comm -13 "$tmp.maint" "$tmp.master" |
75 while read topic
77 t=$(find_last_tip $topic master) &&
78 test -n "$t" &&
79 m=$(git rev-parse --verify "$t^1") &&
80 test -n "$m" || continue
82 # NEEDSWORK: this misses repeated merges
84 # o---o---maint
85 # /
86 # .---o---o topic
87 # / \ \
88 # ---o---o---*---*---master
90 tsize=$(git rev-list "$m..$topic" | wc -l)
91 rsize=$(git rev-list "maint..$topic" | wc -l)
93 if test $tsize -eq $rsize
94 then
95 s=$(git show -s --pretty="tformat:%ct %H" $t)
96 echo "$s $topic"
97 else
98 s=$(git show -s --pretty="tformat:%ct %H" $t)
99 echo >&3 "$s $topic"
101 done 3>"$tmp.unmergeable" >"$tmp.mergeable"
103 if test -s "$tmp.unmergeable"
104 then
105 echo ": # Graduated to master; unmergeable to maint"
106 sort -n "$tmp.unmergeable" |
107 while read timestamp merge topic
109 git show -s --pretty="format:: # %h %cd" $merge
110 echo "git branch -d $topic"
111 done
112 echo
114 if test -s "$tmp.mergeable"
115 then
116 sort -n "$tmp.mergeable" |
117 while read timestamp merge topic
120 git show -s --pretty="format:%h %cd" $merge
121 git log --pretty=oneline --abbrev-commit maint..$topic
123 sed -e 's/^/: # /'
124 maint=maint
125 these=$(git rev-list maint..$topic)
126 for m in $old_maint maint
128 those=$(git rev-list $m..$topic)
129 if test "z$these" = "z$those"
130 then
131 maint=$m
132 break
134 done
136 echo "git checkout $maint && git merge $topic"
137 echo
138 done