mirror of
https://github.com/nushell/nushell.git
synced 2024-12-23 23:49:44 +01:00
7ac5a01e2f
# Description looking at the [Wax documentation about `wax::Walk.not`](https://docs.rs/wax/latest/wax/struct.Walk.html#examples), especially > therefore does not read directory trees from the file system when a directory matches an [exhaustive glob expression](https://docs.rs/wax/latest/wax/trait.Pattern.html#tymethod.is_exhaustive) > **Important** > in the following of this PR description, i talk about *pruning* and a `--prune` option, but this has been changed to *exclusion* and `--exclude` after a discussion with @fdncred. this looks like a *pruning* operation to me, right? 😮 i wanted to make the `glob` option `--not` clearer about that, because > -n, --not <List(String)> - Patterns to exclude from the results from `help glob` is not very explicit about whether the search is pruned when entering a directory matching a pattern in `--not` or just removing it from the output 😕 ## changelog this PR proposes to rename the `glob --not` option to `glob --prune` and make it's documentation more explicit 😋 ## benchmarking to support the *pruning* behaviour put forward above, i've run a benchmark 1. define two closures to compare the behaviour between removing patterns manually or using `--not` ```nushell let where = { [.*/\.local/.*, .*/documents/.*, .*/\.config/.*] | reduce --fold (glob **) {|pat, acc| $acc | where $it !~ $pat} | length } ``` ```nushell let not = { glob ** --not [**/.local/**, **/documents/**, **/.config/**] | length } ``` 2. run the two to make sure they give similar results ```nushell > do $where 33424 ``` ```nushell > do $not 33420 ``` 👌 3. measure the performance ```nushell use std bench ``` ```nushell > bench --verbose --pretty --rounds 25 $not 44ms 52µs 285ns +/- 977µs 571ns ``` ```nushell > bench --verbose --pretty --rounds 5 $where 1sec 250ms 187µs 99ns +/- 8ms 538µs 57ns ``` 👉 we can see that the results are (almost) the same but `--not` is much faster, looks like pruning 😋 # User-Facing Changes - `--not` will give a warning message but still work - `--prune` will work just as `--not` without warning and with a more explicit doc - `--prune` and `--not` at the same time will give an error # Tests + Formatting this PR fixes the examples of `glob` using the `--not` option. # After Submitting prepare the removal PR and mention in release notes. |
||
---|---|---|
.. | ||
src | ||
tests | ||
Cargo.toml | ||
LICENSE |