summaryrefslogtreecommitdiff
path: root/git-request-pull.sh
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-08-14 16:53:27 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-08-14 16:54:44 +0300
commitcc539b7b9f35a6bc0735a8a8a47e1a54aefaef0e (patch)
treea236bf8e4a4d80008a2188498789d9774265d949 /git-request-pull.sh
parentdd7fc0317dc4976d7c97a00e1904686be0e7d192 (diff)
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 <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'git-request-pull.sh')
-rwxr-xr-xgit-request-pull.sh34
1 files changed, 26 insertions, 8 deletions
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