diff rust/rhg/src/ui.rs @ 49513:467d9df98c68

rhg: centralize PlainInfo
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Thu, 22 Sep 2022 17:16:54 -0400
parents 6939d5ed20e0
children 364e78389653
line wrap: on
line diff
--- a/rust/rhg/src/ui.rs	Tue Sep 20 18:16:50 2022 -0400
+++ b/rust/rhg/src/ui.rs	Thu Sep 22 17:16:54 2022 -0400
@@ -3,10 +3,9 @@
 use format_bytes::format_bytes;
 use format_bytes::write_bytes;
 use hg::config::Config;
+use hg::config::PlainInfo;
 use hg::errors::HgError;
-use hg::utils::files::get_bytes_from_os_string;
 use std::borrow::Cow;
-use std::env;
 use std::io;
 use std::io::{ErrorKind, Write};
 
@@ -129,29 +128,13 @@
     }
 }
 
-/// Return whether plain mode is 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
+// TODO: pass the PlainInfo to call sites directly and
+// delete this function
 pub fn plain(opt_feature: Option<&str>) -> bool {
-    if let Some(except) = env::var_os("HGPLAINEXCEPT") {
-        opt_feature.map_or(true, |feature| {
-            get_bytes_from_os_string(except)
-                .split(|&byte| byte == b',')
-                .all(|exception| exception != feature.as_bytes())
-        })
-    } else {
-        env::var_os("HGPLAIN").is_some()
+    let plain_info = PlainInfo::from_env();
+    match opt_feature {
+        None => plain_info.is_plain(),
+        Some(feature) => plain_info.is_feature_plain(feature),
     }
 }