@@ -25,6 +25,7 @@ EXCLUDED_PATH_PREFIXES=(
2525 " bazel-prysm"
2626 " bazel-testlogs"
2727 " build"
28+ " .git"
2829 " .github"
2930 " .jj"
3031 " .idea"
@@ -35,6 +36,12 @@ EXCLUDED_PATH_PREFIXES=(
3536LOGRUS_IMPORT=" github.com/sirupsen/logrus"
3637# ----------------------------
3738
39+ # Require ripgrep
40+ if ! command -v rg > /dev/null 2>&1 ; then
41+ echo " Error: ripgrep (rg) is required but not installed." >&2
42+ exit 1
43+ fi
44+
3845# Find project root (git repo root if available, else current dir)
3946ROOT_DIR=" $( git rev-parse --show-toplevel 2> /dev/null || pwd) "
4047cd " $ROOT_DIR "
@@ -52,30 +59,28 @@ is_excluded() {
5259 return 1
5360}
5461
55- # Build a find command that:
56- # - starts at .
57- # - prunes all EXCLUDED_PATH_PREFIXES
58- # - returns only *.go files that are NOT *_test.go
59- find_cmd=(find .)
60-
61- find_cmd+=( \( -path ' ./.git' )
62+ # Build rg command:
63+ # - respects .gitignore automatically
64+ # - searches only *.go, excluding *_test.go
65+ # - excludes EXCLUDED_PATH_PREFIXES via negative globs so rg doesn't even enter them
66+ rg_args=(
67+ rg -F " $LOGRUS_IMPORT "
68+ --glob ' *.go'
69+ --glob ' !*_test.go'
70+ -l # list matching files
71+ -0 # NUL-delimited output
72+ )
6273
63- # Add all excluded prefixes to prune group
6474for ex in " ${EXCLUDED_PATH_PREFIXES[@]} " ; do
65- find_cmd +=( -o -path " ./ $ex " )
75+ rg_args +=( --glob " ! $ex /** " )
6676done
6777
68- # Close prune group, then search for go files
69- find_cmd+=( \) -prune -o -type f -name ' *.go' ! -name ' *_test.go' -print0 )
70-
71- # Find all non-test .go files that import logrus, respecting exclusions
72- mapfile -t FILES < <(
73- " ${find_cmd[@]} " \
74- | xargs -0 -r grep -Il " $LOGRUS_IMPORT " \
75- || true
78+ # 1) Use ripgrep to find all non-test .go files that import logrus.
79+ mapfile -d ' ' -t FILES < <(
80+ " ${rg_args[@]} " . || true
7681)
7782
78- # Collect unique directories containing such files
83+ # 2) Collect unique directories containing such files (is_excluded is now redundant but harmless)
7984declare -A DIRS=()
8085for f in " ${FILES[@]} " ; do
8186 dir=" $( dirname " $f " ) "
@@ -85,6 +90,7 @@ for f in "${FILES[@]}"; do
8590 DIRS[" $dir " ]=1
8691done
8792
93+ # 3) For each directory, (re)generate log.go
8894for dir in " ${! DIRS[@]} " ; do
8995 # Collect Go files in this directory
9096 shopt -s nullglob
0 commit comments