diff --git a/src/commands/mod.rs b/src/commands/mod.rs index b89ce5784..dd751ff89 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1484,6 +1484,7 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C if !args.no_graph { let mut graph = get_graphlog(command.settings(), formatter.raw()); + let default_node_symbol = graph.default_node_symbol().to_owned(); let iter: Box)>> = if args.reversed { Box::new(RevsetGraphIterator::new(revset.as_ref()).reversed()) @@ -1538,7 +1539,7 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C let node_symbol = if Some(&commit_id) == wc_commit_id { "@" } else { - "o" + &default_node_symbol }; graph.add_node( @@ -1624,6 +1625,7 @@ fn cmd_obslog(ui: &mut Ui, command: &CommandHelper, args: &ObslogArgs) -> Result ); if !args.no_graph { let mut graph = get_graphlog(command.settings(), formatter.raw()); + let default_node_symbol = graph.default_node_symbol().to_owned(); for commit in commits { let mut edges = vec![]; for predecessor in &commit.predecessors() { @@ -1650,7 +1652,7 @@ fn cmd_obslog(ui: &mut Ui, command: &CommandHelper, args: &ObslogArgs) -> Result let node_symbol = if Some(commit.id()) == wc_commit_id { "@" } else { - "o" + &default_node_symbol }; graph.add_node( commit.id(), diff --git a/src/commands/operation.rs b/src/commands/operation.rs index 992c8abd3..4755e4388 100644 --- a/src/commands/operation.rs +++ b/src/commands/operation.rs @@ -69,6 +69,7 @@ fn cmd_op_log( let mut formatter = ui.stdout_formatter(); let formatter = formatter.as_mut(); let mut graph = get_graphlog(command.settings(), formatter.raw()); + let default_node_symbol = graph.default_node_symbol().to_owned(); for op in topo_order_reverse( vec![head_op], Box::new(|op: &Operation| op.id().clone()), @@ -88,7 +89,11 @@ fn cmd_op_log( if !buffer.ends_with(b"\n") { buffer.push(b'\n'); } - let node_symbol = if is_head_op { "@" } else { "o" }; + let node_symbol = if is_head_op { + "@" + } else { + &default_node_symbol + }; graph.add_node( op.id(), &edges, diff --git a/src/graphlog.rs b/src/graphlog.rs index d72c11338..918c4e980 100644 --- a/src/graphlog.rs +++ b/src/graphlog.rs @@ -56,12 +56,15 @@ pub trait GraphLog { text: &str, ) -> io::Result<()>; + fn default_node_symbol(&self) -> &str; + fn width(&self, id: &K, edges: &[Edge]) -> usize; } pub struct SaplingGraphLog<'writer, R> { renderer: R, writer: &'writer mut dyn Write, + default_node_symbol: String, } impl From<&Edge> for Ancestor { @@ -99,6 +102,10 @@ where write!(self.writer, "{row}") } + fn default_node_symbol(&self) -> &str { + &self.default_node_symbol + } + fn width(&self, id: &K, edges: &[Edge]) -> usize { let parents = edges.iter().map_into().collect(); let w: u64 = self.renderer.width(Some(id), Some(&parents)); @@ -110,6 +117,7 @@ impl<'writer, R> SaplingGraphLog<'writer, R> { pub fn create( renderer: R, formatter: &'writer mut dyn Write, + default_node_symbol: &str, ) -> Box + 'writer> where K: Clone + Eq + Hash + 'writer, @@ -118,6 +126,7 @@ impl<'writer, R> SaplingGraphLog<'writer, R> { Box::new(SaplingGraphLog { renderer, writer: formatter, + default_node_symbol: default_node_symbol.to_owned(), }) } } @@ -129,12 +138,14 @@ pub fn get_graphlog<'a, K: Clone + Eq + Hash + 'a>( let builder = GraphRowRenderer::new().output().with_min_row_height(0); match settings.graph_style().as_str() { - "curved" => SaplingGraphLog::create(builder.build_box_drawing(), formatter), - "square" => { - SaplingGraphLog::create(builder.build_box_drawing().with_square_glyphs(), formatter) - } - "ascii" => SaplingGraphLog::create(builder.build_ascii(), formatter), - "ascii-large" => SaplingGraphLog::create(builder.build_ascii_large(), formatter), + "curved" => SaplingGraphLog::create(builder.build_box_drawing(), formatter, "o"), + "square" => SaplingGraphLog::create( + builder.build_box_drawing().with_square_glyphs(), + formatter, + "o", + ), + "ascii" => SaplingGraphLog::create(builder.build_ascii(), formatter, "o"), + "ascii-large" => SaplingGraphLog::create(builder.build_ascii_large(), formatter, "o"), _ => Box::new(AsciiGraphDrawer::new(formatter)), } } @@ -290,6 +301,10 @@ impl<'writer, K: Clone + Eq + Hash> GraphLog for AsciiGraphDrawer<'writer, K> Ok(()) } + fn default_node_symbol(&self) -> &str { + "o" + } + fn width(&self, id: &K, edges: &[Edge]) -> usize { let orig = self.edges.len() - usize::from(self.index_by_target(id).is_some()); let added = cmp::max(edges.len(), 1);