# HG changeset patch # User Arseniy Alekseyev # Date 2022-08-24 15:38:13 # Node ID b07465adbcc8588a9f476b003bdcb115e0d2e7d2 # Parent 44d4fd09982fe6105f821df58454f39489cf6edd rhg: make [rhg status -v] work when it needs no extra output Add support for verbose [status] when no extra output is actually needed. This makes it so that [rhg status] is actually useful when [tweakdefaults] is true. (since tweakdefaults implies verbose status) diff --git a/rust/hg-core/src/dirstate.rs b/rust/hg-core/src/dirstate.rs --- a/rust/hg-core/src/dirstate.rs +++ b/rust/hg-core/src/dirstate.rs @@ -30,6 +30,10 @@ impl DirstateParents { p1: NULL_NODE, p2: NULL_NODE, }; + + pub fn is_merge(&self) -> bool { + return !(self.p2 == NULL_NODE); + } } pub type StateMapIter<'a> = Box< diff --git a/rust/rhg/src/commands/status.rs b/rust/rhg/src/commands/status.rs --- a/rust/rhg/src/commands/status.rs +++ b/rust/rhg/src/commands/status.rs @@ -104,6 +104,12 @@ pub fn args() -> clap::App<'static, 'sta .short("-n") .long("--no-status"), ) + .arg( + Arg::with_name("verbose") + .help("enable additional output") + .short("-v") + .long("--verbose"), + ) } /// Pure data type allowing the caller to specify file states to display @@ -150,6 +156,33 @@ impl DisplayStates { } } +fn has_unfinished_merge(repo: &Repo) -> Result { + return Ok(repo.dirstate_parents()?.is_merge()); +} + +fn has_unfinished_state(repo: &Repo) -> Result { + // These are all the known values for the [fname] argument of + // [addunfinished] function in [state.py] + let known_state_files: &[&str] = &[ + "bisect.state", + "graftstate", + "histedit-state", + "rebasestate", + "shelvedstate", + "transplant/journal", + "updatestate", + ]; + if has_unfinished_merge(repo)? { + return Ok(true); + }; + for f in known_state_files { + if repo.hg_vfs().join(f).exists() { + return Ok(true); + } + } + return Ok(false); +} + pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { // TODO: lift these limitations if invocation.config.get_bool(b"ui", b"tweakdefaults")? { @@ -178,13 +211,9 @@ pub fn run(invocation: &crate::CliInvoca let verbose = !ui.plain(None) && !args.is_present("print0") - && (config.get_bool(b"ui", b"verbose")? + && (args.is_present("verbose") + || config.get_bool(b"ui", b"verbose")? || config.get_bool(b"commands", b"status.verbose")?); - if verbose { - return Err(CommandError::unsupported( - "verbose status is not supported yet", - )); - } let all = args.is_present("all"); let display_states = if all { @@ -214,6 +243,14 @@ pub fn run(invocation: &crate::CliInvoca let repo = invocation.repo?; + if verbose { + if has_unfinished_state(repo)? { + return Err(CommandError::unsupported( + "verbose status output is not supported by rhg (and is needed because we're in an unfinished operation)", + )); + }; + } + if repo.has_sparse() || repo.has_narrow() { return Err(CommandError::unsupported( "rhg status is not supported for sparse checkouts or narrow clones yet"