What's cooking (2021/04 #04)
[git] / ML
1 #!/bin/sh
2 # Merge later...
3
4 MASTER=master
5
6 : "${target:=maint}" "${here:=$MASTER}"
7
8 # Read from RelNotes and find mergeable topics
9 search_topics () {
10         tmp=/tmp/ML.$$
11         trap 'rm -f "$tmp"' 0
12         git rev-list --parents --first-parent $target..$here >"$tmp"
13
14         x40='[0-9a-f]'
15         x40="$x40$x40$x40$x40$x40"
16         x40="$x40$x40$x40$x40$x40$x40$x40$x40"
17         sed -n -e 's/^   (merge \([0-9a-f]*\) \([^ ]*\) later to maint.*/\1 \2/p' |
18         while read sha1 topic
19         do
20                 if ! full_sha1=$(git rev-parse --verify "$sha1")
21                 then
22                         echo >&2 "Not found: $sha1 $topic"
23                         continue
24                 fi
25
26                 comment=
27                 if ! git show-ref --quiet --verify "refs/heads/$topic"
28                 then
29                         comment="$topic gone"
30                         tip=$full_sha1 topic=$sha1
31                 elif tip=$(git rev-parse --verify "refs/heads/$topic") &&
32                      test "$tip" != "$full_sha1"
33                 then
34                         echo >&2 "$topic # $tip moved from $sha1"
35                         continue
36                 fi
37
38                 ago= lg=0
39                 fp=$(
40                     sed -ne "s/^\($x40\) $x40 $tip"'$/\1/p' "$tmp"
41                 ) &&
42                 test -n "$fp" &&
43                 ago=$(
44                     git show -s --format='%ar' $fp
45                 ) &&
46                 lg=$(git log --oneline $target..$tip | wc -l)
47                 if test $lg != 0
48                 then
49                         echo "$topic # $lg${ago+ ($ago)}${comment+ $comment}"
50                 else
51                         echo "# $topic already merged${ago+ ($ago)}${comment+ $comment}"
52                 fi
53         done
54 }
55
56 while   case "$#,$1" in
57         0,*)
58                 break ;;
59         *,-t)
60                 target=${2?"-t target???"}
61                 git show-ref --quiet --verify "refs/heads/$target" || {
62                         echo >&2 "$target: no such branch"
63                         exit 1
64                 }
65                 shift ;;
66         *)
67                 break ;;
68         esac
69 do
70         shift
71 done
72
73 case $# in
74 0)
75         search_topics
76         exit $?
77         ;;
78 esac
79
80 for topic
81 do
82         sha1=$(git rev-parse --short $topic)
83         echo "   (merge $sha1 $topic later to maint)."
84 done
85