Skip to content

daily-file-diet: replace expensive find | wc -l with git ls-tree#283

Merged
dsyme merged 2 commits intomainfrom
copilot/replace-find-wc-with-git-ls-tree
Mar 19, 2026
Merged

daily-file-diet: replace expensive find | wc -l with git ls-tree#283
dsyme merged 2 commits intomainfrom
copilot/replace-find-wc-with-git-ls-tree

Conversation

Copy link
Contributor

Copilot AI commented Mar 18, 2026

find ... -exec wc -l {} \; spawns one wc process per file, scans all file types, and requires manual exclusion of generated directories — slow enough to hit workflow timeouts on larger repos.

Changes

  • tools.bash allowlist — Replaced 9 find-based entries with git ls-tree command patterns:

    • git ls-tree -r --name-only HEAD / git ls-tree -r -l --full-name HEAD
    • Pipeline patterns: grep -E * | grep -vE * | xargs wc -l
  • Analysis Process example — Replaced the find | wc block with:

    git ls-tree -r --name-only HEAD \
      | grep -E '\.(go|py|ts|tsx|js|jsx|rb|java|rs|cs|cpp|c|h|hpp)$' \
      | grep -vE '(_test\.go|\.test\.(ts|js)|\.spec\.(ts|js)|test_[^/]*\.py|[^/]*_test\.py)$' \
      | xargs wc -l 2>/dev/null \
      | sort -rn \
      | head -20

    Test-file exclusion is now handled inline via grep -vE, removing the need for a separate note.

  • docs/daily-file-diet.md — Updated "Scans Source Files" description and customization tip to reflect the git ls-tree approach.

Why git ls-tree

  • Reads from git's object DB — no filesystem traversal
  • Only lists tracked files, so node_modules, vendor, dist, etc. are automatically excluded (they're gitignored and untracked)
  • Single xargs wc -l invocation instead of N processes

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>
Copilot AI changed the title [WIP] Replace expensive find | wc -l with git ls-tree daily-file-diet: replace expensive find | wc -l with git ls-tree Mar 18, 2026
Copilot AI requested a review from dsyme March 18, 2026 20:24
@dsyme dsyme marked this pull request as ready for review March 19, 2026 00:43
@dsyme dsyme merged commit fed4a49 into main Mar 19, 2026
1 check passed
@dsyme dsyme deleted the copilot/replace-find-wc-with-git-ls-tree branch March 19, 2026 00:46
@lkraav
Copy link

lkraav commented Mar 19, 2026

Tyvm 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

daily-file-diet: replace expensive find | wc -l with git ls-tree

3 participants