mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-01 09:08:51 +00:00
revset: use generic GraphEdge type in default graph iterator
This commit is contained in:
parent
6e72b1cfb0
commit
c6ee6130da
2 changed files with 11 additions and 34 deletions
|
@ -29,38 +29,8 @@ use crate::backend::CommitId;
|
||||||
use crate::graph::GraphEdge;
|
use crate::graph::GraphEdge;
|
||||||
use crate::graph::GraphEdgeType;
|
use crate::graph::GraphEdgeType;
|
||||||
|
|
||||||
/// Like `RevsetGraphEdge`, but stores `IndexPosition` instead.
|
// This can be cheaply allocated and hashed compared to `CommitId`-based type.
|
||||||
///
|
type IndexGraphEdge = GraphEdge<IndexPosition>;
|
||||||
/// This can be cheaply allocated and hashed compared to `CommitId`-based type.
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
|
||||||
struct IndexGraphEdge {
|
|
||||||
target: IndexPosition,
|
|
||||||
edge_type: GraphEdgeType,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IndexGraphEdge {
|
|
||||||
fn missing(target: IndexPosition) -> Self {
|
|
||||||
let edge_type = GraphEdgeType::Missing;
|
|
||||||
IndexGraphEdge { target, edge_type }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn direct(target: IndexPosition) -> Self {
|
|
||||||
let edge_type = GraphEdgeType::Direct;
|
|
||||||
IndexGraphEdge { target, edge_type }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn indirect(target: IndexPosition) -> Self {
|
|
||||||
let edge_type = GraphEdgeType::Indirect;
|
|
||||||
IndexGraphEdge { target, edge_type }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn to_revset_edge(self, index: &CompositeIndex) -> GraphEdge<CommitId> {
|
|
||||||
GraphEdge {
|
|
||||||
target: index.entry_by_pos(self.target).commit_id(),
|
|
||||||
edge_type: self.edge_type,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Given a `RevWalk` over some set of revisions, yields the same revisions with
|
/// Given a `RevWalk` over some set of revisions, yields the same revisions with
|
||||||
/// associated edge types.
|
/// associated edge types.
|
||||||
|
@ -349,7 +319,7 @@ impl RevWalk<CompositeIndex> for RevsetGraphWalk<'_> {
|
||||||
}
|
}
|
||||||
let edges = edges
|
let edges = edges
|
||||||
.iter()
|
.iter()
|
||||||
.map(|edge| edge.to_revset_edge(index))
|
.map(|edge| edge.map(|pos| index.entry_by_pos(pos).commit_id()))
|
||||||
.collect();
|
.collect();
|
||||||
Some((entry.commit_id(), edges))
|
Some((entry.commit_id(), edges))
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ use std::collections::HashSet;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
|
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
|
||||||
pub struct GraphEdge<N> {
|
pub struct GraphEdge<N> {
|
||||||
pub target: N,
|
pub target: N,
|
||||||
pub edge_type: GraphEdgeType,
|
pub edge_type: GraphEdgeType,
|
||||||
|
@ -46,6 +46,13 @@ impl<N> GraphEdge<N> {
|
||||||
edge_type: GraphEdgeType::Indirect,
|
edge_type: GraphEdgeType::Indirect,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn map<M>(self, f: impl FnOnce(N) -> M) -> GraphEdge<M> {
|
||||||
|
GraphEdge {
|
||||||
|
target: f(self.target),
|
||||||
|
edge_type: self.edge_type,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
|
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
|
||||||
|
|
Loading…
Reference in a new issue