1 use crate::commands::Command; |
1 use crate::commands::Command; |
2 use crate::error::CommandError; |
2 use crate::error::CommandError; |
3 use crate::ui::utf8_to_local; |
|
4 use crate::ui::Ui; |
3 use crate::ui::Ui; |
5 use hg::operations::{list_rev_tracked_files, ListRevTrackedFilesError}; |
4 use hg::operations::list_rev_tracked_files; |
6 use hg::operations::{Dirstate, ListDirstateTrackedFilesError}; |
5 use hg::operations::Dirstate; |
7 use hg::repo::Repo; |
6 use hg::repo::Repo; |
8 use hg::utils::files::{get_bytes_from_path, relativize_path}; |
7 use hg::utils::files::{get_bytes_from_path, relativize_path}; |
9 use hg::utils::hg_path::{HgPath, HgPathBuf}; |
8 use hg::utils::hg_path::{HgPath, HgPathBuf}; |
10 |
9 |
11 pub const HELP_TEXT: &str = " |
10 pub const HELP_TEXT: &str = " |
50 impl<'a> Command for FilesCommand<'a> { |
49 impl<'a> Command for FilesCommand<'a> { |
51 fn run(&self, ui: &Ui) -> Result<(), CommandError> { |
50 fn run(&self, ui: &Ui) -> Result<(), CommandError> { |
52 let repo = Repo::find()?; |
51 let repo = Repo::find()?; |
53 repo.check_requirements()?; |
52 repo.check_requirements()?; |
54 if let Some(rev) = self.rev { |
53 if let Some(rev) = self.rev { |
55 let files = list_rev_tracked_files(&repo, rev) |
54 let files = |
56 .map_err(|e| map_rev_error(rev, e))?; |
55 list_rev_tracked_files(&repo, rev).map_err(|e| (e, rev))?; |
57 self.display_files(ui, &repo, files.iter()) |
56 self.display_files(ui, &repo, files.iter()) |
58 } else { |
57 } else { |
59 let distate = Dirstate::new(&repo).map_err(map_dirstate_error)?; |
58 let distate = Dirstate::new(&repo)?; |
60 let files = distate.tracked_files().map_err(map_dirstate_error)?; |
59 let files = distate.tracked_files()?; |
61 self.display_files(ui, &repo, files) |
60 self.display_files(ui, &repo, files) |
62 } |
61 } |
63 } |
62 } |
64 } |
63 } |
65 |
|
66 /// Convert `ListRevTrackedFilesError` to `CommandError` |
|
67 fn map_rev_error(rev: &str, err: ListRevTrackedFilesError) -> CommandError { |
|
68 match err { |
|
69 ListRevTrackedFilesError::IoError(err) => CommandError::Abort(Some( |
|
70 utf8_to_local(&format!("abort: {}\n", err)).into(), |
|
71 )), |
|
72 ListRevTrackedFilesError::InvalidRevision => { |
|
73 CommandError::Abort(Some( |
|
74 utf8_to_local(&format!( |
|
75 "abort: invalid revision identifier {}\n", |
|
76 rev |
|
77 )) |
|
78 .into(), |
|
79 )) |
|
80 } |
|
81 ListRevTrackedFilesError::AmbiguousPrefix => { |
|
82 CommandError::Abort(Some( |
|
83 utf8_to_local(&format!( |
|
84 "abort: ambiguous revision identifier {}\n", |
|
85 rev |
|
86 )) |
|
87 .into(), |
|
88 )) |
|
89 } |
|
90 ListRevTrackedFilesError::UnsuportedRevlogVersion(version) => { |
|
91 CommandError::Abort(Some( |
|
92 utf8_to_local(&format!( |
|
93 "abort: unsupported revlog version {}\n", |
|
94 version |
|
95 )) |
|
96 .into(), |
|
97 )) |
|
98 } |
|
99 ListRevTrackedFilesError::CorruptedRevlog => { |
|
100 CommandError::Abort(Some("abort: corrupted revlog\n".into())) |
|
101 } |
|
102 ListRevTrackedFilesError::UnknowRevlogDataFormat(format) => { |
|
103 CommandError::Abort(Some( |
|
104 utf8_to_local(&format!( |
|
105 "abort: unknow revlog dataformat {:?}\n", |
|
106 format |
|
107 )) |
|
108 .into(), |
|
109 )) |
|
110 } |
|
111 } |
|
112 } |
|
113 |
|
114 /// Convert `ListDirstateTrackedFilesError` to `CommandError` |
|
115 fn map_dirstate_error(err: ListDirstateTrackedFilesError) -> CommandError { |
|
116 match err { |
|
117 ListDirstateTrackedFilesError::IoError(err) => CommandError::Abort( |
|
118 Some(utf8_to_local(&format!("abort: {}\n", err)).into()), |
|
119 ), |
|
120 ListDirstateTrackedFilesError::ParseError(_) => { |
|
121 CommandError::Abort(Some( |
|
122 // TODO find a better error message |
|
123 b"abort: parse error\n".to_vec(), |
|
124 )) |
|
125 } |
|
126 } |
|
127 } |
|