tools/verifygitlog.py: Sync with changes from the main repo.

This includes the following commits:

- Allow long co-author and sign-off names.
- Disallow a leading slash in commit subject line.
- Apply stricter rules on git subject line.
- Show invalid commit subjects in quotes.

Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
pull/1007/head
Daniël van de Giessen 2025-05-14 18:08:22 +02:00
rodzic 68e0dfce0a
commit 3a4f7fc61b
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 9F0EF4D3441C8163
1 zmienionych plików z 30 dodań i 3 usunięć

Wyświetl plik

@ -49,7 +49,7 @@ def git_log(pretty_format, *args):
def diagnose_subject_line(subject_line, subject_line_format, err):
err.error("Subject line: " + subject_line)
err.error('Subject line: "' + subject_line + '"')
if not subject_line.endswith("."):
err.error('* must end with "."')
if not re.match(r"^[^!]+: ", subject_line):
@ -98,20 +98,47 @@ def verify_message_body(raw_body, err):
if len(subject_line) >= 73:
err.error("Subject line must be 72 or fewer characters: " + subject_line)
# Do additional checks on the prefix of the subject line.
verify_subject_line_prefix(subject_line.split(": ")[0], err)
# Second one divides subject and body.
if len(raw_body) > 1 and raw_body[1]:
err.error("Second message line must be empty: " + raw_body[1])
# Message body lines.
for line in raw_body[2:]:
# Long lines with URLs are exempt from the line length rule.
if len(line) >= 76 and "://" not in line:
# Long lines with URLs or human names are exempt from the line length rule.
if len(line) >= 76 and not (
"://" in line
or line.startswith("Co-authored-by: ")
or line.startswith("Signed-off-by: ")
):
err.error("Message lines should be 75 or less characters: " + line)
if not raw_body[-1].startswith("Signed-off-by: ") or "@" not in raw_body[-1]:
err.error('Message must be signed-off. Use "git commit -s".')
def verify_subject_line_prefix(prefix, err):
ext = (".c", ".h", ".cpp", ".js", ".rst", ".md")
if prefix.startswith((".", "/")):
err.error('Subject prefix cannot begin with "." or "/".')
if prefix.endswith("/"):
err.error('Subject prefix cannot end with "/".')
if prefix.startswith("ports/"):
err.error(
'Subject prefix cannot begin with "ports/", start with the name of the port instead.'
)
if prefix.endswith(ext):
err.error(
"Subject prefix cannot end with a file extension, use the main part of the filename without the extension."
)
def run(args):
verbose("run", *args)