What's cooking (2012/11 #04)
[alt-git.git] / GRADUATED
blobaea874f5ac77cff0baaced0595269bc3512c1120
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 --always $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 sort -V -k 6,6
68 echo
69 cat "$tmp.known" "$tmp.both" | sort >"$tmp.next"
70 mv "$tmp.next" "$tmp.known"
72 done
74 comm -13 "$tmp.maint" "$tmp.master" |
76 while read topic
78 t=$(find_last_tip $topic master) &&
79 test -n "$t" &&
80 m=$(git rev-parse --verify "$t^1") &&
81 test -n "$m" || continue
83 # NEEDSWORK: this misses repeated merges
85 # o---o---maint
86 # /
87 # .---o---o topic
88 # / \ \
89 # ---o---o---*---*---master
91 tsize=$(git rev-list "$m..$topic" | wc -l)
92 rsize=$(git rev-list "maint..$topic" | wc -l)
94 if test $tsize -eq $rsize
95 then
96 s=$(git show -s --pretty="tformat:%ct %H" $t)
97 echo "$s $topic"
98 else
99 s=$(git show -s --pretty="tformat:%ct %H" $t)
100 echo >&3 "$s $topic"
102 done 3>"$tmp.unmergeable" >"$tmp.mergeable"
104 if test -s "$tmp.unmergeable"
105 then
106 echo ": # Graduated to master; unmergeable to maint"
107 sort -n "$tmp.unmergeable" |
108 while read timestamp merge topic
110 git show -s --pretty="format:: # %h %cd" $merge
111 echo "git branch -d $topic"
112 done
113 echo
115 if test -s "$tmp.mergeable"
116 then
117 sort -n "$tmp.mergeable" |
118 while read timestamp merge topic
121 git show -s --pretty="format:%h %cd" $merge
122 git log --pretty=oneline --abbrev-commit maint..$topic
124 sed -e 's/^/: # /'
125 maint=maint
126 these=$(git rev-list maint..$topic)
127 for m in $old_maint maint
129 those=$(git rev-list $m..$topic)
130 if test "z$these" = "z$those"
131 then
132 maint=$m
133 break
135 done
137 echo "git checkout $maint && git merge $topic"
138 echo
139 done