Conversation
bee5e1d to
b93c133
Compare
b93c133 to
4f1dd7b
Compare
lib/fileset/default.nix
Outdated
There was a problem hiding this comment.
| # A list of Nix files | |
| # A set of Nix-related files |
nix/ may contain non-.nix files, which could be considered non-Nix.
lib/fileset/internal.nix
Outdated
There was a problem hiding this comment.
| # The filesetTree's need to have the same base path in order to be able to compute the difference between them. | |
| # The filesetTree's need to have the same base path in order to be able to compute the difference between them. | |
| # Technically an unrelated root in the second, negative argument could be considered not to match any files in | |
| # the first argument, but users would be clueless as to why their filter doesn't work. |
There was a problem hiding this comment.
Hmm not sure what you mean here. If the root of the second argument is unrelated (e.g. difference /foo /bar), then no files inside /foo match /bar, meaning nothing gets subtracted, so the result is /foo. And that should be expected.
There was a problem hiding this comment.
I was thinking of entirely unrelated trees, such as when one is an absolute path, but the other is a fetchGit lazy tree.
Rejecting difference /foo /bar seems excessive, I agree.
There was a problem hiding this comment.
Ah yeah, it will error for different filesystem roots, there's a comment on this in the comments for _difference:
# The filesets must already be coerced and validated to be in the same filesystem root.
The public difference function passes its arguments through _coerceMany, which checks against this, before calling the internal one.
lib/fileset/internal.nix
Outdated
There was a problem hiding this comment.
| _difference = fileset1: fileset2: | |
| _difference = positive: negative: |
| _difference = fileset1: fileset2: | |
| _difference = baseSet: negatingSet: |
| _difference = fileset1: fileset2: | |
| _difference = fileset: subtrahend: |
There was a problem hiding this comment.
Nice! I'll also apply this to the user-facing function. I like positive/negative the most
lib/fileset/internal.nix
Outdated
There was a problem hiding this comment.
Not clear to me why.
What is tree2 for?
There was a problem hiding this comment.
Same as the tree of the negative file set, but with the same base path as the positive file set, such that they are comparable and can be operated on.
E.g. if you have difference /foo /foo/bar, the common path would be /foo, meaning the first branch applies.
It then takes the negative file set, (base: /foo/bar, tree: "directory") in this case, and shortens the base to /foo instead, such that you get (base: /foo, tree: { bar = "directory"; }). tree2 here only contains the tree part though, so { bar = "directory"; }.
Now we have two trees, "directory" from the positive file set, and { bar = "directory"; } from the negative file set, that have the same base /foo, so they can be operated on, and it matches the base path that the result should have.
I'll put something like this in the code docs, and I'll improve the variable name, negativeTreeWithPositiveBasePath or so (maybe shorter :P)
lib/fileset/internal.nix
Outdated
There was a problem hiding this comment.
| # Otherwise we always have two attribute sets which we can recurse into | |
| # Otherwise we always have two attribute sets to recurse into |
lib/fileset/tests.sh
Outdated
There was a problem hiding this comment.
How about removing the parent? e.g.
difference ./a ./.There was a problem hiding this comment.
Maybe the test could be more systematic, by framing it as a matrix of possible arguments. Perhaps not an actual matrix in terms of code, but laid out in a way that you can see that all combinations are tested.
That way you would naturally test difference ./a ./..
2d4b2e4 to
cb9a53d
Compare
|
@roberth Should be good now! |
lib/fileset/default.nix
Outdated
There was a problem hiding this comment.
| { | |
| context = "first argument"; | |
| value = positive; | |
| } | |
| { | |
| context = "second argument"; | |
| value = negative; | |
| } | |
| { | |
| context = "first argument (positive set)"; | |
| value = positive; | |
| } | |
| { | |
| context = "second argument (negative set)"; | |
| value = negative; | |
| } |
Not 100% sure, but might be nice.
lib/fileset/internal.nix
Outdated
There was a problem hiding this comment.
| negativeTreePositiveBase = | |
| negativeTreeWithPositiveBase = |
cb9a53d to
50df7f9
Compare
|
Done now, unless you do it before me, I'll merge once CI passes :) |
Description of changes
This is another split off from the WIP file set combinators PR. This PR adds one function:
lib.fileset.difference: Subtracts the second file set from the first.This work is sponsored by Antithesis ✨
Things done