Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster globbing by respecting root .gitignore. #1209

Merged
merged 1 commit into from
Apr 2, 2024
Merged

Faster globbing by respecting root .gitignore. #1209

merged 1 commit into from
Apr 2, 2024

Conversation

Blugatroff
Copy link
Contributor

@Blugatroff Blugatroff commented Apr 2, 2024

Addresses part of #1182 by implementing this snippet.

I'm not sure, whether this is the right place for the change, would it have been better to implement this purescript/registry-dev since that's where Glob.match' is implemented? Although then again, Glob.match' is just a wrapper for fast-glob.

On my laptop and repo mentioned in #1182 this change reduces the time spent globbing for spago.yaml from 600ms to 30ms :)

Description of the change

Instead of globbing everything for **/spago.yaml and then filtering the matches against .gitignore files, use every entry in the root .gitignore as a negative match (ignore) while globbing.

The resulting matches still need to be checked seperately using Git.isIgnored, because the new function only considers the root .gitignore file, .gitignore files in subdirectories are ignored.

Checklist:

  • Added the change to the "Unreleased" section of the changelog
  • Added some example of the new feature to the README
  • Added a test for the contribution (if applicable)

Instead of globbing everything for **/spago.yaml and then filtering the
matches against .gitignore files, use every entry in the root .gitignore as
a negative match (ignore) while globbing.

The resulting matches still need to be checked seperately using
`Git.isIgnored`, because the new function only considers the root
.gitignore file, .gitignore files in subdirectories are ignored.
Copy link
Member

@f-f f-f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Thanks @Blugatroff 👏

@f-f f-f merged commit 7308e90 into purescript:master Apr 2, 2024
3 checks passed
Blugatroff added a commit to Blugatroff/spago that referenced this pull request Apr 5, 2024
Addresses purescript#1182

This implementation is using `micromatch` (a dependency of fast-glob)
and `fs.walk` to traverse the file system itself, instead of relying on fast-glob.
As opposed to the previous implementation (from purescript#1209) This implementation takes
every .gitignore file into account, not just the root one.
The callbacks `entryFilter` and `deepFilter` are used to control which
directories to recurse into. When `entryFilter` encounters a .gitignore
file, it's patterns are parsed into micromatch compatible ones and every
subsequent call to these filter functions respect them.

I'm not sure whether this should have been (partially) implemented in the
registry-dev repo since that's where the FFI for fast-glob is located.

I also did not remove the fast-glob npm dependency, since i'm not sure if
it is still in use elsewhere and because the registry-dev dependency
definitely still contains the foreign functions relying on it being available.
f-f pushed a commit that referenced this pull request Apr 19, 2024
Fixes #1182

This implementation is using `micromatch` (a dependency of fast-glob)
and `fs.walk` to traverse the file system itself, instead of relying on fast-glob.
As opposed to the previous implementation (from #1209) This implementation takes
every .gitignore file into account, not just the root one.
The callbacks `entryFilter` and `deepFilter` are used to control which
directories to recurse into. When `entryFilter` encounters a .gitignore
file, it's patterns are parsed into micromatch compatible ones and every
subsequent call to these filter functions respect them.
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.

2 participants