Add Meta/GRADUATED

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