Commit Graph

174 Commits

Author SHA1 Message Date
one230six
138919907b refactor: Optimize code based on cargo clippy suggestions
Signed-off-by: one230six <723682061@qq.com>
2024-03-13 15:37:24 +08:00
garlic-hub
0788c43c3f
Clean up clippy warnings 2024-03-08 10:46:24 -08:00
Tavian Barnes
16c2d1e1d0 walk: Flush stdout in batches
The previous behaviour was designed to mimic the output buffering of
typical UNIX tools: line-buffered if stdout is a TTY, and fully-buffered
otherwise.  More precicely, when printing to a terminal, fd would flush
explicitly after printing any buffered results, then flush after every
single result once streaming mode started.  When not printing to a
terminal, fd never explicitly flushed, so writes would only happen as
the BufWriter filled up.

The new behaviour actually unifies the TTY and non-TTY cases: we flush
after printing the buffered results, then once we start streaming, we
flush after each batch, but *only when the channel is empty*.  This
provides a good balance: if the channel is empty, the receiver thread
might as well flush before it goes to sleep waiting for more results.
If the channel is non-empty, we might as well process those results
before deciding to flush.

For TTYs, this should improve performance by consolidating write() calls
without sacrificing interactivity.  For non-TTYs, we'll be flushing more
often, but only when the receiver would otherwise have nothing to do,
thus improving interactivity without sacrificing performance.  This is
particularly handy when fd is piped into another command (such as head
or grep): with the old behaviour, fd could wait for the whole traversal
to finish before printing anything.  With the new behaviour, fd will
print those results soon after they are received.

Fixes #1313.
2023-12-18 22:01:11 +01:00
Tavian Barnes
b8a5f95cf2 walk: Limit batch sizes in --exec mode 2023-11-28 15:51:33 -05:00
Tavian Barnes
73260c0e35 walk: Send WorkerResults in batches 2023-11-28 15:51:33 -05:00
Tavian Barnes
8bbbd7679b walk: New WorkerState struct shared by the worker threads 2023-11-02 17:07:38 +01:00
Thayne McCombs
53fd416c47 docs: Document exclusion of .git/ 2023-10-23 08:34:03 +02:00
Karthik Prakash
9df9a489f0 refactor: replace map_err with expect
Co-authored-by: Thayne McCombs <astrothayne@gmail.com>
2023-10-18 13:06:51 +05:30
skoriop
3f9794cd1a feat: ignore .git/ by default 2023-10-15 11:11:53 +05:30
Utkarsh Gupta
3ae04546ea Replace dirs-next crate with etcetera crate 2023-06-14 21:22:28 +02:00
Thayne McCombs
424d6efcc0 fix: Remove unnecessary collection into a vec. 2023-03-20 01:21:00 -06:00
Thayne McCombs
ee44c1ed90 refactor: Use scoped threads from stdlib in spawn_receiver
This makes it so we don't need to use Arc as much.

Fixes #1141
2023-03-20 01:21:00 -06:00
Max 👨🏽‍💻 Coplan
08c0d427bf Add flag --no-require-git to always respect gitignore files
Summary: Currently, `--ignore-vcs` only serves to unset `--no-ignore-vcs`.
There is currently no way to tell fd to respect gitignore files when not in a
git repository.  This commit adds the flag `--no-require-git` to make fd always
respect all gitignore files.

This behaves the same as the `--no-require-git` option in [ripgrep](3bb71b0cb8/crates/core/app.rs (L2214-L2226))

This commit also contains an unrelated wording fix to CONTRIBUTING.md

Test Plan: `tests/tests.rs`

