5800687419c881eae36c119163f9847c662c6dba
[deb_dpdk.git] / devtools / git-log-fixes.sh
1 #! /bin/sh -e
2
3 # BSD LICENSE
4 #
5 # Copyright 2016 6WIND S.A.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 #
11 #   * Redistributions of source code must retain the above copyright
12 #     notice, this list of conditions and the following disclaimer.
13 #   * Redistributions in binary form must reproduce the above copyright
14 #     notice, this list of conditions and the following disclaimer in
15 #     the documentation and/or other materials provided with the
16 #     distribution.
17 #   * Neither the name of 6WIND S.A. nor the names of its
18 #     contributors may be used to endorse or promote products derived
19 #     from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 print_usage ()
34 {
35         echo "usage: $(basename $0) [-h] <git_range>"
36 }
37
38 print_help ()
39 {
40         print_usage
41         cat <<- END_OF_HELP
42
43         Find fixes to backport on previous versions.
44         It looks for the word "fix" in the headline or a tag "Fixes" or "Reverts".
45         The oldest bug origin is printed as well as partially fixed versions.
46         END_OF_HELP
47 }
48
49 usage_error () # <message>
50 {
51         echo "$*" >&2
52         print_usage >&2
53         exit 1
54 }
55
56 while getopts h ARG ; do
57         case $ARG in
58                 h ) print_help ; exit 0 ;;
59                 ? ) print_usage >&2 ; exit 1 ;;
60         esac
61 done
62 shift $(($OPTIND - 1))
63 [ $# -ge 1 ] || usage_error 'range argument required'
64 range="$*"
65
66 # get major release version of a commit
67 commit_version () # <hash>
68 {
69         tag=$(git tag -l --contains $1 --merged | head -n1)
70         if [ -z "$tag" ] ; then
71                 # before -rc1 tag of release in progress
72                 make showversion | cut -d'.' -f-2
73         else
74                 echo $tag | sed 's,^v,,' | sed 's,-rc.*,,'
75         fi
76 }
77
78 # get bug origin hashes of a fix
79 origin_filter () # <hash>
80 {
81         git log --format='%b' -1 $1 |
82         sed -n 's,^ *\([Ff]ixes\|[Rr]everts\): *\([0-9a-f]*\).*,\2,p'
83 }
84
85 # get oldest major release version of bug origins
86 origin_version () # <origin_hash> ...
87 {
88         for origin in $* ; do
89                 # check hash is valid
90                 git rev-parse -q --verify $1 >&- || continue
91                 # get version of this bug origin
92                 local origver=$(commit_version $origin)
93                 local roothashes="$(origin_filter $origin)"
94                 if [ -n "$roothashes" ] ; then
95                         # look chained fix of fix recursively
96                         local rootver="$(origin_version $roothashes)"
97                         [ -n "$rootver" ] || continue
98                         echo "$rootver (partially fixed in $origver)"
99                 else
100                         echo "$origver"
101                 fi
102         # filter the oldest origin
103         done | sort -uV | head -n1
104 }
105
106 # print a marker for stable tag presence
107 stable_tag () # <hash>
108 {
109         if git log --format='%b' -1 $1 | grep -qi '^Cc: *stable@dpdk.org' ; then
110                 echo 'S'
111         else
112                 echo '-'
113         fi
114 }
115
116 git log --oneline --reverse $range |
117 while read id headline ; do
118         origins=$(origin_filter $id)
119         stable=$(stable_tag $id)
120         [ "$stable" = "S" ] || [ -n "$origins" ] || echo "$headline" | grep -q fix || continue
121         version=$(commit_version $id)
122         if [ -n "$origins" ] ; then
123                 origver="$(origin_version $origins)"
124                 [ -n "$origver" ] || continue
125                 # ignore fix of bug introduced in the same release
126                 ! echo "$origver" | grep -q "^$version" || continue
127         else
128                 origver='N/A'
129         fi
130         printf '%s %7s %s %s (%s)\n' $version $id $stable "$headline" "$origver"
131 done