devtools: fix checkpatch header retrieval from stdin

When passing the patch to checkpatches.sh through stdin, the subject is
retrieved by reading the input until a "Subject:" entry is found. The
rest of the input is piped to checkpatch.pl.

Since the "From:" line is before the "Subject:" line, it won't be sent to
checkpatch.pl, which won't be able to get the author of the commit.
The following error will appear:

ERROR:NO_AUTHOR_SIGN_OFF: Missing Signed-off-by: line by nominal patch author ''

Do the subject lookup on the temporary file instead of stdin, and
send the whole lines to checkpatch.pl.

The problem is visible since the introduction of this check in linux
checkpatch.pl in version 4.19 (see link below).

Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=cd2614967d8b
Fixes: 8005feef42 ("scripts: add standard input to checkpatch")
Cc: stable@dpdk.org

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
Reviewed-by: Thomas Monjalon <thomas@monjalon.net>
This commit is contained in:
Olivier Matz 2022-09-29 14:04:03 +02:00 committed by Thomas Monjalon
parent 830bf2a04f
commit 9cb8326456

View File

@ -284,12 +284,12 @@ print_headline() { # <title>
total=0
status=0
check () { # <patch> <commit> <title>
check () { # <patch-file> <commit>
local ret=0
local subject=''
headline_printed=false
total=$(($total + 1))
! $verbose || print_headline "$3"
if [ -n "$1" ] ; then
tmpinput=$1
else
@ -304,10 +304,14 @@ check () { # <patch> <commit> <title>
fi
fi
# Subject can be on 2 lines
subject=$(sed '/^Subject: */!d;s///;N;s,\n[[:space:]]\+, ,;s,\n.*,,;q' "$tmpinput")
! $verbose || print_headline "$subject"
! $verbose || printf 'Running checkpatch.pl:\n'
report=$($DPDK_CHECKPATCH_PATH $options "$tmpinput" 2>/dev/null)
if [ $? -ne 0 ] ; then
$headline_printed || print_headline "$3"
$headline_printed || print_headline "$subject"
printf '%s\n' "$report" | sed -n '1,/^total:.*lines checked$/p'
ret=1
fi
@ -315,7 +319,7 @@ check () { # <patch> <commit> <title>
! $verbose || printf '\nChecking API additions/removals:\n'
report=$($VALIDATE_NEW_API "$tmpinput")
if [ $? -ne 0 ] ; then
$headline_printed || print_headline "$3"
$headline_printed || print_headline "$subject"
printf '%s\n' "$report"
ret=1
fi
@ -323,7 +327,7 @@ check () { # <patch> <commit> <title>
! $verbose || printf '\nChecking forbidden tokens additions:\n'
report=$(check_forbidden_additions "$tmpinput")
if [ $? -ne 0 ] ; then
$headline_printed || print_headline "$3"
$headline_printed || print_headline "$subject"
printf '%s\n' "$report"
ret=1
fi
@ -331,7 +335,7 @@ check () { # <patch> <commit> <title>
! $verbose || printf '\nChecking __rte_experimental tags:\n'
report=$(check_experimental_tags "$tmpinput")
if [ $? -ne 0 ] ; then
$headline_printed || print_headline "$3"
$headline_printed || print_headline "$subject"
printf '%s\n' "$report"
ret=1
fi
@ -339,7 +343,7 @@ check () { # <patch> <commit> <title>
! $verbose || printf '\nChecking __rte_internal tags:\n'
report=$(check_internal_tags "$tmpinput")
if [ $? -ne 0 ] ; then
$headline_printed || print_headline "$3"
$headline_printed || print_headline "$subject"
printf '%s\n' "$report"
ret=1
fi
@ -347,7 +351,7 @@ check () { # <patch> <commit> <title>
! $verbose || printf '\nChecking release notes updates:\n'
report=$(check_release_notes "$tmpinput")
if [ $? -ne 0 ] ; then
$headline_printed || print_headline "$3"
$headline_printed || print_headline "$subject"
printf '%s\n' "$report"
ret=1
fi
@ -363,20 +367,10 @@ check () { # <patch> <commit> <title>
if [ -n "$1" ] ; then
for patch in "$@" ; do
# Subject can be on 2 lines
subject=$(sed '/^Subject: */!d;s///;N;s,\n[[:space:]]\+, ,;s,\n.*,,;q' "$patch")
check "$patch" '' "$subject"
check "$patch" ''
done
elif [ ! -t 0 ] ; then # stdin
subject=$(while read header value ; do
if [ "$header" = 'Subject:' ] ; then
IFS= read next
continuation=$(echo "$next" | sed -n 's,^[[:space:]]\+, ,p')
echo $value$continuation
break
fi
done)
check '' '' "$subject"
check '' ''
else
if [ $number -eq 0 ] ; then
commits=$(git rev-list --reverse $range)
@ -384,8 +378,7 @@ else
commits=$(git rev-list --reverse --max-count=$number HEAD)
fi
for commit in $commits ; do
subject=$(git log --format='%s' -1 $commit)
check '' $commit "$subject"
check '' $commit
done
fi
pass=$(($total - $status))