rhg: add ui.plain() and check it before showing relative paths in status
authorPulkit Goyal <7895pulkit@gmail.com>
Fri, 25 Jun 2021 15:00:08 +0530
changeset 48176 38deb65d4441
parent 48175 707c58880cd0
child 48177 066cdec8f74f
rhg: add ui.plain() and check it before showing relative paths in status Adds a very basic replica of `ui.plain()`. Differential Revision: https://phab.mercurial-scm.org/D10912
rust/rhg/src/commands/status.rs
rust/rhg/src/ui.rs
--- a/rust/rhg/src/commands/status.rs	Tue Oct 05 18:10:04 2021 +0530
+++ b/rust/rhg/src/commands/status.rs	Fri Jun 25 15:00:08 2021 +0530
@@ -267,7 +267,7 @@
     relative = config
         .get_bool(b"commands", b"status.relative")
         .unwrap_or(relative);
-    if relative {
+    if relative && !ui.plain() {
         relativize_paths(
             repo,
             paths,
--- a/rust/rhg/src/ui.rs	Tue Oct 05 18:10:04 2021 +0530
+++ b/rust/rhg/src/ui.rs	Fri Jun 25 15:00:08 2021 +0530
@@ -1,5 +1,6 @@
 use format_bytes::format_bytes;
 use std::borrow::Cow;
+use std::env;
 use std::io;
 use std::io::{ErrorKind, Write};
 
@@ -49,6 +50,25 @@
 
         stderr.flush().or_else(handle_stderr_error)
     }
+
+    /// is plain mode active
+    ///
+    /// Plain mode means that all configuration variables which affect
+    /// the behavior and output of Mercurial should be
+    /// ignored. Additionally, the output should be stable,
+    /// reproducible and suitable for use in scripts or applications.
+    ///
+    /// The only way to trigger plain mode is by setting either the
+    /// `HGPLAIN' or `HGPLAINEXCEPT' environment variables.
+    ///
+    /// The return value can either be
+    /// - False if HGPLAIN is not set, or feature is in HGPLAINEXCEPT
+    /// - False if feature is disabled by default and not included in HGPLAIN
+    /// - True otherwise
+    pub fn plain(&self) -> bool {
+        // TODO: add support for HGPLAINEXCEPT
+        env::var_os("HGPLAIN").is_some()
+    }
 }
 
 /// A buffered stdout writer for faster batch printing operations.