scripts: allow checkpatch and get_maintainer in sparse checkouts
Subsystems (2)
PATCH 1/1 scripts: allow checkpatch and get_maintainer in sparse checkouts
checkpatch.pl and get_maintainer.pl currently reject sparse checkouts because top_of_kernel_tree() insists on top-level directories such as arch/, drivers/ and fs/ being present in the working tree.
That unnecessarily blocks common patch preparation workflows using partial clones or sparse checkouts, even when the files needed by these tools are present.
Relax the tree check to require only the top-level files and directories these scripts actually need so they continue to recognize full trees while also working from sparse checkouts.
--- scripts/checkpatch.pl | 4 ++-- scripts/get_maintainer.pl | 9 +-------- 2 files changed, 3 insertions(+), 10 deletions(-)
scripts/checkpatch.pl +2 -2
@@ -1397,10 +1397,10 @@ exit($exit); sub top_of_kernel_tree { my ($root) = @_; + # Allow sparse checkouts that still contain the files these scripts need. my @tree_check = ( "COPYING", "CREDITS", "Kbuild", "MAINTAINERS", "Makefile", - "README", "Documentation", "arch", "include", "drivers", - "fs", "init", "ipc", "kernel", "lib", "scripts", + "README", "Documentation", "scripts", ); foreach my $check (@tree_check) {
scripts/get_maintainer.pl +1 -8
@@ -1157,6 +1157,7 @@ sub top_of_kernel_tree { if ($lk_path ne "" && substr($lk_path,length($lk_path)-1,1) ne "/") { $lk_path .= "/"; } + # Allow sparse checkouts that still contain the files these scripts need. if ( (-f "${lk_path}COPYING") && (-f "${lk_path}CREDITS") && (-f "${lk_path}Kbuild")
@@ -1164,14 +1165,6 @@ sub top_of_kernel_tree { && (-f "${lk_path}Makefile") && (-f "${lk_path}README") && (-d "${lk_path}Documentation") - && (-d "${lk_path}arch") - && (-d "${lk_path}include") - && (-d "${lk_path}drivers") - && (-d "${lk_path}fs") - && (-d "${lk_path}init") - && (-d "${lk_path}ipc") - && (-d "${lk_path}kernel") - && (-d "${lk_path}lib") && (-d "${lk_path}scripts")) { return 1; }
Signature · 1 line
2.39.5 (Apple Git-154)
Joe Perches
maintainerQuoted 1 line · CaoRuichuang
checkpatch.pl and get_maintainer.pl currently reject sparse checkouts because
top_of_kernel_tree()insists on top-level directories such asarch/,drivers/andfs/being present in the working tree.
So add / use the command-line --notree option instead ?
PATCH v2 2/2 scripts: add sparse checkout regression test for checkpatch tools
In reply to CaoRuichuangAdd a shell-based regression test that exercises checkpatch.pl and get_maintainer.pl from a minimal sparse checkout style tree.
This locks in the sparse checkout behavior added by the preceding patch and catches future regressions in top_of_kernel_tree() handling for these scripts.
--- scripts/checkpatch-sparse-checkout-test.sh | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 scripts/checkpatch-sparse-checkout-test.sh
scripts/checkpatch-sparse-checkout-test.sh new file +48 -0
@@ -0,0 +1,48 @@ +#!/bin/sh -eu +# SPDX-License-Identifier: GPL-2.0 + +srctree=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +tmpdir=$(mktemp -d) +trap 'rm -rf "$tmpdir"' EXIT + +mkdir -p "$tmpdir/Documentation/process" "$tmpdir/scripts" + +for file in COPYING CREDITS Kbuild MAINTAINERS Makefile README; do + cp "$srctree/$file" "$tmpdir/$file" +done + +cp "$srctree/Documentation/process/submitting-patches.rst" \ + "$tmpdir/Documentation/process/" +cp "$srctree/scripts/checkpatch.pl" "$tmpdir/scripts/" +cp "$srctree/scripts/get_maintainer.pl" "$tmpdir/scripts/" +cp "$srctree/scripts/spdxcheck.py" "$tmpdir/scripts/" +cp "$srctree/scripts/spelling.txt" "$tmpdir/scripts/" + +git -C "$tmpdir" init -q +git -C "$tmpdir" add \ + COPYING CREDITS Kbuild MAINTAINERS Makefile README \ + Documentation/process/submitting-patches.rst \ + scripts/checkpatch.pl scripts/get_maintainer.pl \ + scripts/spdxcheck.py scripts/spelling.txt + +checkpatch_out=$( + cd "$tmpdir" && + perl scripts/checkpatch.pl --file Documentation/process/submitting-patches.rst \ + 2>&1 || true +) + +echo "$checkpatch_out" | + grep -q "Must be run from the top-level dir. of a kernel tree" && + exit 1 + +get_maintainer_out=$( + cd "$tmpdir" && + perl scripts/get_maintainer.pl -f Documentation/process/submitting-patches.rst \ + 2>&1 +) + +echo "$get_maintainer_out" | + grep -q "The current directory does not appear to be a linux kernel source tree" && + exit 1 + +echo "$get_maintainer_out" | grep -q "Jonathan Corbet" || exit 1
Signature · 1 line
2.39.5 (Apple Git-154)
v2 cover scripts: support sparse checkouts in checkpatch tools
In reply to CaoRuichuangcheckpatch.pl and get_maintainer.pl currently reject sparse checkouts because their top_of_kernel_tree() checks require top-level directories that may not be present in a sparse working tree.
This series relaxes that check to match the files the scripts actually need and adds a regression test to keep that behavior from regressing.
Changes in v2:
- add a regression test for sparse checkout handling in checkpatch.pl and get_maintainer.pl
CaoRuichuang (2):
scripts: allow checkpatch and get_maintainer in sparse checkouts
scripts: add sparse checkout regression test for checkpatch tools
scripts/checkpatch-sparse-checkout-test.sh | 48 ++++++++++++++++++++++ scripts/checkpatch.pl | 4 +- scripts/get_maintainer.pl | 9 +--- 3 files changed, 51 insertions(+), 10 deletions(-) create mode 100755 scripts/checkpatch-sparse-checkout-test.sh
Signature · 1 line
2.39.5 (Apple Git-154)
PATCH v2 1/2 scripts: allow checkpatch and get_maintainer in sparse checkouts
checkpatch.pl and get_maintainer.pl currently reject sparse checkouts because top_of_kernel_tree() insists on top-level directories such as arch/, drivers/ and fs/ being present in the working tree.
That unnecessarily blocks common patch preparation workflows using partial clones or sparse checkouts, even when the files needed by these tools are present.
Relax the tree check to require only the top-level files and directories these scripts actually need so they continue to recognize full trees while also working from sparse checkouts.
--- scripts/checkpatch.pl | 4 ++-- scripts/get_maintainer.pl | 9 +-------- 2 files changed, 3 insertions(+), 10 deletions(-)
scripts/checkpatch.pl +2 -2
@@ -1397,10 +1397,10 @@ exit($exit); sub top_of_kernel_tree { my ($root) = @_; + # Allow sparse checkouts that still contain the files these scripts need. my @tree_check = ( "COPYING", "CREDITS", "Kbuild", "MAINTAINERS", "Makefile", - "README", "Documentation", "arch", "include", "drivers", - "fs", "init", "ipc", "kernel", "lib", "scripts", + "README", "Documentation", "scripts", ); foreach my $check (@tree_check) {
scripts/get_maintainer.pl +1 -8
@@ -1157,6 +1157,7 @@ sub top_of_kernel_tree { if ($lk_path ne "" && substr($lk_path,length($lk_path)-1,1) ne "/") { $lk_path .= "/"; } + # Allow sparse checkouts that still contain the files these scripts need. if ( (-f "${lk_path}COPYING") && (-f "${lk_path}CREDITS") && (-f "${lk_path}Kbuild")
@@ -1164,14 +1165,6 @@ sub top_of_kernel_tree { && (-f "${lk_path}Makefile") && (-f "${lk_path}README") && (-d "${lk_path}Documentation") - && (-d "${lk_path}arch") - && (-d "${lk_path}include") - && (-d "${lk_path}drivers") - && (-d "${lk_path}fs") - && (-d "${lk_path}init") - && (-d "${lk_path}ipc") - && (-d "${lk_path}kernel") - && (-d "${lk_path}lib") && (-d "${lk_path}scripts")) { return 1; }
Signature · 1 line
2.39.5 (Apple Git-154)
Joe Perches
maintainerQuoted 1 line · CaoRuichuang
checkpatch.pl and get_maintainer.pl currently reject sparse checkouts because
top_of_kernel_tree()insists on top-level directories such asarch/,drivers/andfs/being present in the working tree.
I still think this is unnecessary and you should just add --no-tree to the command line / script invocations of these tools.
Hi Joe,
I re-tested this on a clean sparse checkout of the upstream tree.
Both tools work fine with --no-tree:
- scripts/checkpatch.pl --no-tree ...
- scripts/get_maintainer.pl --no-tree ...
So you are right that changing top_of_kernel_tree() is unnecessary for this workflow. I'll drop this series.
Thanks,
CaoRuichuang