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

Fail-fast on children of negated glob directory matches like Git does #657

Open
magneticflux- opened this issue Nov 30, 2020 · 0 comments
Open
Labels
enhancement New feature or request glob

Comments

@magneticflux-
Copy link

magneticflux- commented Nov 30, 2020

Describe the enhancement

The default globbing technique investigates all paths, even ones that have already been invalidated by negated matchers:

/**
* Matches the patterns against the path
*/
export function match(patterns: Pattern[], itemPath: string): MatchKind {
let result: MatchKind = MatchKind.None
for (const pattern of patterns) {
if (pattern.negate) {
result &= ~pattern.match(itemPath)
} else {
result |= pattern.match(itemPath)
}
}
return result
}
/**
* Checks whether to descend further into the directory
*/
export function partialMatch(patterns: Pattern[], itemPath: string): boolean {
return patterns.some(x => !x.negate && x.partialMatch(itemPath))
}

This differs from Git's globbing technique used in the .gitignore files here:

It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn’t list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined.

This is unintuitive because many developers are already familiar with Git's globbing style and can inadvertently introduce performance problems by including arbitrary folders and trying (and failing) to exclude certain large directories.

Additional information

limjh16/jekyll-action-ts#3 (comment) describes a significant performance penalty from searching everywhere for a certain file name.

@magneticflux- magneticflux- added the enhancement New feature or request label Nov 30, 2020
@thboop thboop added the glob label Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request glob
Projects
None yet
Development

No branches or pull requests

2 participants