Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lute/cli/commands/transform/lib/ignore.luau
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ end

local function parseGitignore(filepath: path.path): GitignoreData
local contents = fs.readfiletostring(path.format(filepath))
return parseGitignoreContents(assert(path.dirname(filepath)), contents)
local parentDirectory = if path.basename(filepath) then path.dirname(filepath) else nil
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we have path.path objects, so I believe the following would be more performant:
if #path.parts > 0 then path.dirname(filepath) else nil

Copy link
Copy Markdown
Contributor Author

@wmccrthy wmccrthy Nov 7, 2025

Choose a reason for hiding this comment

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

If filePath is always a table here, won't path.basename mirror this exact logic (non-nil if #path.parts > 0 and nil otherwise)? Happy to change but curious what the performance bottleneck would be

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yeah, the logic will be the same, but we avoid the table check and passing the string basename around this way

return parseGitignoreContents(assert(parentDirectory), contents)
Comment thread
wmccrthy marked this conversation as resolved.
Outdated
end

local function matchesGlob(glob: Glob, filepath: string, isDirectory: boolean): boolean
Expand Down Expand Up @@ -196,7 +197,7 @@ end

--- Checks whether the given file matches an ignore
function IgnoreResolver.isIgnoredFile(self: IgnoreResolver, filepath: path.path)
local directory = path.dirname(filepath)
local directory = if path.basename(filepath) then path.dirname(filepath) else nil
assert(directory ~= nil, "filepath has no directory!")

local ignoreData = self:_readIgnoreRecursive(directory)
Expand All @@ -209,7 +210,7 @@ function IgnoreResolver.isIgnoredDirectory(self: IgnoreResolver, directorypath:
return true
end

local parentDirectory = path.dirname(directorypath)
local parentDirectory = if path.basename(directorypath) then path.dirname(directorypath) else nil
if parentDirectory then
local ignoreData = self:_readIgnoreRecursive(parentDirectory)
return isIgnored(ignoreData, path.format(directorypath), true)
Expand All @@ -223,7 +224,7 @@ function IgnoreResolver._readIgnoreRecursive(self: IgnoreResolver, directory: st
return self._ignoreCache[directory]
end

local parentPath = path.dirname(directory)
local parentPath = if path.basename(directory) then path.dirname(directory) else nil
local baseIgnores = if parentPath then self:_readIgnoreRecursive(parentPath) else nil
local gitignorePath = path.join(directory, ".gitignore")

Expand Down