Skip to content

Commit

Permalink
refactor(techStackGeneric): ignore .git directory (#253)
Browse files Browse the repository at this point in the history
A significant fraction of the tech stack detection execution time was
often from scanning files in any `.git` directory. Prevent that.

Clearly, the speedup here depends on the relative size of the `.git`
directory versus the rest of the data. But at least on one machine,
this commit is a 2x speedup for running in the chalk repo:

    chalk insert --use-tech-stack-detection ./foo

We should eventually improve the directory walking here, and consider
ignoring other directories and files, but let's just do this for now.

Refs: #249
  • Loading branch information
ee7 authored Mar 28, 2024
1 parent a3ae9f5 commit 45ef21d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/plugins/techStackGeneric.nim
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ proc scanDirectory(directory: string, category: string, subcategory: string) =
break
if kind == pcFile:
scanFile(path, category, subcategory)
elif kind == pcDir:
elif kind == pcDir and not path.endsWith(".git"):
scanDirectory(path, category, subcategory)

proc getLanguages(directory: string, langs: var HashSet[string]) =
Expand All @@ -188,7 +188,7 @@ proc getLanguages(directory: string, langs: var HashSet[string]) =
let ext = path.splitFile().ext
if ext != "" and ext in languages:
langs.incl(languages[ext])
elif kind == pcDir:
elif kind == pcDir and not path.endsWith(".git"):
getLanguages(path, langs)

proc detectLanguages(): HashSet[string] =
Expand Down

0 comments on commit 45ef21d

Please sign in to comment.