Skip to content
Myr

Merge remote-tracking branch 'origin/master' into clap-derive

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Peter · committed by David Peter · parents 36ee44a, c6f9595 · Browse files · 5 files+33 added−28 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+33 added−28 removed

  • other:+33 added−28 removed

5 files+33 added−28 removed

modified:src/exec/job.rs+4 added-8 removed
1use std::sync::mpsc::Receiver;1use std::sync::{Arc, Mutex};23use crossbeam_channel::Receiver;45use crate::config::Config;6use crate::dir_entry::DirEntry;7use crate::error::print_error;8use crate::exit_codes::{merge_exitcodes, ExitCode};
4 unmodified lines
13/// An event loop that listens for inputs from the `rx` receiver. Each received input will14/// generate a command with the supplied command template. The generated command will then15/// be executed, and this process will continue until the receiver's sender has closed.16pub fn job(16 rx: Arc<Mutex<Receiver<WorkerResult>>>,17 rx: Receiver<WorkerResult>,18 cmd: Arc<CommandSet>,19 out_perm: Arc<Mutex<()>>,20 config: &Config,21) -> ExitCode {
1 unmodified line
23 let buffer_output: bool = config.threads > 1;2425 let mut results: Vec<ExitCode> = Vec::new();26 loop {26 // Create a lock on the shared receiver for this thread.27 let lock = rx.lock().unwrap();2827 // Obtain the next result from the receiver, else if the channel28 // has closed, exit from the loop31 let dir_entry: DirEntry = match lock.recv() {29 let dir_entry: DirEntry = match rx.recv() {30 Ok(WorkerResult::Entry(dir_entry)) => dir_entry,31 Ok(WorkerResult::Error(err)) => {32 if config.show_filesystem_errors {33 print_error(err.to_string());
2 unmodified lines
36 }37 Err(_) => break,38 };3942 // Drop the lock so that other threads can read from the receiver.43 drop(lock);40 // Generate a command, execute it and store its exit code.41 results.push(cmd.execute(42 dir_entry.stripped_path(config),43 config.path_separator.as_deref(),
23 unmodified lines
modified:src/walk.rs+12 added-19 removed
1 unmodified line
2use std::io;3use std::mem;4use std::path::PathBuf;5use std::sync::atomic::{AtomicBool, Ordering};6use std::sync::mpsc::{channel, Receiver, RecvTimeoutError, Sender};6use std::sync::{Arc, Mutex};7use std::thread;8use std::time::{Duration, Instant};9use std::{borrow::Cow, io::Write};1011use anyhow::{anyhow, Result};12use crossbeam_channel::{bounded, Receiver, RecvTimeoutError, Sender};13use ignore::overrides::OverrideBuilder;14use ignore::{self, WalkBuilder};15use regex::bytes::Regex;16
31 unmodified lines
48///49/// If the `--exec` argument was supplied, this will create a thread pool for executing50/// jobs in parallel from a given command line and the discovered paths. Otherwise, each51/// path will simply be written to standard output.52pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<Config>) -> Result<ExitCode> {53 let mut path_iter = path_vec.iter();54 let first_path_buf = path_iter55 .next()56 .expect("Error: Path vector can not be empty");57 let (tx, rx) = channel();52pub fn scan(paths: &[PathBuf], pattern: Arc<Regex>, config: Arc<Config>) -> Result<ExitCode> {53 let first_path = &paths[0];5459 let mut override_builder = OverrideBuilder::new(first_path_buf.as_path());55 // Channel capacity was chosen empircally to perform similarly to an unbounded channel56 let (tx, rx) = bounded(0x4000 * config.threads);5758 let mut override_builder = OverrideBuilder::new(first_path);5960 for pattern in &config.exclude_patterns {61 override_builder62 .add(pattern)63 .map_err(|e| anyhow!("Malformed exclude pattern: {}", e))?;
1 unmodified line
65 let overrides = override_builder66 .build()67 .map_err(|_| anyhow!("Mismatch in exclude patterns"))?;6870 let mut walker = WalkBuilder::new(first_path_buf.as_path());69 let mut walker = WalkBuilder::new(first_path);70 walker71 .hidden(config.ignore_hidden)72 .ignore(config.read_fdignore)73 .parents(config.read_parent_ignore && (config.read_fdignore || config.read_vcsignore))
45 unmodified lines
119 None => (),120 }121 }122124 for path_entry in path_iter {125 walker.add(path_entry.as_path());123 for path in &paths[1..] {124 walker.add(path);125 }126127 let parallel_walker = walker.threads(config.threads).build_parallel();128
94 unmodified lines
223 fn recv(&self) -> Result<WorkerResult, RecvTimeoutError> {224 match self.mode {225 ReceiverMode::Buffering => {226 // Wait at most until we should switch to streaming228 let now = Instant::now();229 self.deadline230 .checked_duration_since(now)231 .ok_or(RecvTimeoutError::Timeout)232 .and_then(|t| self.rx.recv_timeout(t))227 self.rx.recv_deadline(self.deadline)228 }229 ReceiverMode::Streaming => {230 // Wait however long it takes for a result231 Ok(self.rx.recv()?)
110 unmodified lines
342 if let Some(ref cmd) = config.command {343 if cmd.in_batch_mode() {344 exec::batch(rx, cmd, &config)345 } else {351 let shared_rx = Arc::new(Mutex::new(rx));352346 let out_perm = Arc::new(Mutex::new(()));347348 // Each spawned job will store it's thread handle in here.349 let mut handles = Vec::with_capacity(threads);350 for _ in 0..threads {351 let config = Arc::clone(&config);359 let rx = Arc::clone(&shared_rx);352 let rx = rx.clone();353 let cmd = Arc::clone(cmd);354 let out_perm = Arc::clone(&out_perm);355356 // Spawn a job thread that will listen for and execute inputs.
195 unmodified lines
modified:Cargo.lock+11 added
173 unmodified lines
174source = "registry+https://github.com/rust-lang/crates.io-index"175checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"176177[[package]]178name = "crossbeam-channel"179version = "0.5.6"180source = "registry+https://github.com/rust-lang/crates.io-index"181checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521"182dependencies = [183 "cfg-if",184 "crossbeam-utils",185]186187[[package]]188name = "crossbeam-utils"189version = "0.8.12"190source = "registry+https://github.com/rust-lang/crates.io-index"191checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac"
124 unmodified lines
316 "atty",317 "chrono",318 "clap",319 "clap_complete",320 "crossbeam-channel",321 "ctrlc",322 "diff",323 "dirs-next",324 "faccess",
793 unmodified lines
modified:Cargo.toml+1 added
modified:CHANGELOG.md+5 added-1 removed
8 unmodified lines
9- Fixed differences between piped / non-piped output. This changes `fd`s behavior back to what we10 had before 8.3.0, i.e. there will be no leading `./` prefixes, unless `--exec`/`-x`,11 `--exec-batch`/`-X`, or `--print0`/`-0` are used. `--strip-cwd-prefix` can be used to strip that12 prefix in those cases. See #1046, #1115, and #1121 (@tavianator)13- `fd` could previously crash with a panic due to a race condition in Rusts standard library14 (see https://github.com/rust-lang/rust/issues/39364). This has been fixed by switching to a different15 message passing implementation, see #1060 and #1146 (@tavianator)16- `fd`s memory usage will not grow unboundedly on huge directory trees, see #1146 (@tavianator)17- fd returns an error when current working directory does not exist while a search path is18 specified, see #1072 (@vijfhoek)19- Improved "command not found" error message, see #1083 and #1109 (@themkat)2021## Changes2223- No leading `./` prefix for non-interactive results, see above.24- fd now colorizes paths in parallel, significantly improving performance, see #1148 (@tavianator)25- fd can now avoid `stat` syscalls even when colorizing paths, as long as the color scheme doesn't26 require metadata, see #1148 (@tavianator)22- fd now colorizes paths in parallel, significantly improving performance, see #1148 (@tavianator)2728## Other2930- Added link back to GitHub in man page and `--help` text, see #1086 (@scottchiefbaker)
593 unmodified lines