From cc539b7b9f35a6bc0735a8a8a47e1a54aefaef0e Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Wed, 14 Aug 2024 16:53:27 +0300 Subject: gut-request-pull.sh: Lower git calls Optimize the commit checks by extracting the commit message once to operate greps on it, instead of calling git for each check. Signed-off-by: Laurent Pinchart --- git-request-pull.sh | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'git-request-pull.sh') diff --git a/git-request-pull.sh b/git-request-pull.sh index 4694130..2b4835c 100755 --- a/git-request-pull.sh +++ b/git-request-pull.sh @@ -63,18 +63,36 @@ check_commits() { local sob for commit in $(git rev-list ^$baserev $headrev) ; do - local author=$(git show --pretty='format:%an <%ae>' -s $commit) - local committer=$(git show --pretty='format:%cn <%ce>' -s $commit) + local msg=$(git cat-file commit "$commit") local summary=$(git show --pretty='format:%h ("%s")' -s $commit) - git show -s $commit | grep -Fqx " Signed-off-by: $author" || { - echo "Commit $summary is not signed off by author" - errors=$((errors+1)) - } - git show -s $commit | grep -Fqx " Signed-off-by: $committer" || { + # 1. The commit message shall have Signed-off-by lines + # corresponding the committer and the author. + local committer=$(echo "$msg" | grep '^committer ' | head -1 | \ + cut -d ' ' -f 2- | rev | cut -d ' ' -f 3- | rev) + if ! echo -E "$msg" | grep -Fqx "Signed-off-by: ${committer}" + then echo "Commit $summary is not signed off by committer" errors=$((errors+1)) - } + fi + + local author=$(echo "$msg" | grep '^author ' | head -1 | \ + cut -d ' ' -f 2- | rev | cut -d ' ' -f 3- | rev) + if ! echo -E "$msg" | grep -Fqx "Signed-off-by: ${author}" + then + echo "Commit $summary is not signed off by author" + errors=$((errors+1)) + fi + + # 2. Fixes: tags shall reference an ancestor commit. + local fixes=$(echo "$msg" | grep '^Fixes: ') + if [ -n "$fixes" ] ; then + fixes=$(echo "$fixes" | sed 's/^Fixes: \([0-9a-f]\+\) (.*)$/\1/') + git merge-base --is-ancestor $fixes $baserev >/dev/null 2>&1 || { + echo "Commit $summary contains a Fixes: tag referencing $fixes not present in history" + errors=$((errors+1)) + } + fi done if [[ $errors != 0 ]] ; then -- cgit v1.2.3