diff --git a/lib/src/default_index/revset_graph_iterator.rs b/lib/src/default_index/revset_graph_iterator.rs index 75bac1d89e..fd5c2e5ad2 100644 --- a/lib/src/default_index/revset_graph_iterator.rs +++ b/lib/src/default_index/revset_graph_iterator.rs @@ -29,38 +29,8 @@ use crate::backend::CommitId; use crate::graph::GraphEdge; use crate::graph::GraphEdgeType; -/// Like `RevsetGraphEdge`, but stores `IndexPosition` instead. -/// -/// 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 { - GraphEdge { - target: index.entry_by_pos(self.target).commit_id(), - edge_type: self.edge_type, - } - } -} +// This can be cheaply allocated and hashed compared to `CommitId`-based type. +type IndexGraphEdge = GraphEdge; /// Given a `RevWalk` over some set of revisions, yields the same revisions with /// associated edge types. @@ -349,7 +319,7 @@ impl RevWalk for RevsetGraphWalk<'_> { } let edges = edges .iter() - .map(|edge| edge.to_revset_edge(index)) + .map(|edge| edge.map(|pos| index.entry_by_pos(pos).commit_id())) .collect(); Some((entry.commit_id(), edges)) } diff --git a/lib/src/graph.rs b/lib/src/graph.rs index cc9fa582ce..e68c952d40 100644 --- a/lib/src/graph.rs +++ b/lib/src/graph.rs @@ -19,7 +19,7 @@ use std::collections::HashSet; use std::collections::VecDeque; use std::hash::Hash; -#[derive(Debug, PartialEq, Eq, Clone, Hash)] +#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] pub struct GraphEdge { pub target: N, pub edge_type: GraphEdgeType, @@ -46,6 +46,13 @@ impl GraphEdge { edge_type: GraphEdgeType::Indirect, } } + + pub fn map(self, f: impl FnOnce(N) -> M) -> GraphEdge { + GraphEdge { + target: f(self.target), + edge_type: self.edge_type, + } + } } #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]