Patchwork D10912: rhg: add ui.plain() and check it before showing relative paths in status

login
register
mail settings
Submitter phabricator
Date June 25, 2021, 9:34 a.m.
Message ID <differential-rev-PHID-DREV-wptmx6aidlh56xwfvngz-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49226/
State Superseded
Headers show

Comments

phabricator - June 25, 2021, 9:34 a.m.
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




To: pulkit, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

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