git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/4] t/chainlint: add --greplint to run greplint

From
Tyler Cipriani <tyler@tylercipriani.com>
Date
Oct 25, 2026, 06:35 UTC
Message-ID
<20261025063508.3026136-5-tyler@tylercipriani.com>
In-Reply-To
<20261025063508.3026136-1-tyler@tylercipriani.com>

Save duplicate file handling and parsing work (and gain parallel file processing) by teaching chainlint to do the work of greplint.

Add --greplint option to chainlint.pl so that it passes tokens to GrepLintParser::check_tokens(). This change allows chainlint.pl to do greplint checks after chainlint has done all the hard work of file handling and parsing.

Update Makefile with new target that invokes chainlint.pl --greplint. In the common case, make test-lint will use the new chainlint target. Continue to respect and set GIT_TEST_CHAIN_LINT=0.

Ensure test-chainlint/test-greplint run on the same set of test files, which expands the set for both.

Local laptop testing shows make test-lint went from around 4.5s before this change to less than 1s after (with -j$(nproc) where nproc == 16).

Reported-by: Junio C Hamano <gitster@pobox.com>
Suggested-by: Jeff King <peff@peff.net>
Signed-off-by: Tyler Cipriani <tyler@tylercipriani.com>
---
 t/Makefile     | 30 ++++++++++++++++++++++--------
 t/chainlint.pl | 24 ++++++++++++++++++++----
 2 files changed, 42 insertions(+), 12 deletions(-)
diff --git a/t/Makefile b/t/Makefile
index e3249879c4..bfe861f6e0 100644
--- a/t/Makefile
+++ b/t/Makefile
@@ -56,9 +56,9 @@ UNIT_TEST_PROGRAMS += unit-tests/bin/unit-tests$(X)
 UNIT_TESTS = $(sort $(UNIT_TEST_PROGRAMS))
 UNIT_TESTS_NO_DIR = $(notdir $(UNIT_TESTS))
 
-# `test-chainlint` (which is a dependency of `test-lint`, `test` and `prove`)
-# checks all tests in all scripts via a single invocation, so tell individual
-# scripts not to run the external "chainlint.pl" script themselves
+# `test-chainlint-greplint` (which is a dependency of `test-lint`, `test`, and
+# `prove`) checks all tests in all scripts via a single invocation, so tell
+# individual scripts not to run the external "chainlint.pl" script themselves
 CHAINLINTSUPPRESS = GIT_TEST_EXT_CHAIN_LINT=0 && export GIT_TEST_EXT_CHAIN_LINT &&
 
 all:: $(DEFAULT_TEST_TARGET)
@@ -127,6 +127,7 @@ check-chainlint:
 clean-greplint:
 	$(RM) -r '$(GREPLINTTMP_SQ)'
 
+# chainlint --jobs=1 needed: parallel workers emit output in arbitrary order
 check-greplint:
 	@mkdir -p '$(GREPLINTTMP_SQ)' && \
 	'$(PERL_PATH_SQ)' greplint-cat.pl '$(GREPLINTTMP_SQ)' $(GREPLINTTESTS) && \
@@ -134,6 +135,11 @@ check-greplint:
 		$(patsubst %,greplint/%.test,$(GREPLINTTESTS)) \
 		>'$(GREPLINTTMP_SQ)'/actual 2>&1 || true; } && \
 	diff -u '$(GREPLINTTMP_SQ)'/expect '$(GREPLINTTMP_SQ)'/actual
+	@$(CHAINLINT) --greplint --jobs=1 \
+		$(patsubst %,greplint/%.test,$(GREPLINTTESTS)) 2>&1 | \
+		sed -e '/^# chainlint: /d' -e '/^[0-9][0-9]* /d' \
+		>'$(GREPLINTTMP_SQ)'/actual-chainlint && \
+	diff -u '$(GREPLINTTMP_SQ)'/expect '$(GREPLINTTMP_SQ)'/actual-chainlint
 
 check-meson:
 	@# awk acts up when trying to match single quotes, so we use \047 instead.
@@ -154,12 +160,16 @@ check-meson:
 test-lint: test-lint-duplicates test-lint-executable \
 	test-lint-filenames
 ifneq ($(PERL_PATH),)
-test-lint: test-lint-shell-syntax test-greplint
+test-lint: test-lint-shell-syntax
 else
 GIT_TEST_CHAIN_LINT = 0
 endif
 ifneq ($(GIT_TEST_CHAIN_LINT),0)
-test-lint: test-chainlint
+test-lint: test-chainlint-greplint
+else
+ifneq ($(PERL_PATH),)
+test-lint: test-greplint
+endif
 endif
 
 test-lint-duplicates:
@@ -176,7 +186,7 @@ test-lint-shell-syntax:
 	@'$(PERL_PATH_SQ)' check-non-portable-shell.pl $(T) $(THELPERS) $(TPERF)
 
 test-greplint:
-	@'$(PERL_PATH_SQ)' greplint.pl $(T) $(THELPERS) $(TPERF)
+	@'$(PERL_PATH_SQ)' greplint.pl $(T) $(THELPERS) $(TPERF) $(TINTEROP)
 
 test-lint-filenames:
 	@# We do *not* pass a glob to ls-files but use grep instead, to catch
