Mercurial > public > mercurial-scm > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
48452:2afaa0145584 | 48453:9b0e1f64656f |
---|---|
1 use crate::error::CommandError; | 1 use crate::error::CommandError; |
2 use crate::ui::Ui; | 2 use crate::ui::Ui; |
3 use crate::ui::UiError; | 3 use crate::utils::path_utils::RelativizePaths; |
4 use crate::utils::path_utils::relativize_paths; | |
5 use clap::Arg; | 4 use clap::Arg; |
6 use hg::errors::HgError; | 5 use hg::errors::HgError; |
7 use hg::operations::list_rev_tracked_files; | 6 use hg::operations::list_rev_tracked_files; |
8 use hg::operations::Dirstate; | 7 use hg::operations::Dirstate; |
9 use hg::repo::Repo; | 8 use hg::repo::Repo; |
10 use hg::utils::hg_path::HgPath; | 9 use hg::utils::hg_path::HgPath; |
11 use std::borrow::Cow; | |
12 | 10 |
13 pub const HELP_TEXT: &str = " | 11 pub const HELP_TEXT: &str = " |
14 List tracked files. | 12 List tracked files. |
15 | 13 |
16 Returns 0 on success. | 14 Returns 0 on success. |
84 files: impl IntoIterator<Item = Result<&'a HgPath, HgError>>, | 82 files: impl IntoIterator<Item = Result<&'a HgPath, HgError>>, |
85 ) -> Result<(), CommandError> { | 83 ) -> Result<(), CommandError> { |
86 let mut stdout = ui.stdout_buffer(); | 84 let mut stdout = ui.stdout_buffer(); |
87 let mut any = false; | 85 let mut any = false; |
88 | 86 |
89 relativize_paths(repo, files, |path: Cow<[u8]>| -> Result<(), UiError> { | 87 let relativize = RelativizePaths::new(repo)?; |
88 for result in files { | |
89 let path = result?; | |
90 stdout.write_all(&relativize.relativize(path))?; | |
91 stdout.write_all(b"\n")?; | |
90 any = true; | 92 any = true; |
91 stdout.write_all(path.as_ref())?; | 93 } |
92 stdout.write_all(b"\n") | 94 |
93 })?; | |
94 stdout.flush()?; | 95 stdout.flush()?; |
95 if any { | 96 if any { |
96 Ok(()) | 97 Ok(()) |
97 } else { | 98 } else { |
98 Err(CommandError::Unsuccessful) | 99 Err(CommandError::Unsuccessful) |