First version of paths in ignore_files

Works correctly and the logic seems sound even if somewhat quirky.

`^%.` match any file of directory whose basename begins with a dot.

`^/node_modules$/"` match a directory named `node_modules` at the project's root.

  Note that the final '/' needs to be at the end. The '/' after the '^' needs to be there to trigger
  a match of the full path filename so we are sure it is at the root.

  PROBLEM: the '/' to trigger full path match could be in a pattern's special expression like:
  [^/]

`^%.git$/` match any directory name '.git' anywhere in the project.

`^/%.git$/` match a directory named '.git' only at the project's root.

`^/subprojects/.+/` match any directory in a top-level folder named "subprojects".

`^/build/` match any top level directory whose name begins with "build"

  PROBLEM: may be surprising, one may expects it matches only a directory named 'build'. It actually acts like
  it was `^/build.*/`.
This commit is contained in:
Francesco Abbate 2022-01-03 15:05:57 +01:00
parent 143b389365
commit 5b154c189f
1 changed files with 29 additions and 2 deletions

View File

@ -122,10 +122,37 @@ local function compare_file(a, b)
end
local function fileinfo_pass_filter(info)
if info.size >= config.file_size_limit * 1e6 then return false end
local basename = common.basename(info.filename)
return (info.size < config.file_size_limit * 1e6 and
not common.match_pattern(basename, config.ignore_files))
-- replace '\' with '/' for Windows where PATHSEP = '\'
local fullname = "/" .. info.filename:gsub("\\", "/")
local ipatterns = config.ignore_files
-- config.ignore_files could be a simple string...
if type(ipatterns) ~= "table" then ipatterns = {ipatterns} end
for _, pattern in ipairs(ipatterns) do
local is_path_like = pattern:match("/[^/]") -- contains a slash but not at the end
local dir_pass = true
if pattern:match("(.+)/$") then
dir_pass = (info.type == "dir")
-- the final '/' should not participate to the match.
pattern = pattern:match("(.+)/$")
end
if is_path_like then
if fullname:match(pattern) and dir_pass then
return false
end
else
if basename:match(pattern) and dir_pass then
return false
end
end
end
return true
end