xref: /dpdk/devtools/git-log-fixes.sh (revision eb6d5a0af9a05bf940ba19ec1ddbe575b5e7540b)
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	# use current branch as history reference
70	local refbranch=$(git rev-parse --abbrev-ref HEAD)
71	local tag=$( (git tag -l --contains $1 --merged $refbranch 2>&- ||
72		# tag --merged option has been introduced in git 2.7.0
73		# below is a fallback in case of old git version
74		for t in $(git tag -l --contains $1) ; do
75			git branch $refbranch --contains $t |
76			sed "s,.\+,$t,"
77		done) |
78		head -n1)
79	if [ -z "$tag" ] ; then
80		# before -rc1 tag of release in progress
81		make showversion | cut -d'.' -f-2
82	else
83		echo $tag | sed 's,^v,,' | sed 's,-rc.*,,'
84	fi
85}
86
87# get bug origin hashes of a fix
88origin_filter () # <hash>
89{
90	git log --format='%b' -1 $1 |
91	sed -n 's,^ *\([Ff]ixes\|[Rr]everts\): *\([0-9a-f]*\).*,\2,p'
92}
93
94# get oldest major release version of bug origins
95origin_version () # <origin_hash> ...
96{
97	for origin in $* ; do
98		# check hash is valid
99		git rev-parse -q --verify $1 >&- || continue
100		# get version of this bug origin
101		local origver=$(commit_version $origin)
102		local roothashes="$(origin_filter $origin)"
103		if [ -n "$roothashes" ] ; then
104			# look chained fix of fix recursively
105			local rootver="$(origin_version $roothashes)"
106			[ -n "$rootver" ] || continue
107			echo "$rootver (partially fixed in $origver)"
108		else
109			echo "$origver"
110		fi
111	# filter the oldest origin
112	done | sort -uV | head -n1
113}
114
115# print a marker for stable tag presence
116stable_tag () # <hash>
117{
118	if git log --format='%b' -1 $1 | grep -qi '^Cc: *stable@dpdk.org' ; then
119		echo 'S'
120	else
121		echo '-'
122	fi
123}
124
125git log --oneline --reverse $range |
126while read id headline ; do
127	origins=$(origin_filter $id)
128	stable=$(stable_tag $id)
129	[ "$stable" = "S" ] || [ -n "$origins" ] || echo "$headline" | grep -q fix || continue
130	version=$(commit_version $id)
131	if [ -n "$origins" ] ; then
132		origver="$(origin_version $origins)"
133		[ -n "$origver" ] || continue
134		# ignore fix of bug introduced in the same release
135		! echo "$origver" | grep -q "^$version" || continue
136	else
137		origver='N/A'
138	fi
139	printf '%s %7s %s %s (%s)\n' $version $id $stable "$headline" "$origver"
140done
141