2020-09-18 16:29:01 +03:00
|
|
|
#!/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)
|
|
|
|
|
2024-10-23 14:33:58 +03:00
|
|
|
print(f"adding upstream git repo @ {repourl}")
|
2020-09-18 16:29:01 +03:00
|
|
|
# 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])
|
2024-10-23 14:33:58 +03:00
|
|
|
subprocess.check_call(["git", "fetch", "check-patch", "master"])
|
2020-09-18 16:29:01 +03:00
|
|
|
|
|
|
|
ancestor = subprocess.check_output(["git", "merge-base",
|
|
|
|
"check-patch/master", "HEAD"],
|
|
|
|
universal_newlines=True)
|
|
|
|
|
|
|
|
ancestor = ancestor.strip()
|
|
|
|
|
2020-10-21 19:31:34 +03:00
|
|
|
log = subprocess.check_output(["git", "log", "--format=%H %s",
|
|
|
|
ancestor + "..."],
|
|
|
|
universal_newlines=True)
|
|
|
|
|
2020-09-18 16:29:01 +03:00
|
|
|
subprocess.check_call(["git", "remote", "rm", "check-patch"])
|
|
|
|
|
2020-10-21 19:31:34 +03:00
|
|
|
if log == "":
|
|
|
|
print("\nNo commits since %s, skipping checks\n" % ancestor)
|
|
|
|
sys.exit(0)
|
|
|
|
|
2020-09-18 16:29:01 +03:00
|
|
|
errors = False
|
|
|
|
|
2020-11-13 20:44:04 +03:00
|
|
|
print("\nChecking all commits since %s...\n" % ancestor, flush=True)
|
2020-09-18 16:29:01 +03:00
|
|
|
|
2020-11-13 20:44:04 +03:00
|
|
|
ret = subprocess.run(["scripts/checkpatch.pl", "--terse", ancestor + "..."])
|
2020-09-18 16:29:01 +03:00
|
|
|
|
|
|
|
if ret.returncode != 0:
|
|
|
|
print(" ❌ FAIL one or more commits failed scripts/checkpatch.pl")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
sys.exit(0)
|