1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Parallel text replacement across files with atomic writes.
//! Workload: I/O-bound (file reading + regex matching + atomic write) with
//! optional per-file CPU fuzzy cascade (single-buffer).
//! Parallelism: `ignore::WalkParallel` + bounded channel; worker bound via
//! `concurrency::apply_walk_threads` (`--threads` / `--max-concurrency`).
//! Progress precount (when enabled) also uses WalkParallel; skipped when
//! `--no-progress` / quiet / `progress_every=0` to avoid a double-walk.
//!
//! v0.1.33 one-shot: fuzzy multi uses [`crate::fuzzy::apply_fuzzy_one_pass`]
//! (never re-scans inserted replacement; default 1 apply; embeds force 1).
use std::borrow::Cow;
use std::io::Write;
use std::path::PathBuf;
use std::sync::Arc;
use std::sync::atomic::{AtomicU64, Ordering};
use std::time::Instant;
use anyhow::Result;
use regex::Regex;
use crate::atomic::AtomicWriteOptions;
use crate::checksum;
use crate::cli::{GlobalArgs, ReplaceArgs};
use crate::commands::resolve_backup;
use crate::fuzzy;
use crate::ndjson_types::{DryRunPlan, ProgressEvent, ReplaceResult, Summary};
use crate::output::NdjsonWriter;
use crate::signal::ShutdownSignal;
/// Replace text across files in parallel with atomic writes.
///
/// # Errors
///
/// Returns `AtomwriteError::WorkspaceJail` if the path escapes the workspace.
/// Returns `AtomwriteError::Io` if reading or writing files fails.
/// Returns `AtomwriteError::NoMatches` if no replacements are found.
#[tracing::instrument(skip_all, fields(command = "replace"))]
pub fn cmd_replace(
args: &ReplaceArgs,
global: &GlobalArgs,
writer: &mut NdjsonWriter<impl Write>,
shutdown: &ShutdownSignal,
defaults: &crate::config::DefaultsSection,
fuzzy_cfg: &crate::config::FuzzySection,
write_cfg: &crate::config::WriteSection,
) -> Result<()> {
run_replace(
args, global, writer, shutdown, defaults, fuzzy_cfg, write_cfg,
)
}
include!("replace_run.inc.rs");
include!("replace_finish.inc.rs");
include!("replace_helpers.inc.rs");