@@ -186,8 +196,11 @@ test-lint-filenames:
 		test -z "$$bad" || { \
 		echo >&2 "non-portable file name(s): $$bad"; exit 1; }
 
+test-chainlint-greplint:
+	@$(CHAINLINT) --greplint $(T) $(THELPERS) $(TPERF) $(TINTEROP)
+
 test-chainlint:
-	@$(CHAINLINT) $(T) $(TLIBS) $(TPERF) $(TINTEROP)
+	@$(CHAINLINT) $(T) $(THELPERS) $(TPERF) $(TINTEROP)
 
 aggregate-results-and-cleanup: $(T)
 	$(MAKE) aggregate-results
@@ -204,7 +217,8 @@ perf:
 
 .PHONY: pre-clean $(T) aggregate-results clean valgrind perf \
 	check-chainlint clean-chainlint test-chainlint \
-	check-greplint clean-greplint test-greplint $(UNIT_TESTS)
+	check-greplint clean-greplint test-greplint \
+	test-chainlint-greplint $(UNIT_TESTS)
 
 .PHONY: libgit-sys-test libgit-rs-test
 libgit-sys-test:
diff --git a/t/chainlint.pl b/t/chainlint.pl
index cededf15ee..dda3617add 100755
--- a/t/chainlint.pl
+++ b/t/chainlint.pl
@@ -22,10 +22,13 @@
 my $jobs = -1;
 my $show_stats;
 my $emit_all;
+my $greplint;
 
 use File::Basename;
 do(dirname($0) . "/lib-shell-parser.pl")
 	or die "$0: failed to load lib-shell-parser.pl: $@$!\n";
+do(dirname($0) . "/lib-greplint.pl")
+	or die "$0: failed to load lib-greplint.pl: $@$!\n";
 
 # TestParser is a subclass of ShellParser which, beyond parsing shell script
 # code, is also imbued with semantic knowledge of test construction, and checks
@@ -147,9 +150,9 @@ sub format_problem {
 sub check_test {
 	my $self = shift @_;
 	my $title = ScriptParser::unwrap(shift @_);
-	my $body = shift @_;
-	my $lineno = $body->[3];
-	$body = ScriptParser::unwrap($body);
+	my $body_token = shift @_;
+	my $lineno = $body_token->[3];
+	my $body = ScriptParser::unwrap($body_token);
 	if ($body eq '-') {
 		my $herebody = shift @_;
 		$body = $herebody->{content};
@@ -160,6 +163,12 @@ sub check_test {
 	my @tokens = $parser->parse();
 	my $problems = $parser->{problems};
 	$self->{nerrs} += @$problems;
+	if ($greplint) {
+		my @grep_errors = GrepLintParser::check_tokens($self->{file},
+			$self->{raw_lines}, $body_token, $lineno, \@tokens);
+		push(@{$self->{greplint}}, @grep_errors);
+		$self->{nerrs} += @grep_errors;
+	}
 	return unless $emit_all || @$problems;
 	my $c = main::fd_colors(1);
 	my ($erropen, $errclose) = -t 1 ? ("$c->{rev}$c->{red}", $c->{reset}) : ('?!', '?!');
@@ -296,15 +305,21 @@ sub check_script {
 			$emit->("?!ERR?! $path: $!\n");
 			next;
 		}
-		my $s = do { local $/; <$fh> };
+		my @raw_lines = <$fh>;
 		close($fh);
+		my $s = join('', @raw_lines);
 		my $parser = ChainlintParser->new(\$s);
+		$parser->{file} = $path;
+		$parser->{raw_lines} = \@raw_lines;
+		$parser->{greplint} = [];
 		1 while $parser->parse_cmd();
 		if (@{$parser->{output}}) {
 			my $c = fd_colors(1);
 			my $s = join('', @{$parser->{output}});
 			$emit->("$c->{bold}$c->{blue}# chainlint: $path$c->{reset}\n" . $s);
 		}
+		$emit->(join('', map { "$_\n" } @{$parser->{greplint}}))
+			if @{$parser->{greplint}};
 		$ntests += $parser->{ntests};
 		$nerrs += $parser->{nerrs};
 	}
@@ -323,6 +338,7 @@ sub exit_code {
 Getopt::Long::Configure(qw{bundling});
 GetOptions(
 	"emit-all!" => \$emit_all,
+	"greplint!" => \$greplint,
 	"jobs|j=i" => \$jobs,
 	"stats|show-stats!" => \$show_stats) or die("option error\n");
 $jobs = ncores() if $jobs < 1;
-- 
2.47.3
Previous: Tyler Cipriani
Message 7 of 7 in “test-grep-lint is uncomfortably slow”
  1. Junio C HamanoOct 6, 2026
  2. Jeff KingOct 14, 2026
  3. 0/4 t: run greplint checks inside chainlintTyler Cipriani, Oct 25, 2026
  4. 1/4 t/interop: replace bare grep with test_grepTyler Cipriani, Oct 25, 2026
  5. 2/4 t/greplint: skip test bodies without the word grepTyler Cipriani, Oct 25, 2026
  6. 3/4 t/greplint: move parsing and token check to libraryTyler Cipriani, Oct 25, 2026
  7. 4/4 t/chainlint: add --greplint to run greplintTyler Cipriani, Oct 25, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.