forked from mirrors/jj
cli: parse graph node settings strictly
This commit is contained in:
parent
406ead241b
commit
36ab165b57
8 changed files with 30 additions and 19 deletions
|
@ -11,6 +11,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
### Breaking changes
|
### Breaking changes
|
||||||
|
|
||||||
|
* Invalid `ui.graph.style` configuration is now an error.
|
||||||
|
|
||||||
### Deprecations
|
### Deprecations
|
||||||
|
|
||||||
* `jj obslog` is now called `jj evolution-log`/`jj evolog`. `jj obslog` remains
|
* `jj obslog` is now called `jj evolution-log`/`jj evolog`. `jj obslog` remains
|
||||||
|
|
|
@ -105,7 +105,7 @@ pub(crate) fn cmd_evolog(
|
||||||
node_template = workspace_command
|
node_template = workspace_command
|
||||||
.parse_template(
|
.parse_template(
|
||||||
&language,
|
&language,
|
||||||
&get_node_template(command.settings()),
|
&get_node_template(command.settings())?,
|
||||||
CommitTemplateLanguage::wrap_commit_opt,
|
CommitTemplateLanguage::wrap_commit_opt,
|
||||||
)?
|
)?
|
||||||
.labeled("node");
|
.labeled("node");
|
||||||
|
@ -144,7 +144,7 @@ pub(crate) fn cmd_evolog(
|
||||||
commits.truncate(n);
|
commits.truncate(n);
|
||||||
}
|
}
|
||||||
if !args.no_graph {
|
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 mut graph = get_graphlog(graph_style, formatter.raw());
|
||||||
for commit in commits {
|
for commit in commits {
|
||||||
let mut edges = vec![];
|
let mut edges = vec![];
|
||||||
|
|
|
@ -145,7 +145,7 @@ pub(crate) fn cmd_log(
|
||||||
node_template = workspace_command
|
node_template = workspace_command
|
||||||
.parse_template(
|
.parse_template(
|
||||||
&language,
|
&language,
|
||||||
&get_node_template(command.settings()),
|
&get_node_template(command.settings())?,
|
||||||
CommitTemplateLanguage::wrap_commit_opt,
|
CommitTemplateLanguage::wrap_commit_opt,
|
||||||
)?
|
)?
|
||||||
.labeled("node");
|
.labeled("node");
|
||||||
|
@ -165,7 +165,7 @@ pub(crate) fn cmd_log(
|
||||||
let limit = args.limit.or(args.deprecated_limit).unwrap_or(usize::MAX);
|
let limit = args.limit.or(args.deprecated_limit).unwrap_or(usize::MAX);
|
||||||
|
|
||||||
if !args.no_graph {
|
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 mut graph = get_graphlog(graph_style, formatter.raw());
|
||||||
let forward_iter = TopoGroupedGraphIterator::new(revset.iter_graph());
|
let forward_iter = TopoGroupedGraphIterator::new(revset.iter_graph());
|
||||||
let iter: Box<dyn Iterator<Item = _>> = if args.reversed {
|
let iter: Box<dyn Iterator<Item = _>> = if args.reversed {
|
||||||
|
@ -297,7 +297,7 @@ pub(crate) fn cmd_log(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_node_template(settings: &UserSettings) -> String {
|
pub fn get_node_template(settings: &UserSettings) -> Result<String, config::ConfigError> {
|
||||||
node_template_for_key(
|
node_template_for_key(
|
||||||
settings,
|
settings,
|
||||||
"templates.log_node",
|
"templates.log_node",
|
||||||
|
|
|
@ -217,7 +217,7 @@ pub fn show_op_diff(
|
||||||
writeln!(formatter)?;
|
writeln!(formatter)?;
|
||||||
writeln!(formatter, "Changed commits:")?;
|
writeln!(formatter, "Changed commits:")?;
|
||||||
if show_graph {
|
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 mut graph = get_graphlog(graph_style, formatter.raw());
|
||||||
|
|
||||||
let graph_iter =
|
let graph_iter =
|
||||||
|
|
|
@ -99,7 +99,7 @@ pub fn cmd_op_log(
|
||||||
.parse_template(
|
.parse_template(
|
||||||
ui,
|
ui,
|
||||||
&language,
|
&language,
|
||||||
&get_node_template(command.settings()),
|
&get_node_template(command.settings())?,
|
||||||
OperationTemplateLanguage::wrap_operation,
|
OperationTemplateLanguage::wrap_operation,
|
||||||
)?
|
)?
|
||||||
.labeled("node");
|
.labeled("node");
|
||||||
|
@ -117,7 +117,7 @@ pub fn cmd_op_log(
|
||||||
let limit = args.limit.or(args.deprecated_limit).unwrap_or(usize::MAX);
|
let limit = args.limit.or(args.deprecated_limit).unwrap_or(usize::MAX);
|
||||||
let iter = op_walk::walk_ancestors(slice::from_ref(¤t_op)).take(limit);
|
let iter = op_walk::walk_ancestors(slice::from_ref(¤t_op)).take(limit);
|
||||||
if !args.no_graph {
|
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 mut graph = get_graphlog(graph_style, formatter.raw());
|
||||||
for op in iter {
|
for op in iter {
|
||||||
let op = op?;
|
let op = op?;
|
||||||
|
@ -152,7 +152,7 @@ pub fn cmd_op_log(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_node_template(settings: &UserSettings) -> String {
|
fn get_node_template(settings: &UserSettings) -> Result<String, config::ConfigError> {
|
||||||
node_template_for_key(
|
node_template_for_key(
|
||||||
settings,
|
settings,
|
||||||
"templates.op_log_node",
|
"templates.op_log_node",
|
||||||
|
|
|
@ -13,6 +13,7 @@ max-inline-alternation = 3
|
||||||
allow-filesets = true
|
allow-filesets = true
|
||||||
always-allow-large-revsets = false
|
always-allow-large-revsets = false
|
||||||
diff-instructions = true
|
diff-instructions = true
|
||||||
|
graph.style = "curved"
|
||||||
paginate = "auto"
|
paginate = "auto"
|
||||||
pager = { command = ["less", "-FRX"], env = { LESSCHARSET = "utf-8" } }
|
pager = { command = ["less", "-FRX"], env = { LESSCHARSET = "utf-8" } }
|
||||||
log-word-wrap = false
|
log-word-wrap = false
|
||||||
|
|
|
@ -17,6 +17,7 @@ use std::io;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
use jj_lib::settings::ConfigResultExt as _;
|
||||||
use jj_lib::settings::UserSettings;
|
use jj_lib::settings::UserSettings;
|
||||||
use renderdag::Ancestor;
|
use renderdag::Ancestor;
|
||||||
use renderdag::GraphRowRenderer;
|
use renderdag::GraphRowRenderer;
|
||||||
|
@ -112,11 +113,8 @@ pub enum GraphStyle {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GraphStyle {
|
impl GraphStyle {
|
||||||
pub fn from_settings(settings: &UserSettings) -> Self {
|
pub fn from_settings(settings: &UserSettings) -> Result<Self, config::ConfigError> {
|
||||||
settings
|
settings.config().get("ui.graph.style")
|
||||||
.config()
|
|
||||||
.get("ui.graph.style")
|
|
||||||
.unwrap_or(GraphStyle::Curved)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_ascii(self) -> bool {
|
pub fn is_ascii(self) -> bool {
|
||||||
|
@ -132,12 +130,12 @@ pub fn node_template_for_key(
|
||||||
key: &str,
|
key: &str,
|
||||||
fallback: &str,
|
fallback: &str,
|
||||||
ascii_fallback: &str,
|
ascii_fallback: &str,
|
||||||
) -> String {
|
) -> Result<String, config::ConfigError> {
|
||||||
let symbol = settings.config().get_string(key);
|
let symbol = settings.config().get_string(key).optional()?;
|
||||||
if GraphStyle::from_settings(settings).is_ascii() {
|
if GraphStyle::from_settings(settings)?.is_ascii() {
|
||||||
symbol.unwrap_or_else(|_| ascii_fallback.to_owned())
|
Ok(symbol.unwrap_or_else(|| ascii_fallback.to_owned()))
|
||||||
} else {
|
} else {
|
||||||
symbol.unwrap_or_else(|_| fallback.to_owned())
|
Ok(symbol.unwrap_or_else(|| fallback.to_owned()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1280,6 +1280,16 @@ fn test_graph_styles() {
|
||||||
○ initial
|
○ 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]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue