diff options
author | github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> | 2020-12-07 18:15:25 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-07 18:15:25 +0000 |
commit | a1b23037101c4c327d9e9bfd44ce6c2f2546a5db (patch) | |
tree | ca2cae67b804c8a244f9c6cc94f9f270f5921860 /pkgs/build-support/nix-gitignore/default.nix | |
parent | 101c5a96ad5df1b1b0d74b0a0f6d071d5a296873 (diff) | |
parent | b2c2260de341ac99b0c30bd0cbc2663f122ca440 (diff) | |
download | nixpkgs-a1b23037101c4c327d9e9bfd44ce6c2f2546a5db.tar nixpkgs-a1b23037101c4c327d9e9bfd44ce6c2f2546a5db.tar.gz nixpkgs-a1b23037101c4c327d9e9bfd44ce6c2f2546a5db.tar.bz2 nixpkgs-a1b23037101c4c327d9e9bfd44ce6c2f2546a5db.tar.lz nixpkgs-a1b23037101c4c327d9e9bfd44ce6c2f2546a5db.tar.xz nixpkgs-a1b23037101c4c327d9e9bfd44ce6c2f2546a5db.tar.zst nixpkgs-a1b23037101c4c327d9e9bfd44ce6c2f2546a5db.zip |
Merge staging-next into staging
Diffstat (limited to 'pkgs/build-support/nix-gitignore/default.nix')
-rw-r--r-- | pkgs/build-support/nix-gitignore/default.nix | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/pkgs/build-support/nix-gitignore/default.nix b/pkgs/build-support/nix-gitignore/default.nix index 28ee6bad554..fba09adc2d4 100644 --- a/pkgs/build-support/nix-gitignore/default.nix +++ b/pkgs/build-support/nix-gitignore/default.nix @@ -20,14 +20,13 @@ let in rec { # [["good/relative/source/file" true] ["bad.tmpfile" false]] -> root -> path filterPattern = patterns: root: - (name: _type: - let - relPath = lib.removePrefix ((toString root) + "/") name; - matches = pair: (match (head pair) relPath) != null; - matched = map (pair: [(matches pair) (last pair)]) patterns; - in - last (last ([[true true]] ++ (filter head matched))) - ); + let + filters = map (pair: relPath: if match (head pair) relPath == null then true else last pair) patterns; + in + name: _type: + let + relPath = lib.removePrefix ((toString root) + "/") name; + in foldl' (acc: f: if acc == true then f relPath else acc) true filters; # string -> [[regex bool]] gitignoreToPatterns = gitignore: @@ -91,7 +90,9 @@ in rec { (filter (l: !isList l && !isComment l) (split "\n" gitignore)); - gitignoreFilter = ign: root: filterPattern (gitignoreToPatterns ign) root; + gitignoreFilter = ign: let + patterns = gitignoreToPatterns ign; + in root: filterPattern patterns root; # string|[string|file] (→ [string|file] → [string]) -> string gitignoreCompileIgnore = file_str_patterns: root: @@ -100,9 +101,10 @@ in rec { str_patterns = map (onPath readFile) (lib.toList file_str_patterns); in concatStringsSep "\n" str_patterns; - gitignoreFilterPure = filter: patterns: root: name: type: - gitignoreFilter (gitignoreCompileIgnore patterns root) root name type - && filter name type; + gitignoreFilterPure = filter: patterns: root: let + compiledFilter = gitignoreCompileIgnore patterns root; + filterFn = gitignoreFilter compiledFilter; + in name: type: filterFn root name type && filter name type; # 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. |