Skip to content
Snippets Groups Projects
Commit 707c5888 authored by Pulkit Goyal's avatar Pulkit Goyal
Browse files

rhg: add relative paths support in `rhg status`

Differential Revision: https://phab.mercurial-scm.org/D11614
parent 9ecf802b
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@
// GNU General Public License version 2 or any later version.
use crate::error::CommandError;
use crate::ui::Ui;
use crate::ui::{Ui, UiError};
use crate::utils::path_utils::relativize_paths;
use clap::{Arg, SubCommand};
use hg;
......@@ -10,5 +11,6 @@
use clap::{Arg, SubCommand};
use hg;
use hg::config::Config;
use hg::errors::HgError;
use hg::manifest::Manifest;
use hg::matchers::AlwaysMatcher;
......@@ -16,6 +18,7 @@
use hg::utils::hg_path::{hg_path_to_os_string, HgPath};
use hg::{HgPathCow, StatusOptions};
use log::{info, warn};
use std::borrow::Cow;
pub const HELP_TEXT: &str = "
Show changed files in the working directory
......@@ -146,6 +149,7 @@
}
let ui = invocation.ui;
let config = invocation.config;
let args = invocation.subcommand_args;
let display_states = if args.is_present("all") {
// TODO when implementing `--quiet`: it excludes clean files
......@@ -225,6 +229,6 @@
}
}
if display_states.modified {
display_status_paths(ui, &mut ds_status.modified, b"M")?;
display_status_paths(ui, repo, config, &mut ds_status.modified, b"M")?;
}
if display_states.added {
......@@ -229,5 +233,5 @@
}
if display_states.added {
display_status_paths(ui, &mut ds_status.added, b"A")?;
display_status_paths(ui, repo, config, &mut ds_status.added, b"A")?;
}
if display_states.removed {
......@@ -232,5 +236,5 @@
}
if display_states.removed {
display_status_paths(ui, &mut ds_status.removed, b"R")?;
display_status_paths(ui, repo, config, &mut ds_status.removed, b"R")?;
}
if display_states.deleted {
......@@ -235,5 +239,5 @@
}
if display_states.deleted {
display_status_paths(ui, &mut ds_status.deleted, b"!")?;
display_status_paths(ui, repo, config, &mut ds_status.deleted, b"!")?;
}
if display_states.unknown {
......@@ -238,5 +242,5 @@
}
if display_states.unknown {
display_status_paths(ui, &mut ds_status.unknown, b"?")?;
display_status_paths(ui, repo, config, &mut ds_status.unknown, b"?")?;
}
if display_states.ignored {
......@@ -241,5 +245,5 @@
}
if display_states.ignored {
display_status_paths(ui, &mut ds_status.ignored, b"I")?;
display_status_paths(ui, repo, config, &mut ds_status.ignored, b"I")?;
}
if display_states.clean {
......@@ -244,6 +248,6 @@
}
if display_states.clean {
display_status_paths(ui, &mut ds_status.clean, b"C")?;
display_status_paths(ui, repo, config, &mut ds_status.clean, b"C")?;
}
Ok(())
}
......@@ -252,7 +256,9 @@
// harcode HgPathBuf, but probably not really useful at this point
fn display_status_paths(
ui: &Ui,
repo: &Repo,
config: &Config,
paths: &mut [HgPathCow],
status_prefix: &[u8],
) -> Result<(), CommandError> {
paths.sort_unstable();
......@@ -255,13 +261,30 @@
paths: &mut [HgPathCow],
status_prefix: &[u8],
) -> Result<(), CommandError> {
paths.sort_unstable();
for path in paths {
// Same TODO as in commands::root
let bytes: &[u8] = path.as_bytes();
// TODO optim, probably lots of unneeded copies here, especially
// if out stream is buffered
ui.write_stdout(&[status_prefix, b" ", bytes, b"\n"].concat())?;
let mut relative: bool =
config.get_bool(b"ui", b"relative-paths").unwrap_or(false);
relative = config
.get_bool(b"commands", b"status.relative")
.unwrap_or(relative);
if relative {
relativize_paths(
repo,
paths,
|path: Cow<[u8]>| -> Result<(), UiError> {
ui.write_stdout(
&[status_prefix, b" ", path.as_ref(), b"\n"].concat(),
)
},
)?;
} else {
for path in paths {
// Same TODO as in commands::root
let bytes: &[u8] = path.as_bytes();
// TODO optim, probably lots of unneeded copies here, especially
// if out stream is buffered
ui.write_stdout(&[status_prefix, b" ", bytes, b"\n"].concat())?;
}
}
Ok(())
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment