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

graphlog: load settings by caller

I'll make it error out if the style name is invalid.
This commit is contained in:
Yuya Nishihara 2024-09-03 16:59:13 +09:00
parent bd7cbaaffb
commit 406ead241b
5 changed files with 14 additions and 6 deletions

View file

@ -32,6 +32,7 @@ use crate::diff_util::DiffRenderer;
use crate::formatter::Formatter;
use crate::graphlog::get_graphlog;
use crate::graphlog::Edge;
use crate::graphlog::GraphStyle;
use crate::ui::Ui;
/// Show how a change has evolved over time
@ -143,7 +144,8 @@ pub(crate) fn cmd_evolog(
commits.truncate(n);
}
if !args.no_graph {
let mut graph = get_graphlog(command.settings(), formatter.raw());
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![];
for predecessor in commit.predecessors() {

View file

@ -33,6 +33,7 @@ use crate::diff_util::DiffFormatArgs;
use crate::graphlog::get_graphlog;
use crate::graphlog::node_template_for_key;
use crate::graphlog::Edge;
use crate::graphlog::GraphStyle;
use crate::ui::Ui;
/// Show revision history
@ -164,7 +165,8 @@ pub(crate) fn cmd_log(
let limit = args.limit.or(args.deprecated_limit).unwrap_or(usize::MAX);
if !args.no_graph {
let mut graph = get_graphlog(command.settings(), formatter.raw());
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 {
Box::new(ReverseGraphIterator::new(forward_iter))

View file

@ -47,6 +47,7 @@ use crate::diff_util::DiffRenderer;
use crate::formatter::Formatter;
use crate::graphlog::get_graphlog;
use crate::graphlog::Edge;
use crate::graphlog::GraphStyle;
use crate::templater::TemplateRenderer;
use crate::ui::Ui;
@ -216,7 +217,8 @@ pub fn show_op_diff(
writeln!(formatter)?;
writeln!(formatter, "Changed commits:")?;
if show_graph {
let mut graph = get_graphlog(command.settings(), formatter.raw());
let graph_style = GraphStyle::from_settings(command.settings());
let mut graph = get_graphlog(graph_style, formatter.raw());
let graph_iter =
TopoGroupedGraphIterator::new(ordered_change_ids.iter().map(|change_id| {

View file

@ -24,6 +24,7 @@ use crate::command_error::CommandError;
use crate::graphlog::get_graphlog;
use crate::graphlog::node_template_for_key;
use crate::graphlog::Edge;
use crate::graphlog::GraphStyle;
use crate::operation_templater::OperationTemplateLanguage;
use crate::ui::Ui;
@ -116,7 +117,8 @@ 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 mut graph = get_graphlog(command.settings(), formatter.raw());
let graph_style = GraphStyle::from_settings(command.settings());
let mut graph = get_graphlog(graph_style, formatter.raw());
for op in iter {
let op = op?;
let mut edges = vec![];

View file

@ -142,11 +142,11 @@ pub fn node_template_for_key(
}
pub fn get_graphlog<'a, K: Clone + Eq + Hash + 'a>(
settings: &UserSettings,
style: GraphStyle,
formatter: &'a mut dyn Write,
) -> Box<dyn GraphLog<K> + 'a> {
let builder = GraphRowRenderer::new().output().with_min_row_height(0);
match GraphStyle::from_settings(settings) {
match style {
GraphStyle::Ascii => SaplingGraphLog::create(builder.build_ascii(), formatter),
GraphStyle::AsciiLarge => SaplingGraphLog::create(builder.build_ascii_large(), formatter),
GraphStyle::Curved => SaplingGraphLog::create(builder.build_box_drawing(), formatter),