From 7d28813d730fd2d4216a3b3365b0a5ec6f627d51 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Wed, 17 Jan 2024 23:06:39 +0100 Subject: check-patches: factorize code Reduce code duplication. Signed-off-by: Robin Jarry Reviewed-by: Bence Ferdinandy --- contrib/check-patches | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'contrib') diff --git a/contrib/check-patches b/contrib/check-patches index 0fb2aa89..741dd5b8 100755 --- a/contrib/check-patches +++ b/contrib/check-patches @@ -12,28 +12,33 @@ if [ "$total" -eq 0 ]; then fi n=0 +title= +fail=false + +err() { + echo "error [PATCH $n/$total] '$title' $*" >&2 + fail=true +} + for rev in $revisions; do n=$((n + 1)) title=$(git log --format='%s' -1 "$rev") fail=false if [ "$(echo "$title" | wc -m)" -gt 72 ]; then - echo "error [PATCH $n/$total] '$title' title is longer than 72 characters, please make it shorter" >&2 - fail=true + err "title is longer than 72 characters, please make it shorter" fi author=$(git log --format='%an <%ae>' -1 "$rev") - if ! git log --format="%(trailers:key=Signed-off-by,only,valueonly)" -1 "$rev" | + if ! git log --format="%(trailers:key=Signed-off-by,only,valueonly,unfold)" -1 "$rev" | grep -qFx "$author"; then - echo "error [PATCH $n/$total] '$title' 'Signed-off-by: $author' trailer is missing" >&2 - fail=true + err "'Signed-off-by: $author' trailer is missing" fi body=$(git log --format='%b' -1 "$rev") body=${body%$(git log --format='%(trailers)' -1 "$rev")} if [ "$(echo "$body" | wc -w)" -lt 3 ]; then - echo "error [PATCH $n/$total] '$title' body has less than three words, please describe your changes" >&2 - fail=true + err "body has less than three words, please describe your changes" fi if [ "$fail" = true ]; then -- cgit