0

I'm using this command:

git ls-tree -r --name-only HEAD -- . | grep -E '\.(ts|tsx|js|jsx|css|scss|html)$' | xargs -n1 git blame -c -e | sed -E 's/^.+\.com>\s+//' | LC_ALL=C grep -F 'todo: ' | sort

This gets all the todos in my codebase, sorted by date. This is mostly from Use git to list TODOs in code sorted by date introduced, I'm not very good with the command line.

However, the grep 'todo: ' part takes a long time. It takes 1min for ~400 files, without any particularly large files. Is it possible to speed this up somehow?

Edit: I realized it's the git blame that's slow, not grep, so I did a search before running git blame:

git ls-tree -r --name-only HEAD -- . | grep -E '\\.(ts|tsx|js|jsx|css|scss|html)$' | LC_ALL=C xargs grep -F -l 'todo: ' | xargs -n1 git blame -c -e | sed -E 's/^.+\\.com>\\s+//' | LC_ALL=C grep -F 'todo: ' | sort

Now it's 6s.

Leo Jiang
  • 24,497
  • 49
  • 154
  • 284
  • 1
    You can do better for instance just `git grep -il todo: \*.{ts,tsx,js,jsx,css,scss,html}` to generate the list. – jthill Dec 20 '20 at 02:08
  • How many files do you have todos in? I guess you could use `git grep --name-only` either as the first step, or as a filtering step between list of files and blame. If only some files have todos, it will save you running costly blame on all the rest of files. – Frax Dec 20 '20 at 02:13
  • @jthill that looks useful! It works when I run it directly in the terminal, but when I use it as a Yarn script, I get `usage: git blame [] [] [] [--] `. Any ideas why `git grep` produces the error but not `git ls-tree`? – Leo Jiang Dec 20 '20 at 02:22
  • @Frax About 30 files have todos. `git grep -il todo: \*.{ts,tsx,js,jsx,css,scss,html}` is really fast already – Leo Jiang Dec 20 '20 at 02:23
  • I don't know Yarn, it could be it doesn't do brace expansion so the blame gets no file args? – jthill Dec 20 '20 at 03:57

0 Answers0