Skip to content

Commit

Permalink
git: display checkpatch warnings in commit message comments
Browse files Browse the repository at this point in the history
Display the output of checkpatch in the comments
displayed below git commit message.

Change-Id: I31265807a3316641d88a320f6817cd63c1ad3c01
  • Loading branch information
tl-cea committed Apr 12, 2017
1 parent 9066ab5 commit 02c402b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 42 deletions.
28 changes: 16 additions & 12 deletions autogen.sh
Expand Up @@ -2,16 +2,20 @@
autoreconf --install

wdir=$(dirname $(readlink -m "$0"))
# if git prepare commit hook is a file, rename it to .orig
# and replace it with a link to the project hook
if [ -f "$wdir/.git/hooks/prepare-commit-msg" ]; then
echo "installing git prepare-commit hook"
mv -f "$wdir/.git/hooks/prepare-commit-msg" "$wdir/.git/hooks/prepare-commit-msg.save" || exit 1
ln -s '../../scripts/git_prepare_hook' "$wdir/.git/hooks/prepare-commit-msg" || exit 1
fi

if [ -f "$wdir/.git/hooks/pre-commit" ]; then
echo "installing git pre-commit hook"
mv -f "$wdir/.git/hooks/pre-commit" "$wdir/.git/hooks/pre-commit.save" || exit 1
ln -s '../../scripts/pre-commit' "$wdir/.git/hooks/pre-commit" || exit 1
fi
function install_hook
{
local src_file="$1"
local tgt_file="$2"

if [ ! -e "$wdir/.git/hooks/$tgt_file" ]; then
echo "installing git hook: $tgt_file"
ln -s "../../scripts/$src_file" "$wdir/.git/hooks/$tgt_file"
fi
if [ ! -x "$wdir/.git/hooks/$tgt_file" ]; then
chmod +x "$wdir/.git/hooks/$tgt_file"
fi
}

install_hook git_prepare_hook prepare-commit-msg
install_hook pre-commit pre-commit
34 changes: 4 additions & 30 deletions scripts/check_commit.sh
@@ -1,30 +1,13 @@
#!/bin/bash

dir=$(dirname $(readlink -m $0))

opt=""

function check_file
{
# check perenthesing
local said=0
git diff $opt $1 | grep "^+" | grep -v "^+++" | sed -e 's/^+//' > /tmp/code.$$
sed -e "s/( /(/g" -e "s/ )/)/g" /tmp/code.$$ > /tmp/indent.$$
diff /tmp/code.$$ /tmp/indent.$$ > /tmp/diff.$$
if (( $? )); then
echo "WARNINGS in $f:" && said=1
cat /tmp/diff.$$ | grep -E '^>|^<' | while read l; do
echo "$l"| sed -e 's/^</this line: /' -e 's/^>/should be: /'
done
echo
fi
# check spaces at EOL
while read l; do
(($said == 0)) && echo "WARNINGS in $f:" && said=1
# line
echo $l
#highlight
echo $l | sed -e "s/[^ ]/ /g" -e "s/ \$/ ^space at EOL/g"
done < <( grep -P "[\t ]\$" /tmp/code.$$ )
(($said == 1 )) && echo
exec git diff --cached --format=email $1 |
$dir/checkpatch.pl --patch --no-tree -q -
}

if [ "$1" ]; then
Expand All @@ -38,12 +21,3 @@ for f in $($cmd | grep -E 'added:|modified:|new file:' | cut -d ':' -f 2 | tr -d
done

exit 0
first=0
while read l; do
# line
echo $l
#highlight
echo $l | sed -e "s/[^ ]/ /g" -e "s/ \$/ ^space at EOL/g"
done < <( grep -e "[\t ]\$" /tmp/code.$$ )

rm -f /tmp/code.$$ /tmp/indent.$$ /tmp/diff.$$
2 changes: 2 additions & 0 deletions scripts/checkpatch.pl
Expand Up @@ -137,6 +137,8 @@ sub help {

# __packed if for kernel land
push @ignore, 'PREFER_PACKED';
# allow typedefs
push @ignore, 'NEW_TYPEDEFS';

foreach my $word (@ignore) {
$word =~ s/\s*\n?$//g;
Expand Down

0 comments on commit 02c402b

Please sign in to comment.