From 86901f38b10838a45437177d5974082a1ec53976 Mon Sep 17 00:00:00 2001 From: Akira Sosa Date: Wed, 18 Feb 2026 09:17:15 +0900 Subject: [PATCH 1/2] perf(copy): limit find depth for simple directory patterns When copying directories with simple basename patterns (e.g., `.serena`, `node_modules`), `find` was scanning the entire repository tree recursively. In repos with large directories like `node_modules` (2GB+), this caused ~11 seconds of unnecessary I/O per pattern. Add `-maxdepth 1` for non-slash patterns since `gtr.copy.includeDirs` entries are typically top-level directories. Patterns with slashes (e.g., `vendor/bundle`) retain recursive behavior via `-path`. Before: ~11s per pattern (full recursive find) After: ~0.03s per pattern (top-level only) Co-Authored-By: Claude Opus 4.6 --- lib/copy.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/copy.sh b/lib/copy.sh index 6446400..636cc6f 100644 --- a/lib/copy.sh +++ b/lib/copy.sh @@ -331,10 +331,11 @@ copy_directories() { # Find directories matching the pattern # Use -path for patterns with slashes (e.g., vendor/bundle), -name for basenames # Note: case inside $() inside heredocs breaks Bash 3.2, so compute first + # Use -maxdepth 1 for simple basenames to avoid scanning entire repo (e.g., node_modules) local find_results case "$pattern" in */*) find_results=$(find . -type d -path "./$pattern" 2>/dev/null) ;; - *) find_results=$(find . -type d -name "$pattern" 2>/dev/null) ;; + *) find_results=$(find . -maxdepth 1 -type d -name "$pattern" 2>/dev/null) ;; esac while IFS= read -r dir_path; do From d7ecd4175e3c84bcc59c79d4e31a17b3a69bb990 Mon Sep 17 00:00:00 2001 From: Tom Elizaga Date: Tue, 17 Feb 2026 16:43:19 -0800 Subject: [PATCH 2/2] fix: add recursive fallback and set -e guards for find in copy_directories - Add || true to all find invocations to prevent silent exits under set -e - Fall back to recursive find when shallow (-maxdepth 1) search finds nothing, preserving backward compatibility for nested directory patterns --- lib/copy.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/copy.sh b/lib/copy.sh index 636cc6f..2a17b58 100644 --- a/lib/copy.sh +++ b/lib/copy.sh @@ -332,10 +332,14 @@ copy_directories() { # Use -path for patterns with slashes (e.g., vendor/bundle), -name for basenames # Note: case inside $() inside heredocs breaks Bash 3.2, so compute first # Use -maxdepth 1 for simple basenames to avoid scanning entire repo (e.g., node_modules) + # Falls back to recursive search if shallow search finds nothing local find_results case "$pattern" in - */*) find_results=$(find . -type d -path "./$pattern" 2>/dev/null) ;; - *) find_results=$(find . -maxdepth 1 -type d -name "$pattern" 2>/dev/null) ;; + */*) find_results=$(find . -type d -path "./$pattern" 2>/dev/null || true) ;; + *) find_results=$(find . -maxdepth 1 -type d -name "$pattern" 2>/dev/null || true) + if [ -z "$find_results" ]; then + find_results=$(find . -type d -name "$pattern" 2>/dev/null || true) + fi ;; esac while IFS= read -r dir_path; do