[Request] [+- ] D10912: rhg: add ui.plain() and check it before showing relative paths in status

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Fri Jun 25 09:34:38 UTC 2021


pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Adds a very basic replica of `ui.plain()`.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10912

AFFECTED FILES
  rust/rhg/src/commands/status.rs
  rust/rhg/src/ui.rs

CHANGE DETAILS

diff --git a/rust/rhg/src/ui.rs b/rust/rhg/src/ui.rs
--- a/rust/rhg/src/ui.rs
+++ b/rust/rhg/src/ui.rs
@@ -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,28 @@
 
         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
+        match env::var("HGPLAIN") {
+            Ok(_) => true,
+            Err(_) => false,
+        }
+    }
 }
 
 /// A buffered stdout writer for faster batch printing operations.
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
@@ -290,7 +290,7 @@
     relative = config
         .get_bool(b"commands", b"status.relative")
         .unwrap_or(relative);
-    if relative {
+    if relative && !ui.plain() {
         let cwd = current_dir()?;
         let working_directory = repo.working_directory_path();
         let working_directory = cwd.join(working_directory); // Make it absolute



To: pulkit, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20210625/1b8ee75d/attachment.html>


More information about the Mercurial-patches mailing list