Details
Details
- Reviewers
Alphare - Group Reviewers
hg-reviewers - Commits
- rHG99b1dfc06571: rhg: Add support for HGPLAINEXPECT
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Branch
- default
- Lint
No Linters Available - Unit
No Unit Test Coverage
( )
Alphare |
hg-reviewers |
No Linters Available |
No Unit Test Coverage |
Path | Packages | |||
---|---|---|---|---|
M | rust/rhg/src/commands/status.rs (4 lines) | |||
M | rust/rhg/src/main.rs (4 lines) | |||
M | rust/rhg/src/ui.rs (16 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
cb399b5ee2ba | 3199b575375d | Simon Sapin | Feb 10 2022, 5:58 AM |
Status | Author | Revision | |
---|---|---|---|
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin |
"status.terse is not yet supported with rhg status", | "status.terse is not yet supported with rhg status", | ||||
)); | )); | ||||
} | } | ||||
let ui = invocation.ui; | let ui = invocation.ui; | ||||
let config = invocation.config; | let config = invocation.config; | ||||
let args = invocation.subcommand_args; | let args = invocation.subcommand_args; | ||||
let verbose = !ui.plain() | let verbose = !ui.plain(None) | ||||
&& !args.is_present("print0") | && !args.is_present("print0") | ||||
&& (config.get_bool(b"ui", b"verbose")? | && (config.get_bool(b"ui", b"verbose")? | ||||
|| config.get_bool(b"commands", b"status.verbose")?); | || config.get_bool(b"commands", b"status.verbose")?); | ||||
if verbose { | if verbose { | ||||
return Err(CommandError::unsupported( | return Err(CommandError::unsupported( | ||||
"verbose status is not supported yet", | "verbose status is not supported yet", | ||||
)); | )); | ||||
} | } | ||||
} else { | } else { | ||||
if display_states.clean { | if display_states.clean { | ||||
ds_status.clean.push(to_check.clone()); | ds_status.clean.push(to_check.clone()); | ||||
} | } | ||||
fixup.push(to_check.path.into_owned()) | fixup.push(to_check.path.into_owned()) | ||||
} | } | ||||
} | } | ||||
} | } | ||||
let relative_paths = (!ui.plain()) | let relative_paths = (!ui.plain(None)) | ||||
&& config | && config | ||||
.get_option(b"commands", b"status.relative")? | .get_option(b"commands", b"status.relative")? | ||||
.unwrap_or(config.get_bool(b"ui", b"relative-paths")?); | .unwrap_or(config.get_bool(b"ui", b"relative-paths")?); | ||||
let output = DisplayStatusPaths { | let output = DisplayStatusPaths { | ||||
ui, | ui, | ||||
no_status, | no_status, | ||||
relativize: if relative_paths { | relativize: if relative_paths { | ||||
Some(RelativizePaths::new(repo)?) | Some(RelativizePaths::new(repo)?) |
Err(CommandError::unsupported("[encode] config"))? | Err(CommandError::unsupported("[encode] config"))? | ||||
} | } | ||||
if config.has_non_empty_section(b"decode") { | if config.has_non_empty_section(b"decode") { | ||||
Err(CommandError::unsupported("[decode] config"))? | Err(CommandError::unsupported("[decode] config"))? | ||||
} | } | ||||
if let Some(color) = config.get(b"ui", b"color") { | if let Some(color) = config.get(b"ui", b"color") { | ||||
if (color == b"always" || color == b"debug") && !ui.plain() { | if (color == b"always" || color == b"debug") | ||||
&& !ui.plain(Some("color")) | |||||
{ | |||||
Err(CommandError::unsupported("colored output"))? | Err(CommandError::unsupported("colored output"))? | ||||
} | } | ||||
} | } | ||||
Ok(()) | Ok(()) | ||||
} | } |
use format_bytes::format_bytes; | use format_bytes::format_bytes; | ||||
use hg::utils::files::get_bytes_from_os_string; | |||||
use std::borrow::Cow; | use std::borrow::Cow; | ||||
use std::env; | use std::env; | ||||
use std::io; | use std::io; | ||||
use std::io::{ErrorKind, Write}; | use std::io::{ErrorKind, Write}; | ||||
#[derive(Debug)] | #[derive(Debug)] | ||||
pub struct Ui { | pub struct Ui { | ||||
stdout: std::io::Stdout, | stdout: std::io::Stdout, | ||||
/// | /// | ||||
/// The only way to trigger plain mode is by setting either the | /// The only way to trigger plain mode is by setting either the | ||||
/// `HGPLAIN' or `HGPLAINEXCEPT' environment variables. | /// `HGPLAIN' or `HGPLAINEXCEPT' environment variables. | ||||
/// | /// | ||||
/// The return value can either be | /// The return value can either be | ||||
/// - False if HGPLAIN is not set, or feature is in HGPLAINEXCEPT | /// - False if HGPLAIN is not set, or feature is in HGPLAINEXCEPT | ||||
/// - False if feature is disabled by default and not included in HGPLAIN | /// - False if feature is disabled by default and not included in HGPLAIN | ||||
/// - True otherwise | /// - True otherwise | ||||
pub fn plain(&self) -> bool { | pub fn plain(&self, feature: Option<&str>) -> bool { | ||||
// TODO: add support for HGPLAINEXCEPT | plain(feature) | ||||
} | |||||
} | |||||
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',') | |||||
.any(|exception| exception == feature.as_bytes()) | |||||
}) | |||||
} else { | |||||
env::var_os("HGPLAIN").is_some() | env::var_os("HGPLAIN").is_some() | ||||
} | } | ||||
} | } | ||||
/// A buffered stdout writer for faster batch printing operations. | /// A buffered stdout writer for faster batch printing operations. | ||||
pub struct StdoutBuffer<W: Write> { | pub struct StdoutBuffer<W: Write> { | ||||
buf: io::BufWriter<W>, | buf: io::BufWriter<W>, | ||||
} | } |