xref: /dpdk/devtools/git-log-fixes.sh (revision 4e30ead5e7ca886535e2b30632b2948d2aac1681)
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
33print_usage ()
34{
35	echo "usage: $(basename $0) [-h] <git_range>"
36}
37
38print_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
49usage_error () # <message>
50{
51	echo "$*" >&2
52	print_usage >&2
53	exit 1
54}
55
56while getopts h ARG ; do
57	case $ARG in
58		h ) print_help ; exit 0 ;;
59		? ) print_usage >&2 ; exit 1 ;;
60	esac
61done
62shift $(($OPTIND - 1))
63[ $# -ge 1 ] || usage_error 'range argument required'
64range="$*"
65
66# get major release version of a commit
67commit_version () # <hash>
68{
69	tag=$(git tag -l --contains $1 | 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
79origin_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
86origin_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
107stable_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
116git log --oneline --reverse $range |
117while read id headline ; do
118	origins=$(origin_filter $id)
119	[ -n "$origins" ] || echo "$headline" | grep -q fix || continue
120	version=$(commit_version $id)
121	if [ -n "$origins" ] ; then
122		origver="$(origin_version $origins)"
123		[ -n "$origver" ] || continue
124		# ignore fix of bug introduced in the same release
125		! echo "$origver" | grep -q "^$version" || continue
126	else
127		origver='N/A'
128	fi
129	stable=$(stable_tag $id)
130	printf '%s %7s %s %s (%s)\n' $version $id $stable "$headline" "$origver"
131done
132