Background: I am using [Sapling](https://sapling-scm.com/docs/introduction/)
for working with git repositories (including this commit ☺️).  Since Sapling
uses `.sl` instead of `.git`, tools using the `ignore` crate (rg and fd) would show gitignored files.
I made a patch (ebf17eef22)
to `ignore` to respect gitignores with _either_ `.git` or `.sl`.  However,
@BurntSushi said he did not want to merge that patch and instead suggested I
use `--no-require-git` (https://github.com/BurntSushi/ripgrep/issues/2374).
This works fine, but I couldn't use this workaround for my other favorite tool!
That's what this patch is for 😁

(a follow-up patch will add a similar `FD_CONFIG_PATH` environment variable
like `RG_CONFIG_PATH`)
2023-01-13 13:52:34 -08:00
Kasper Gałkowski
7e26925933 Added the --and flag for matching multiple patterns 2022-11-21 21:06:48 +01:00
Thayne McCombs
55aae3a8c0 Silence warning about large enum variant
Because boxing the large variant is probably worse.
2022-11-03 00:56:56 -06:00
David Peter
169d22fde2 Merge remote-tracking branch 'origin/master' into clap-derive 2022-11-01 20:00:16 +01:00
Tavian Barnes
5278405263 walk: Use a bounded queue.
Fixes #918.
2022-11-01 19:48:39 +01:00
Tavian Barnes
5bb7a52704 walk: Switch back to crossbeam-channel
Fixes #933.  Fixes #1060.  Fixes #1113.
2022-11-01 19:48:39 +01:00
Tavian Barnes
93e5488420 walk: Simplify the code in scan() a bit 2022-11-01 15:36:48 +01:00
Thayne McCombs
8500c3193d Merge remote-tracking branch 'upstream/master' into clap-derive 2022-11-01 01:12:41 -06:00
Tavian Barnes
cd8ec44abf Address review comments 2022-10-31 22:23:30 +01:00
Tavian Barnes
17d849df6c Compute colors in parallel 2022-10-31 22:23:30 +01:00
Thayne McCombs
a3622ba294 Remove TODO comment
In favor of tracking scoped threads in #1141
2022-10-19 23:43:45 -06:00
Thayne McCombs
c41d61eeda Merge remote-tracking branch 'upstream/master' into clap-derive 2022-10-09 01:00:48 -06:00
Thayne McCombs
4e7b403c1f Use clap-derive for option parsing
This makes the definition of arguments to fd a little more ergonomic,
and makes it easier to insure the types for the arguments are consitent.
2022-10-08 00:41:33 -06:00
Tavian Barnes
4ffc34956f Make --strip-cwd-prefix apply to -x/-X
Fixes #898.
2022-10-03 21:35:39 +02:00
Jonathan Goren
60c14b1af2 make DirEntry Ord 2022-03-16 18:38:16 +02:00
Thayne McCombs
50c0fa812f
Merge branch 'master' into master 2022-03-15 01:20:35 -06:00
Thayne McCombs
9fb0c5d372 Group together output from multi exec commands
So that if multiple `--exec` options are given, and the commands are run
in parallel, the buffered output for related commands will be
consecutive.
2022-03-08 10:15:48 +01:00
Thayne McCombs
6e5c8d9c20 Fix some clippy warnings 2022-03-04 08:30:41 +01:00
Tavian Barnes
e7f192f1c6 Revert "Switch from std::sync::mpsc to crossbeam-channel"
@sharkdp [noticed][1] a quite severe performance degredation due to this
change.  Switch back to std::sync::mpsc until we can fix the performance
regression.

This reverts commit a4bb734482.

[1]: https://github.com/sharkdp/fd/pull/895#issuecomment-1002099369
2021-12-28 12:11:32 -05:00
Thayne McCombs
b7e077320d
Fix logic for --no-ignore-parent (#908)
Make sure that using `--no-ignore-vcs` or `--no-ignore` don't also
enable `--no-ignore-parent`. So that if `--no-ignore-vcs` is enabled, it
continues to respect .fdignore and .ignore in the parent directories.

Fixes: #907
Fixes: #901
2021-12-22 23:38:00 -07:00
Jonathan Goren
3dc61b5f28 rename module entry -> dir_entry 2021-12-11 15:43:52 +02:00
Jonathan Goren
813a802b2c send DirEntries to output instead of just path 2021-12-11 15:42:07 +02:00
Tavian Barnes
4baefb2f5a walk: Split wants_to_quit into two separate flags
quit_flag is now used to quit the sender threads for any reason, either
due to an interrupt or because the receiver is done.

interrupt_flag is used specifically for ^C interrupts, and causes the
receiver to stop between printing paths, to avoid unfinished escape
sequences when colors are being used.

Fixes #867.
2021-12-05 12:06:49 -05:00
Tavian Barnes
97a8825b00 output: Remove wants_to_quit handling from print_entry()
Since we only check it once per path now, we might as well just check it
before printing anything.
2021-12-05 12:06:49 -05:00
Tavian Barnes
a4bb734482 Switch from std::sync::mpsc to crossbeam-channel
This lets us avoid https://github.com/rust-lang/rust/issues/39364, which
could potentially be seen now that we're using recv_timeout().
2021-12-01 10:24:58 -05:00
Tavian Barnes
16ae03c3b4 walk: Encapsulate the buffering behavior in a struct
The new ReceiverBuffer struct allows us to factor out the receiver
implementation into a number of helper methods.  The new implementation
uses rx.{recv,recv_timeout} instead of a for loop, which enables us to
switch to streaming mode at the right time without waiting for more
results.

Fixes #868.
2021-11-27 12:56:22 -05:00
David Peter
f219da4b3a Use non-sync channel 2021-11-26 21:23:47 +01:00
Thayne McCombs
e990a13405 squash! Add buffering to stdout when it's not a terminal
Co-authored-by: sourlemon207 <jw1756@protonmail.com>
2021-11-26 21:23:47 +01:00
Thayne McCombs
feac240eb5 Add buffering to stdout when it's not a terminal
This is based on the work of #736 by @sourlemon207.

I've added the suggestion I recommended on that PR.
2021-11-26 21:23:47 +01:00
Tavian Barnes
2b1bf471b1 Add an exit() method to ExitCode 2021-11-15 07:53:57 +01:00
Devon Hollowood
17dd2a6dfe
Implement --batch-size (#866) 2021-10-22 00:05:13 -06:00
Tavian Barnes
7b5b3ec47b walk: Add a cache for DirEntry metadata 2021-10-13 09:13:44 +02:00
Niklas Mohrin
02e9850112 Refactor: Rename Options to Config 2021-10-12 18:49:07 +02:00
Niklas Mohrin
3de948ae0d Refactor: use some nice Rust methods in buffering code 2021-10-12 18:49:07 +02:00
Niklas Mohrin
45a86459b2 Refactor: merge_exit_codes now takes an impl IntoIterator<Item = ExitCode>
This way, callers don't need to collect into a slice / vec.
2021-10-12 18:49:07 +02:00
Tavian Barnes
476d404938
Merge pull request #817 from will459/add_no_ignore_parent
Add --no-ignore-parent flag
2021-09-01 13:22:01 -04:00
Asha20
334488cab7
Add -q/--quiet/--has-match flag (#813)
Instead of printing to stdout, the program will return 1 as the exit
code if there are no matches and 0 otherwise.
2021-08-14 17:57:01 +02:00
Thayne McCombs
e4730603d0 Address feedback for removing buffering when running on a single thread 2021-08-11 09:38:55 +02:00