Revert "nix-gitignore: Optimise performance"
This commit is contained in:
parent
b5bf9da14d
commit
11e522cb6e
|
@ -20,13 +20,14 @@ let
|
||||||
in rec {
|
in rec {
|
||||||
# [["good/relative/source/file" true] ["bad.tmpfile" false]] -> root -> path
|
# [["good/relative/source/file" true] ["bad.tmpfile" false]] -> root -> path
|
||||||
filterPattern = patterns: root:
|
filterPattern = patterns: root:
|
||||||
let
|
(name: _type:
|
||||||
filters = map (pair: relPath: if match (head pair) relPath == null then true else last pair) patterns;
|
let
|
||||||
in
|
relPath = lib.removePrefix ((toString root) + "/") name;
|
||||||
name: _type:
|
matches = pair: (match (head pair) relPath) != null;
|
||||||
let
|
matched = map (pair: [(matches pair) (last pair)]) patterns;
|
||||||
relPath = lib.removePrefix ((toString root) + "/") name;
|
in
|
||||||
in foldl' (acc: f: if acc == true then f relPath else acc) true filters;
|
last (last ([[true true]] ++ (filter head matched)))
|
||||||
|
);
|
||||||
|
|
||||||
# string -> [[regex bool]]
|
# string -> [[regex bool]]
|
||||||
gitignoreToPatterns = gitignore:
|
gitignoreToPatterns = gitignore:
|
||||||
|
@ -90,9 +91,7 @@ in rec {
|
||||||
(filter (l: !isList l && !isComment l)
|
(filter (l: !isList l && !isComment l)
|
||||||
(split "\n" gitignore));
|
(split "\n" gitignore));
|
||||||
|
|
||||||
gitignoreFilter = ign: let
|
gitignoreFilter = ign: root: filterPattern (gitignoreToPatterns ign) root;
|
||||||
patterns = gitignoreToPatterns ign;
|
|
||||||
in root: filterPattern patterns root;
|
|
||||||
|
|
||||||
# string|[string|file] (→ [string|file] → [string]) -> string
|
# string|[string|file] (→ [string|file] → [string]) -> string
|
||||||
gitignoreCompileIgnore = file_str_patterns: root:
|
gitignoreCompileIgnore = file_str_patterns: root:
|
||||||
|
@ -101,10 +100,9 @@ in rec {
|
||||||
str_patterns = map (onPath readFile) (lib.toList file_str_patterns);
|
str_patterns = map (onPath readFile) (lib.toList file_str_patterns);
|
||||||
in concatStringsSep "\n" str_patterns;
|
in concatStringsSep "\n" str_patterns;
|
||||||
|
|
||||||
gitignoreFilterPure = filter: patterns: root: let
|
gitignoreFilterPure = filter: patterns: root: name: type:
|
||||||
compiledFilter = gitignoreCompileIgnore patterns root;
|
gitignoreFilter (gitignoreCompileIgnore patterns root) root name type
|
||||||
filterFn = gitignoreFilter compiledFilter;
|
&& filter name type;
|
||||||
in name: type: filterFn root name type && filter name type;
|
|
||||||
|
|
||||||
# This is a very hacky way of programming this!
|
# This is a very hacky way of programming this!
|
||||||
# A better way would be to reuse existing filtering by making multiple gitignore functions per each root.
|
# A better way would be to reuse existing filtering by making multiple gitignore functions per each root.
|
||||||
|
|
Loading…
Reference in New Issue