From f76d6ecc788a522916469f202f2e7f0d7cee1b77 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Thu, 30 Nov 2023 16:00:38 -0700 Subject: [PATCH] LU-7328 misc: no non-ASCII characters in commit messages Some commit messages have control characters, or fancy quotation marks, or mdash hyphens or similar, and this messes up the display of "git log" and other tools depending on the current locale and character set used in the terminal. Add a check into commit-msg to reject commit messages that have non-ASCII characters. This does not apply to characters used in the Signed-off-by: or similar fields that list people's names. Test-Parameters: trivial Signed-off-by: Andreas Dilger Change-Id: I99d0954a68f8a5391195553ebf4b69181b6991f2 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/53304 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Timothy Day Reviewed-by: Arshad Hussain Reviewed-by: Oleg Drokin --- contrib/git-hooks/commit-msg | 24 ++++++++++++++++++++---- contrib/git-hooks/tests/commit.nonascii | 29 +++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 contrib/git-hooks/tests/commit.nonascii diff --git a/contrib/git-hooks/commit-msg b/contrib/git-hooks/commit-msg index abb666a..d8d400e 100755 --- a/contrib/git-hooks/commit-msg +++ b/contrib/git-hooks/commit-msg @@ -71,7 +71,7 @@ die() { # Called when doing the final "wrap up" clause because we've found # one of the tagged lines that belongs in the final section. # -function ck_wrapup() { +function ck_wrapup_started() { $IS_WRAPPING_UP && return $HAS_LAST_BLANK || error "blank line must preceed signoff section" @@ -82,8 +82,19 @@ function ck_wrapup() { IS_WRAPPING_UP=true } +function ck_is_ascii() { + LANG=C + [[ "${LINE//[![:alnum:][:blank:][:punct:]]/}" == "$LINE" ]] || + error "non-printable characters in '$LINE'" +} + +function ck_wrapup() { + ck_wrapup_started + ck_is_ascii +} + function do_signoff() { - ck_wrapup + ck_wrapup_started # Signed-off-by: First Last local txt=$(echo "${LINE#*: }" | grep -E "${EMAILPAT}") if (( ${#txt} == 0 )); then @@ -125,7 +136,7 @@ function do_fixes() { # All "emails" lines specify a person and email address # function do_emails() { - ck_wrapup + ck_wrapup_started local txt=$(echo "${LINE#*: }" | grep -E "${EMAILPAT}") (( ${#txt} == 0 )) && error "${LINE%: *} invalid name and email" } @@ -134,6 +145,8 @@ function do_emails() { # function do_change() { local url="${LINE#*change: }" + + ck_is_ascii [[ $url =~ $GERRIT_URL/[0-9][0-9][0-9] ]] || error "bad Gerrit URL, use '$GERRIT_URL/nnnnn' format" } @@ -143,6 +156,8 @@ function do_change() { # function do_commit() { local val=${LINE#*commit: } + + ck_is_ascii if [[ $val =~ TBD ]]; then val=${val#TBD (from } val=${val%)} @@ -183,6 +198,7 @@ function do_default_line() { HAS_BODY=true fi HAS_LAST_BLANK=false + ck_is_ascii } # Add a new unique Change-Id @@ -240,7 +256,7 @@ for full details. A good example of a valid commit comment is: changed (including important functions that were changed, if this is useful to understand the patch, and for easier searching). Performance patches should quanify the improvements being seen. - Wrap lines at/under $WIDTH_REG columns. + Wrap lines at/under $WIDTH_REG columns. Only ASCII text allowed. Optionally, if the patch is backported from master, include links to the original patch to simplify tracking it across branches/repos: diff --git a/contrib/git-hooks/tests/commit.nonascii b/contrib/git-hooks/tests/commit.nonascii new file mode 100644 index 0000000..1a453f9 --- /dev/null +++ b/contrib/git-hooks/tests/commit.nonascii @@ -0,0 +1,29 @@ +commit a3a51806ef361f55421a1bc07f64c78730ae50d5 +Author: Shaun Tancheff +AuthorDate: Sun Jan 22 11:43:29 2023 -0600 +Commit: Oleg Drokin +CommitDate: Wed Feb 8 06:26:57 2023 +0000 + +LU-16118 build: Workaround __write_overflow_field errors + +Linux commit v5.17-rc3-1-gf68f2ff91512 + fortify: Detect struct member overflows in memcpy() at compile-time + +memcpy and memset of collections of struct members +will trigger: + +error: call to ‘__write_overflow_field’ declared with attribute + warning: detected write beyond size of field (1st parameter); + maybe use struct_group()? + [-Werror] __write_overflow_field(p_size_field, size); + +Test-Parameters: trivial +HPE-bug-id: LUS-11194 +Signed-off-by: Shaun Tancheff +Change-Id: Iacd1ab03d1b90ce62b5d7b65e1cd518a5f7981f2 +Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/48364 +Reviewed-by: Petros Koutoupis +Reviewed-by: Oleg Drokin +Reviewed-by: jsimmons +Reviewed-by: Andreas Dilger +Reviewed-by: Neil Brown -- 1.8.3.1