##// END OF EJS Templates
rhg: add relative paths support in `rhg status`...
Pulkit Goyal -
r48989:707c5888 default
parent child Browse files
Show More
@@ -6,9 +6,11 b''
6 // GNU General Public License version 2 or any later version.
6 // GNU General Public License version 2 or any later version.
7
7
8 use crate::error::CommandError;
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 use clap::{Arg, SubCommand};
11 use clap::{Arg, SubCommand};
11 use hg;
12 use hg;
13 use hg::config::Config;
12 use hg::errors::HgError;
14 use hg::errors::HgError;
13 use hg::manifest::Manifest;
15 use hg::manifest::Manifest;
14 use hg::matchers::AlwaysMatcher;
16 use hg::matchers::AlwaysMatcher;
@@ -16,6 +18,7 b' use hg::repo::Repo;'
16 use hg::utils::hg_path::{hg_path_to_os_string, HgPath};
18 use hg::utils::hg_path::{hg_path_to_os_string, HgPath};
17 use hg::{HgPathCow, StatusOptions};
19 use hg::{HgPathCow, StatusOptions};
18 use log::{info, warn};
20 use log::{info, warn};
21 use std::borrow::Cow;
19
22
20 pub const HELP_TEXT: &str = "
23 pub const HELP_TEXT: &str = "
21 Show changed files in the working directory
24 Show changed files in the working directory
@@ -146,6 +149,7 b' pub fn run(invocation: &crate::CliInvoca'
146 }
149 }
147
150
148 let ui = invocation.ui;
151 let ui = invocation.ui;
152 let config = invocation.config;
149 let args = invocation.subcommand_args;
153 let args = invocation.subcommand_args;
150 let display_states = if args.is_present("all") {
154 let display_states = if args.is_present("all") {
151 // TODO when implementing `--quiet`: it excludes clean files
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 if display_states.modified {
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 if display_states.added {
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 if display_states.removed {
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 if display_states.deleted {
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 if display_states.unknown {
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 if display_states.ignored {
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 if display_states.clean {
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 Ok(())
252 Ok(())
249 }
253 }
@@ -252,16 +256,35 b' pub fn run(invocation: &crate::CliInvoca'
252 // harcode HgPathBuf, but probably not really useful at this point
256 // harcode HgPathBuf, but probably not really useful at this point
253 fn display_status_paths(
257 fn display_status_paths(
254 ui: &Ui,
258 ui: &Ui,
259 repo: &Repo,
260 config: &Config,
255 paths: &mut [HgPathCow],
261 paths: &mut [HgPathCow],
256 status_prefix: &[u8],
262 status_prefix: &[u8],
257 ) -> Result<(), CommandError> {
263 ) -> Result<(), CommandError> {
258 paths.sort_unstable();
264 paths.sort_unstable();
259 for path in paths {
265 let mut relative: bool =
260 // Same TODO as in commands::root
266 config.get_bool(b"ui", b"relative-paths").unwrap_or(false);
261 let bytes: &[u8] = path.as_bytes();
267 relative = config
262 // TODO optim, probably lots of unneeded copies here, especially
268 .get_bool(b"commands", b"status.relative")
263 // if out stream is buffered
269 .unwrap_or(relative);
264 ui.write_stdout(&[status_prefix, b" ", bytes, b"\n"].concat())?;
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 Ok(())
289 Ok(())
267 }
290 }
General Comments 0
You need to be logged in to leave comments. Login now