Show More
@@ -6,9 +6,11 b'' | |||
|
6 | 6 | // GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | use crate::error::CommandError; |
|
9 | use crate::ui::Ui; | |
|
9 | use crate::ui::{Ui, UiError}; | |
|
10 | use crate::utils::path_utils::relativize_paths; | |
|
10 | 11 | use clap::{Arg, SubCommand}; |
|
11 | 12 | use hg; |
|
13 | use hg::config::Config; | |
|
12 | 14 | use hg::errors::HgError; |
|
13 | 15 | use hg::manifest::Manifest; |
|
14 | 16 | use hg::matchers::AlwaysMatcher; |
@@ -16,6 +18,7 b' use hg::repo::Repo;' | |||
|
16 | 18 | use hg::utils::hg_path::{hg_path_to_os_string, HgPath}; |
|
17 | 19 | use hg::{HgPathCow, StatusOptions}; |
|
18 | 20 | use log::{info, warn}; |
|
21 | use std::borrow::Cow; | |
|
19 | 22 | |
|
20 | 23 | pub const HELP_TEXT: &str = " |
|
21 | 24 | Show changed files in the working directory |
@@ -146,6 +149,7 b' pub fn run(invocation: &crate::CliInvoca' | |||
|
146 | 149 | } |
|
147 | 150 | |
|
148 | 151 | let ui = invocation.ui; |
|
152 | let config = invocation.config; | |
|
149 | 153 | let args = invocation.subcommand_args; |
|
150 | 154 | let display_states = if args.is_present("all") { |
|
151 | 155 | // TODO when implementing `--quiet`: it excludes clean files |
@@ -225,25 +229,25 b' pub fn run(invocation: &crate::CliInvoca' | |||
|
225 | 229 | } |
|
226 | 230 | } |
|
227 | 231 | if display_states.modified { |
|
228 | display_status_paths(ui, &mut ds_status.modified, b"M")?; | |
|
232 | display_status_paths(ui, repo, config, &mut ds_status.modified, b"M")?; | |
|
229 | 233 | } |
|
230 | 234 | if display_states.added { |
|
231 | display_status_paths(ui, &mut ds_status.added, b"A")?; | |
|
235 | display_status_paths(ui, repo, config, &mut ds_status.added, b"A")?; | |
|
232 | 236 | } |
|
233 | 237 | if display_states.removed { |
|
234 | display_status_paths(ui, &mut ds_status.removed, b"R")?; | |
|
238 | display_status_paths(ui, repo, config, &mut ds_status.removed, b"R")?; | |
|
235 | 239 | } |
|
236 | 240 | if display_states.deleted { |
|
237 | display_status_paths(ui, &mut ds_status.deleted, b"!")?; | |
|
241 | display_status_paths(ui, repo, config, &mut ds_status.deleted, b"!")?; | |
|
238 | 242 | } |
|
239 | 243 | if display_states.unknown { |
|
240 | display_status_paths(ui, &mut ds_status.unknown, b"?")?; | |
|
244 | display_status_paths(ui, repo, config, &mut ds_status.unknown, b"?")?; | |
|
241 | 245 | } |
|
242 | 246 | if display_states.ignored { |
|
243 | display_status_paths(ui, &mut ds_status.ignored, b"I")?; | |
|
247 | display_status_paths(ui, repo, config, &mut ds_status.ignored, b"I")?; | |
|
244 | 248 | } |
|
245 | 249 | if display_states.clean { |
|
246 | display_status_paths(ui, &mut ds_status.clean, b"C")?; | |
|
250 | display_status_paths(ui, repo, config, &mut ds_status.clean, b"C")?; | |
|
247 | 251 | } |
|
248 | 252 | Ok(()) |
|
249 | 253 | } |
@@ -252,16 +256,35 b' pub fn run(invocation: &crate::CliInvoca' | |||
|
252 | 256 | // harcode HgPathBuf, but probably not really useful at this point |
|
253 | 257 | fn display_status_paths( |
|
254 | 258 | ui: &Ui, |
|
259 | repo: &Repo, | |
|
260 | config: &Config, | |
|
255 | 261 | paths: &mut [HgPathCow], |
|
256 | 262 | status_prefix: &[u8], |
|
257 | 263 | ) -> Result<(), CommandError> { |
|
258 | 264 | paths.sort_unstable(); |
|
259 | for path in paths { | |
|
260 | // Same TODO as in commands::root | |
|
261 | let bytes: &[u8] = path.as_bytes(); | |
|
262 | // TODO optim, probably lots of unneeded copies here, especially | |
|
263 | // if out stream is buffered | |
|
264 | ui.write_stdout(&[status_prefix, b" ", bytes, b"\n"].concat())?; | |
|
265 | let mut relative: bool = | |
|
266 | config.get_bool(b"ui", b"relative-paths").unwrap_or(false); | |
|
267 | relative = config | |
|
268 | .get_bool(b"commands", b"status.relative") | |
|
269 | .unwrap_or(relative); | |
|
270 | if relative { | |
|
271 | relativize_paths( | |
|
272 | repo, | |
|
273 | paths, | |
|
274 | |path: Cow<[u8]>| -> Result<(), UiError> { | |
|
275 | ui.write_stdout( | |
|
276 | &[status_prefix, b" ", path.as_ref(), b"\n"].concat(), | |
|
277 | ) | |
|
278 | }, | |
|
279 | )?; | |
|
280 | } else { | |
|
281 | for path in paths { | |
|
282 | // Same TODO as in commands::root | |
|
283 | let bytes: &[u8] = path.as_bytes(); | |
|
284 | // TODO optim, probably lots of unneeded copies here, especially | |
|
285 | // if out stream is buffered | |
|
286 | ui.write_stdout(&[status_prefix, b" ", bytes, b"\n"].concat())?; | |
|
287 | } | |
|
265 | 288 | } |
|
266 | 289 | Ok(()) |
|
267 | 290 | } |
General Comments 0
You need to be logged in to leave comments.
Login now