What's cooking (2013/01 #07)
[alt-git.git] / GRADUATED
blobc04040af8b0741a052126dd2ffc7fcb6d6f99b36
1 #!/bin/sh
3 base=
4 while :
5 do
6 case "$1" in
7 --base=*)
8 base=${1#*=} ;;
9 -*)
10 echo >&2 "Eh? $1"
11 exit 1 ;;
13 break ;;
14 esac
15 shift
16 done
18 if test -z "$base"
19 then
20 describe=$(git describe "master")
21 base=$(expr "$describe" : '\(.*\)-\([0-9]*\)-g[0-9a-f]*$') ||
22 base="$describe"
24 git rev-parse --verify "$base^0" >/dev/null 2>/dev/null || {
25 echo >&2 "Eh? where is your base?"
26 exit 1
30 topics=
31 leftover=
32 dothis=
33 LF='
36 defer () {
37 leftover="$leftover$1$LF"
40 dothis () {
41 dothis="$1$LF$LF$dothis"
44 one_topic () {
45 topic="$1" tip="$2" date="$3"
46 case " $topics" in *" $topic "*) return ;; esac
47 topics="$topics$topic "
49 mergeable=no ready=no label=
51 maint_count=$(git rev-list "maint..$tip" | wc -l)
52 if test "$maint_count" = 0
53 then
54 return ;# already merged
56 master_count=$(git rev-list "$base..$tip" | wc -l)
58 test $master_count = $maint_count && mergeable=yes
60 if current=$(git rev-parse --verify -q "$topic^0") &&
61 test "$current" = "$tip"
62 then
63 ready=yes
64 label="$topic"
65 elif test -z "$current"
66 then
67 ready=yes
68 label="$tip"
71 case "$mergeable,$ready" in
72 no,*)
73 defer "# $topic: not mergeable ($master_count vs $maint_count)"
75 yes,no)
76 topic_count=$(git rev-list "$base..$current" | wc -l)
77 defer "# $topic: not ready ($master_count vs $topic_count)"
79 yes,yes)
80 insn="$label # $master_count ($date)"
81 insn="$insn$LF$(git log --oneline "maint..$tip" | sed -e "s/^/# /")"
82 dothis "$insn"
84 esac
87 git log --first-parent --min-parents=2 --max-parents=2 \
88 --format='%ci %H %P %s' "$base..master" | {
89 while read date time zone commit parent tip subject
91 topic=$(expr "$subject" : "Merge branch '\(.*\)'$") || {
92 echo >&2 "Cannot parse $commit ($subject)"
93 continue
95 one_topic "$topic" "$tip" "$date"
96 done
97 echo "$leftover"
98 echo "$dothis"