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

graphlog: refactor graphlog::Edge enum and its usage

`graphlog::Edge` is used somewhat inconsistently. I've replaced `Edge::Present`
with two distinct `Edge::Direct` and `Edge::Indirect` which simplifies the
construction of the enum.
This commit is contained in:
Aleksey Kuznetsov 2024-02-17 13:37:35 +05:00
parent aaa5d6bc4f
commit 89cf6a00a1
4 changed files with 10 additions and 44 deletions

View file

@ -140,23 +140,14 @@ pub(crate) fn cmd_log(
has_missing = true;
}
RevsetGraphEdgeType::Direct => {
graphlog_edges.push(Edge::Present {
direct: true,
target: (edge.target, false),
});
graphlog_edges.push(Edge::Direct((edge.target, false)));
}
RevsetGraphEdgeType::Indirect => {
if use_elided_nodes {
elided_targets.push(edge.target.clone());
graphlog_edges.push(Edge::Present {
direct: true,
target: (edge.target, true),
});
graphlog_edges.push(Edge::Direct((edge.target, true)));
} else {
graphlog_edges.push(Edge::Present {
direct: false,
target: (edge.target, false),
});
graphlog_edges.push(Edge::Indirect((edge.target, false)));
}
}
}
@ -201,10 +192,7 @@ pub(crate) fn cmd_log(
for elided_target in elided_targets {
let elided_key = (elided_target, true);
let real_key = (elided_key.0.clone(), false);
let edges = [Edge::Present {
direct: true,
target: real_key,
}];
let edges = [Edge::Direct(real_key)];
let mut buffer = vec![];
with_content_format.write_graph_text(
ui.new_formatter(&mut buffer).as_mut(),

View file

@ -95,7 +95,7 @@ pub(crate) fn cmd_obslog(
for commit in commits {
let mut edges = vec![];
for predecessor in &commit.predecessors() {
edges.push(Edge::direct(predecessor.id().clone()));
edges.push(Edge::Direct(predecessor.id().clone()));
}
let mut buffer = vec![];
with_content_format.write_graph_text(

View file

@ -184,7 +184,7 @@ fn cmd_op_log(
let op = op?;
let mut edges = vec![];
for id in op.parent_ids() {
edges.push(Edge::direct(id.clone()));
edges.push(Edge::Direct(id.clone()));
}
let is_current_op = Some(op.id()) == current_op_id;
let mut buffer = vec![];

View file

@ -23,30 +23,11 @@ use renderdag::{Ancestor, GraphRowRenderer, Renderer};
#[derive(Debug, Clone, PartialEq, Eq)]
// An edge to another node in the graph
pub enum Edge<T> {
Present { target: T, direct: bool },
Direct(T),
Indirect(T),
Missing,
}
impl<T> Edge<T> {
pub fn missing() -> Self {
Edge::Missing
}
pub fn direct(id: T) -> Self {
Edge::Present {
target: id,
direct: true,
}
}
pub fn indirect(id: T) -> Self {
Edge::Present {
target: id,
direct: false,
}
}
}
pub trait GraphLog<K: Clone + Eq + Hash> {
fn add_node(
&mut self,
@ -73,11 +54,8 @@ pub struct SaplingGraphLog<'writer, R> {
impl<K: Clone> From<&Edge<K>> for Ancestor<K> {
fn from(e: &Edge<K>) -> Self {
match e {
Edge::Present {
target,
direct: true,
} => Ancestor::Parent(target.clone()),
Edge::Present { target, .. } => Ancestor::Ancestor(target.clone()),
Edge::Direct(target) => Ancestor::Parent(target.clone()),
Edge::Indirect(target) => Ancestor::Ancestor(target.clone()),
Edge::Missing => Ancestor::Anonymous,
}
}