Files
Daniel P. Berrangé 6cd6c8381e gitlab: use --emacs --quiet for checkpatch.pl instead of --terse
The default checkpatch.pl output includes a lot of "progress"
information...

   NN/MM Checking commit HASH (SUBJECT)
   total: 0 errors, 0 warnings, 105 lines checked

for large patch series, this results in alot of noise from
clean patches (which are the common case), obscuring the
info about the patch violations.

Since the alerts from gitlab job failures only include the
last few lines of log output, we want the checkpatch.pl
output to be highly relevant to the failure.

We previously addressed that by adding use of the --terse
flag in 7025111a19, but that
made the output a bit too terse. It no longer prints the
offending line of code, so understanding the CI job failure
now requires manually re-running checkpatch.pl locally.

Using the '--quiet' flag gets rid of the "Check commit HASH.."
messages which create noise, while adding '--emacs' causes
the WARNING/ERROR message lines to include the commit hash.

This is a more useful tradeoff for the CI job logs. The
output is limited to only patches which include code
violations, while still including the offending lines of
code in the output.

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2026-09-07 11:31:03 +01:00

60 lines
1.8 KiB
Python
Executable File

#!/usr/bin/env python3
#
# check-patch.py: run checkpatch.pl across all commits in a branch
#
# Copyright (C) 2020 Red Hat, Inc.
#
# SPDX-License-Identifier: GPL-2.0-or-later
import os
import os.path
import sys
import subprocess
namespace = "qemu-project"
if len(sys.argv) >= 2:
namespace = sys.argv[1]
cwd = os.getcwd()
reponame = os.path.basename(cwd)
repourl = "https://gitlab.com/%s/%s.git" % (namespace, reponame)
print(f"adding upstream git repo @ {repourl}")
# GitLab CI environment does not give us any direct info about the
# base for the user's branch. We thus need to figure out a common
# ancestor between the user's branch and current git master.
subprocess.check_call(["git", "remote", "add", "check-patch", repourl])
subprocess.check_call(["git", "fetch", "--refetch", "check-patch", "master"])
ancestor = subprocess.check_output(["git", "merge-base",
"check-patch/master", "HEAD"],
universal_newlines=True)
ancestor = ancestor.strip()
log = subprocess.check_output(["git", "log", "--format=%H %s",
ancestor + "..."],
universal_newlines=True)
subprocess.check_call(["git", "remote", "rm", "check-patch"])
if log == "":
print("\nNo commits since %s, skipping checks\n" % ancestor)
sys.exit(0)
errors = False
print("\nChecking all commits since %s...\n" % ancestor, flush=True)
# We don't want "noise" for clean patches, but do want to see
# the full commit hash for each violation, along with the
# offending patch content
ret = subprocess.run(["scripts/checkpatch.pl", "--emacs", "--quiet",
ancestor + "..."])
if ret.returncode != 0:
print(" ❌ FAIL one or more commits failed scripts/checkpatch.pl")
sys.exit(1)
sys.exit(0)