1#! /usr/bin/env bash 2 3check_tool_installed() { 4 if ! command -v $1 &> /dev/null 5 then 6 echo "Please install '$1' tool" 7 exit 1 8 fi 9} 10 11echoerr() { 12 printf "ERROR: %s\n" "$*" >&2 13} 14 15findtag() { 16 local commit_body tag person 17 commit_body=$1 18 tag=$2 19 person=$3 20 21 # trim duplicate spaces from commit body and person 22 match="$tag: $(echo $person | tr -s ' ')" 23 24 if [ -z "$(echo "$commit_body" | tr -s ' ' | grep -i "$match")" ]; then 25 echoerr "Tag is missing from commit body" 26 echoerr "" 27 echoerr "Looking for '"$match"' in: " 28 echoerr "-----------------------------------------------------" 29 echoerr "$commit_body" 30 echoerr "-----------------------------------------------------" 31 echoerr "" 32 return 0 33 fi 34 35 return 1 36} 37 38check_tool_installed bpfmt 39check_tool_installed clang-format-diff-19 40 41git fetch https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer.git 42 43git log --pretty='%h' FETCH_HEAD..HEAD | while read h; do 44 subject=$(git show -s --pretty='%s' "$h") 45 if [[ $subject != drm_hwcomposer:* ]] && [[ $subject != Revert* ]]; then 46 echoerr "Invalid subject prefix: $subject" 47 exit 1 48 fi 49 50 commit_body=$(git show -s --pretty=%b "$h") 51 52 author=$(git show -s --format='%an <%ae>' "$h") 53 if findtag "$commit_body" "Signed-off-by" "$author"; then 54 echoerr "Author SoB tag is missing from commit $h" 55 exit 1 56 fi 57 58 committer=$(git show -s --format='%cn <%ce>' "$h") 59 if findtag "$commit_body" "Signed-off-by" "$committer"; then 60 echoerr "Committer SoB tag is missing from commit $h" 61 exit 1 62 fi 63 64 git diff -U0 "$h" -- | clang-format-diff-19 -p 1 -style=file > /tmp/format-fixup.patch 65 if [ -s /tmp/format-fixup.patch ]; then 66 cat /tmp/format-fixup.patch >&2 67 exit 1 68 fi 69 70 find -name "*.bp" -exec bpfmt -d -s {} \; > /tmp/bpfmt.patch 71 if [ -s /tmp/bpfmt.patch ]; then 72 cat /tmp/bpfmt.patch >&2 73 exit 1 74 fi 75done 76