Mercurial > public > mercurial-scm > hg
diff rust/rhg/src/commands/files.rs @ 48453:9b0e1f64656f
rhg: refactor relativize_path into a struct + method
? instead of a function that takes an iterator and a callback.
Differential Revision: https://phab.mercurial-scm.org/D11898
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Fri, 10 Dec 2021 16:57:39 +0100 |
parents | 005ae1a343f8 |
children | 37bc3edef76f |
line wrap: on
line diff
--- a/rust/rhg/src/commands/files.rs Fri Dec 10 16:31:16 2021 +0100 +++ b/rust/rhg/src/commands/files.rs Fri Dec 10 16:57:39 2021 +0100 @@ -1,14 +1,12 @@ use crate::error::CommandError; use crate::ui::Ui; -use crate::ui::UiError; -use crate::utils::path_utils::relativize_paths; +use crate::utils::path_utils::RelativizePaths; use clap::Arg; use hg::errors::HgError; use hg::operations::list_rev_tracked_files; use hg::operations::Dirstate; use hg::repo::Repo; use hg::utils::hg_path::HgPath; -use std::borrow::Cow; pub const HELP_TEXT: &str = " List tracked files. @@ -86,11 +84,14 @@ let mut stdout = ui.stdout_buffer(); let mut any = false; - relativize_paths(repo, files, |path: Cow<[u8]>| -> Result<(), UiError> { + let relativize = RelativizePaths::new(repo)?; + for result in files { + let path = result?; + stdout.write_all(&relativize.relativize(path))?; + stdout.write_all(b"\n")?; any = true; - stdout.write_all(path.as_ref())?; - stdout.write_all(b"\n") - })?; + } + stdout.flush()?; if any { Ok(())