##// END OF EJS Templates
rhg: Add support for `rhg status -n`...
Simon Sapin -
r49171:c12ed335 default
parent child Browse files
Show More
@@ -6,9 +6,10 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, UiError};
9 use crate::ui::Ui;
10 use crate::utils::path_utils::relativize_paths;
10 use crate::utils::path_utils::relativize_paths;
11 use clap::{Arg, SubCommand};
11 use clap::{Arg, SubCommand};
12 use format_bytes::format_bytes;
12 use hg;
13 use hg;
13 use hg::config::Config;
14 use hg::config::Config;
14 use hg::dirstate::{has_exec_bit, TruncatedTimestamp};
15 use hg::dirstate::{has_exec_bit, TruncatedTimestamp};
@@ -20,7 +21,6 b' use hg::utils::files::get_bytes_from_os_'
20 use hg::utils::hg_path::{hg_path_to_os_string, HgPath};
21 use hg::utils::hg_path::{hg_path_to_os_string, HgPath};
21 use hg::{HgPathCow, StatusOptions};
22 use hg::{HgPathCow, StatusOptions};
22 use log::{info, warn};
23 use log::{info, warn};
23 use std::borrow::Cow;
24
24
25 pub const HELP_TEXT: &str = "
25 pub const HELP_TEXT: &str = "
26 Show changed files in the working directory
26 Show changed files in the working directory
@@ -82,6 +82,12 b" pub fn args() -> clap::App<'static, 'sta"
82 .short("-i")
82 .short("-i")
83 .long("--ignored"),
83 .long("--ignored"),
84 )
84 )
85 .arg(
86 Arg::with_name("no-status")
87 .help("hide status prefix")
88 .short("-n")
89 .long("--no-status"),
90 )
85 }
91 }
86
92
87 /// Pure data type allowing the caller to specify file states to display
93 /// Pure data type allowing the caller to specify file states to display
@@ -182,6 +188,7 b' pub fn run(invocation: &crate::CliInvoca'
182 requested
188 requested
183 }
189 }
184 };
190 };
191 let no_status = args.is_present("no-status");
185
192
186 let repo = invocation.repo?;
193 let repo = invocation.repo?;
187 let mut dmap = repo.dirstate_map_mut()?;
194 let mut dmap = repo.dirstate_map_mut()?;
@@ -240,25 +247,74 b' pub fn run(invocation: &crate::CliInvoca'
240 }
247 }
241 }
248 }
242 if display_states.modified {
249 if display_states.modified {
243 display_status_paths(ui, repo, config, &mut ds_status.modified, b"M")?;
250 display_status_paths(
251 ui,
252 repo,
253 config,
254 no_status,
255 &mut ds_status.modified,
256 b"M",
257 )?;
244 }
258 }
245 if display_states.added {
259 if display_states.added {
246 display_status_paths(ui, repo, config, &mut ds_status.added, b"A")?;
260 display_status_paths(
261 ui,
262 repo,
263 config,
264 no_status,
265 &mut ds_status.added,
266 b"A",
267 )?;
247 }
268 }
248 if display_states.removed {
269 if display_states.removed {
249 display_status_paths(ui, repo, config, &mut ds_status.removed, b"R")?;
270 display_status_paths(
271 ui,
272 repo,
273 config,
274 no_status,
275 &mut ds_status.removed,
276 b"R",
277 )?;
250 }
278 }
251 if display_states.deleted {
279 if display_states.deleted {
252 display_status_paths(ui, repo, config, &mut ds_status.deleted, b"!")?;
280 display_status_paths(
281 ui,
282 repo,
283 config,
284 no_status,
285 &mut ds_status.deleted,
286 b"!",
287 )?;
253 }
288 }
254 if display_states.unknown {
289 if display_states.unknown {
255 display_status_paths(ui, repo, config, &mut ds_status.unknown, b"?")?;
290 display_status_paths(
291 ui,
292 repo,
293 config,
294 no_status,
295 &mut ds_status.unknown,
296 b"?",
297 )?;
256 }
298 }
257 if display_states.ignored {
299 if display_states.ignored {
258 display_status_paths(ui, repo, config, &mut ds_status.ignored, b"I")?;
300 display_status_paths(
301 ui,
302 repo,
303 config,
304 no_status,
305 &mut ds_status.ignored,
306 b"I",
307 )?;
259 }
308 }
260 if display_states.clean {
309 if display_states.clean {
261 display_status_paths(ui, repo, config, &mut ds_status.clean, b"C")?;
310 display_status_paths(
311 ui,
312 repo,
313 config,
314 no_status,
315 &mut ds_status.clean,
316 b"C",
317 )?;
262 }
318 }
263 Ok(())
319 Ok(())
264 }
320 }
@@ -269,6 +325,7 b' fn display_status_paths('
269 ui: &Ui,
325 ui: &Ui,
270 repo: &Repo,
326 repo: &Repo,
271 config: &Config,
327 config: &Config,
328 no_status: bool,
272 paths: &mut [HgPathCow],
329 paths: &mut [HgPathCow],
273 status_prefix: &[u8],
330 status_prefix: &[u8],
274 ) -> Result<(), CommandError> {
331 ) -> Result<(), CommandError> {
@@ -277,23 +334,23 b' fn display_status_paths('
277 relative = config
334 relative = config
278 .get_option(b"commands", b"status.relative")?
335 .get_option(b"commands", b"status.relative")?
279 .unwrap_or(relative);
336 .unwrap_or(relative);
337 let print_path = |path: &[u8]| {
338 // TODO optim, probably lots of unneeded copies here, especially
339 // if out stream is buffered
340 if no_status {
341 ui.write_stdout(&format_bytes!(b"{}\n", path))
342 } else {
343 ui.write_stdout(&format_bytes!(b"{} {}\n", status_prefix, path))
344 }
345 };
346
280 if relative && !ui.plain() {
347 if relative && !ui.plain() {
281 relativize_paths(
348 relativize_paths(repo, paths.iter().map(Ok), |path| {
282 repo,
349 print_path(&path)
283 paths.iter().map(Ok),
350 })?;
284 |path: Cow<[u8]>| -> Result<(), UiError> {
285 ui.write_stdout(
286 &[status_prefix, b" ", path.as_ref(), b"\n"].concat(),
287 )
288 },
289 )?;
290 } else {
351 } else {
291 for path in paths {
352 for path in paths {
292 // Same TODO as in commands::root
353 print_path(path.as_bytes())?
293 let bytes: &[u8] = path.as_bytes();
294 // TODO optim, probably lots of unneeded copies here, especially
295 // if out stream is buffered
296 ui.write_stdout(&[status_prefix, b" ", bytes, b"\n"].concat())?;
297 }
354 }
298 }
355 }
299 Ok(())
356 Ok(())
@@ -222,6 +222,13 b' hg status:'
222 ! deleted
222 ! deleted
223 ? unknown
223 ? unknown
224
224
225 hg status -n:
226 $ env RHG_STATUS=1 RHG_ON_UNSUPPORTED=abort hg status -n
227 added
228 removed
229 deleted
230 unknown
231
225 hg status modified added removed deleted unknown never-existed ignored:
232 hg status modified added removed deleted unknown never-existed ignored:
226
233
227 $ hg status modified added removed deleted unknown never-existed ignored
234 $ hg status modified added removed deleted unknown never-existed ignored
General Comments 0
You need to be logged in to leave comments. Login now