changeset 49439:b07465adbcc8

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)
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Wed, 24 Aug 2022 16:38:13 +0100
parents 44d4fd09982f
children a0b57cabc245
files rust/hg-core/src/dirstate.rs rust/rhg/src/commands/status.rs
diffstat 2 files changed, 47 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate.rs	Thu Jul 28 16:25:21 2022 +0200
+++ b/rust/hg-core/src/dirstate.rs	Wed Aug 24 16:38:13 2022 +0100
@@ -30,6 +30,10 @@
         p1: NULL_NODE,
         p2: NULL_NODE,
     };
+
+    pub fn is_merge(&self) -> bool {
+        return !(self.p2 == NULL_NODE);
+    }
 }
 
 pub type StateMapIter<'a> = Box<
--- a/rust/rhg/src/commands/status.rs	Thu Jul 28 16:25:21 2022 +0200
+++ b/rust/rhg/src/commands/status.rs	Wed Aug 24 16:38:13 2022 +0100
@@ -104,6 +104,12 @@
                 .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 @@
     }
 }
 
+fn has_unfinished_merge(repo: &Repo) -> Result<bool, CommandError> {
+    return Ok(repo.dirstate_parents()?.is_merge());
+}
+
+fn has_unfinished_state(repo: &Repo) -> Result<bool, CommandError> {
+    // 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 @@
 
     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 @@
 
     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"