Mercurial > public > mercurial-scm > hg-stable
comparison rust/rhg/src/commands/files.rs @ 48391:10c32e1b892a
rhg: Propogate manifest parse errors instead of panicking
The Rust parser for the manifest file format is an iterator. Now every item
from that iterator is a `Result`, which makes error handling required
in multiple new places.
This makes better recovery on errors possible, compare to a run time panic.
Differential Revision: https://phab.mercurial-scm.org/D11771
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Tue, 23 Nov 2021 18:27:42 +0100 |
parents | 9ecf802b06e0 |
children | 005ae1a343f8 |
comparison
equal
deleted
inserted
replaced
48390:51f26c8088b2 | 48391:10c32e1b892a |
---|---|
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::ui::UiError; |
4 use crate::utils::path_utils::relativize_paths; | 4 use crate::utils::path_utils::relativize_paths; |
5 use clap::Arg; | 5 use clap::Arg; |
6 use hg::errors::HgError; | |
6 use hg::operations::list_rev_tracked_files; | 7 use hg::operations::list_rev_tracked_files; |
7 use hg::operations::Dirstate; | 8 use hg::operations::Dirstate; |
8 use hg::repo::Repo; | 9 use hg::repo::Repo; |
9 use hg::utils::hg_path::HgPath; | 10 use hg::utils::hg_path::HgPath; |
10 use std::borrow::Cow; | 11 use std::borrow::Cow; |
43 let files = list_rev_tracked_files(repo, rev).map_err(|e| (e, rev))?; | 44 let files = list_rev_tracked_files(repo, rev).map_err(|e| (e, rev))?; |
44 display_files(invocation.ui, repo, files.iter()) | 45 display_files(invocation.ui, repo, files.iter()) |
45 } else { | 46 } else { |
46 let distate = Dirstate::new(repo)?; | 47 let distate = Dirstate::new(repo)?; |
47 let files = distate.tracked_files()?; | 48 let files = distate.tracked_files()?; |
48 display_files(invocation.ui, repo, files) | 49 display_files(invocation.ui, repo, files.into_iter().map(Ok)) |
49 } | 50 } |
50 } | 51 } |
51 | 52 |
52 fn display_files<'a>( | 53 fn display_files<'a>( |
53 ui: &Ui, | 54 ui: &Ui, |
54 repo: &Repo, | 55 repo: &Repo, |
55 files: impl IntoIterator<Item = &'a HgPath>, | 56 files: impl IntoIterator<Item = Result<&'a HgPath, HgError>>, |
56 ) -> Result<(), CommandError> { | 57 ) -> Result<(), CommandError> { |
57 let mut stdout = ui.stdout_buffer(); | 58 let mut stdout = ui.stdout_buffer(); |
58 let mut any = false; | 59 let mut any = false; |
59 | 60 |
60 relativize_paths(repo, files, |path: Cow<[u8]>| -> Result<(), UiError> { | 61 relativize_paths(repo, files, |path: Cow<[u8]>| -> Result<(), UiError> { |