ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: parse graph node settings strictly

This commit is contained in:
Yuya Nishihara 2024-09-03 17:01:22 +09:00
parent 406ead241b
commit 36ab165b57
8 changed files with 30 additions and 19 deletions

View file

@ -11,6 +11,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### Breaking changes
* Invalid `ui.graph.style` configuration is now an error.
### Deprecations
* `jj obslog` is now called `jj evolution-log`/`jj evolog`. `jj obslog` remains

View file

@ -105,7 +105,7 @@ pub(crate) fn cmd_evolog(
node_template = workspace_command
.parse_template(
&language,
&get_node_template(command.settings()),
&get_node_template(command.settings())?,
CommitTemplateLanguage::wrap_commit_opt,
)?
.labeled("node");
@ -144,7 +144,7 @@ pub(crate) fn cmd_evolog(
commits.truncate(n);
}
if !args.no_graph {
let graph_style = GraphStyle::from_settings(command.settings());
let graph_style = GraphStyle::from_settings(command.settings())?;
let mut graph = get_graphlog(graph_style, formatter.raw());
for commit in commits {
let mut edges = vec![];

View file

@ -145,7 +145,7 @@ pub(crate) fn cmd_log(
node_template = workspace_command
.parse_template(
&language,
&get_node_template(command.settings()),
&get_node_template(command.settings())?,
CommitTemplateLanguage::wrap_commit_opt,
)?
.labeled("node");
@ -165,7 +165,7 @@ pub(crate) fn cmd_log(
let limit = args.limit.or(args.deprecated_limit).unwrap_or(usize::MAX);
if !args.no_graph {
let graph_style = GraphStyle::from_settings(command.settings());
let graph_style = GraphStyle::from_settings(command.settings())?;
let mut graph = get_graphlog(graph_style, formatter.raw());
let forward_iter = TopoGroupedGraphIterator::new(revset.iter_graph());
let iter: Box<dyn Iterator<Item = _>> = if args.reversed {
@ -297,7 +297,7 @@ pub(crate) fn cmd_log(
Ok(())
}
pub fn get_node_template(settings: &UserSettings) -> String {
pub fn get_node_template(settings: &UserSettings) -> Result<String, config::ConfigError> {
node_template_for_key(
settings,
"templates.log_node",

View file

@ -217,7 +217,7 @@ pub fn show_op_diff(
writeln!(formatter)?;
writeln!(formatter, "Changed commits:")?;
if show_graph {
let graph_style = GraphStyle::from_settings(command.settings());
let graph_style = GraphStyle::from_settings(command.settings())?;
let mut graph = get_graphlog(graph_style, formatter.raw());
let graph_iter =

View file

@ -99,7 +99,7 @@ pub fn cmd_op_log(
.parse_template(
ui,
&language,
&get_node_template(command.settings()),
&get_node_template(command.settings())?,
OperationTemplateLanguage::wrap_operation,
)?
.labeled("node");
@ -117,7 +117,7 @@ pub fn cmd_op_log(
let limit = args.limit.or(args.deprecated_limit).unwrap_or(usize::MAX);
let iter = op_walk::walk_ancestors(slice::from_ref(&current_op)).take(limit);
if !args.no_graph {
let graph_style = GraphStyle::from_settings(command.settings());
let graph_style = GraphStyle::from_settings(command.settings())?;
let mut graph = get_graphlog(graph_style, formatter.raw());
for op in iter {
let op = op?;
@ -152,7 +152,7 @@ pub fn cmd_op_log(
Ok(())
}
fn get_node_template(settings: &UserSettings) -> String {
fn get_node_template(settings: &UserSettings) -> Result<String, config::ConfigError> {
node_template_for_key(
settings,
"templates.op_log_node",

View file

@ -13,6 +13,7 @@ max-inline-alternation = 3
allow-filesets = true
always-allow-large-revsets = false
diff-instructions = true
graph.style = "curved"
paginate = "auto"
pager = { command = ["less", "-FRX"], env = { LESSCHARSET = "utf-8" } }
log-word-wrap = false

View file

@ -17,6 +17,7 @@ use std::io;
use std::io::Write;
use itertools::Itertools;
use jj_lib::settings::ConfigResultExt as _;
use jj_lib::settings::UserSettings;
use renderdag::Ancestor;
use renderdag::GraphRowRenderer;
@ -112,11 +113,8 @@ pub enum GraphStyle {
}
impl GraphStyle {
pub fn from_settings(settings: &UserSettings) -> Self {
settings
.config()
.get("ui.graph.style")
.unwrap_or(GraphStyle::Curved)
pub fn from_settings(settings: &UserSettings) -> Result<Self, config::ConfigError> {
settings.config().get("ui.graph.style")
}
pub fn is_ascii(self) -> bool {
@ -132,12 +130,12 @@ pub fn node_template_for_key(
key: &str,
fallback: &str,
ascii_fallback: &str,
) -> String {
let symbol = settings.config().get_string(key);
if GraphStyle::from_settings(settings).is_ascii() {
symbol.unwrap_or_else(|_| ascii_fallback.to_owned())
) -> Result<String, config::ConfigError> {
let symbol = settings.config().get_string(key).optional()?;
if GraphStyle::from_settings(settings)?.is_ascii() {
Ok(symbol.unwrap_or_else(|| ascii_fallback.to_owned()))
} else {
symbol.unwrap_or_else(|_| fallback.to_owned())
Ok(symbol.unwrap_or_else(|| fallback.to_owned()))
}
}

View file

@ -1280,6 +1280,16 @@ fn test_graph_styles() {
initial
"###);
// Invalid style name
let stderr = test_env.jj_cmd_failure(
&repo_path,
&["log", "--config-toml=ui.graph.style='unknown'"],
);
insta::assert_snapshot!(stderr, @r###"
Config error: enum GraphStyle does not have variant constructor unknown
For help, see https://martinvonz.github.io/jj/latest/config/.
"###);
}
#[test]