Skip to content

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

@magneticflux-

Description

@magneticflux-

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions