Skip to content

Commit

Permalink
revset_graph: rename to graph and make generic over graph node type
Browse files Browse the repository at this point in the history
  • Loading branch information
bnjmnt4n committed May 15, 2024
1 parent c9b44f3 commit 6ce6efa
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 305 deletions.
14 changes: 6 additions & 8 deletions cli/src/commands/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
// limitations under the License.

use jj_lib::backend::CommitId;
use jj_lib::graph::{GraphEdgeType, ReverseGraphIterator, TopoGroupedGraphIterator};
use jj_lib::repo::Repo;
use jj_lib::revset::{RevsetExpression, RevsetFilterPredicate, RevsetIteratorExt};
use jj_lib::revset_graph::{
ReverseRevsetGraphIterator, RevsetGraphEdgeType, TopoGroupedRevsetGraphIterator,
};
use tracing::instrument;

use crate::cli_util::{format_template, CommandHelper, LogContentFormat, RevisionArg};
Expand Down Expand Up @@ -141,9 +139,9 @@ pub(crate) fn cmd_log(

if !args.no_graph {
let mut graph = get_graphlog(command.settings(), formatter.raw());
let forward_iter = TopoGroupedRevsetGraphIterator::new(revset.iter_graph());
let forward_iter = TopoGroupedGraphIterator::new(revset.iter_graph());
let iter: Box<dyn Iterator<Item = _>> = if args.reversed {
Box::new(ReverseRevsetGraphIterator::new(forward_iter))
Box::new(ReverseGraphIterator::new(forward_iter))
} else {
Box::new(forward_iter)
};
Expand All @@ -157,13 +155,13 @@ pub(crate) fn cmd_log(
let mut elided_targets = vec![];
for edge in edges {
match edge.edge_type {
RevsetGraphEdgeType::Missing => {
GraphEdgeType::Missing => {
has_missing = true;
}
RevsetGraphEdgeType::Direct => {
GraphEdgeType::Direct => {
graphlog_edges.push(Edge::Direct((edge.target, false)));
}
RevsetGraphEdgeType::Indirect => {
GraphEdgeType::Indirect => {
if use_elided_nodes {
elided_targets.push(edge.target.clone());
graphlog_edges.push(Edge::Direct((edge.target, true)));
Expand Down
6 changes: 3 additions & 3 deletions lib/src/default_index/revset_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ use super::rev_walk::{EagerRevWalk, PeekableRevWalk, RevWalk, RevWalkBuilder};
use super::revset_graph_iterator::RevsetGraphWalk;
use crate::backend::{ChangeId, CommitId, MillisSinceEpoch};
use crate::default_index::{AsCompositeIndex, CompositeIndex, IndexEntry, IndexPosition};
use crate::graph::GraphEdge;
use crate::matchers::{Matcher, Visit};
use crate::repo_path::RepoPath;
use crate::revset::{
ResolvedExpression, ResolvedPredicateExpression, Revset, RevsetEvaluationError,
RevsetFilterExtensionWrapper, RevsetFilterPredicate, GENERATION_RANGE_FULL,
};
use crate::revset_graph::RevsetGraphEdge;
use crate::rewrite;
use crate::store::Store;

Expand Down Expand Up @@ -103,7 +103,7 @@ impl<I: AsCompositeIndex + Clone> RevsetImpl<I> {
pub fn iter_graph_impl(
&self,
skip_transitive_edges: bool,
) -> impl Iterator<Item = (CommitId, Vec<RevsetGraphEdge>)> {
) -> impl Iterator<Item = (CommitId, Vec<GraphEdge<CommitId>>)> {
let index = self.index.clone();
let walk = self.inner.positions();
let mut graph_walk = RevsetGraphWalk::new(walk, skip_transitive_edges);
Expand Down Expand Up @@ -147,7 +147,7 @@ impl<I: AsCompositeIndex + Clone> Revset for RevsetImpl<I> {
}))
}

fn iter_graph<'a>(&self) -> Box<dyn Iterator<Item = (CommitId, Vec<RevsetGraphEdge>)> + 'a>
fn iter_graph<'a>(&self) -> Box<dyn Iterator<Item = (CommitId, Vec<GraphEdge<CommitId>>)> + 'a>
where
Self: 'a,
{
Expand Down
26 changes: 13 additions & 13 deletions lib/src/default_index/revset_graph_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,35 @@ use super::entry::{IndexEntry, IndexPosition};
use super::rev_walk::RevWalk;
use super::revset_engine::BoxedRevWalk;
use crate::backend::CommitId;
use crate::revset_graph::{RevsetGraphEdge, RevsetGraphEdgeType};
use crate::graph::{GraphEdge, 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: RevsetGraphEdgeType,
edge_type: GraphEdgeType,
}

impl IndexGraphEdge {
fn missing(target: IndexPosition) -> Self {
let edge_type = RevsetGraphEdgeType::Missing;
let edge_type = GraphEdgeType::Missing;
IndexGraphEdge { target, edge_type }
}

fn direct(target: IndexPosition) -> Self {
let edge_type = RevsetGraphEdgeType::Direct;
let edge_type = GraphEdgeType::Direct;
IndexGraphEdge { target, edge_type }
}

fn indirect(target: IndexPosition) -> Self {
let edge_type = RevsetGraphEdgeType::Indirect;
let edge_type = GraphEdgeType::Indirect;
IndexGraphEdge { target, edge_type }
}

fn to_revset_edge(self, index: &CompositeIndex) -> RevsetGraphEdge {
RevsetGraphEdge {
fn to_revset_edge(self, index: &CompositeIndex) -> GraphEdge<CommitId> {
GraphEdge {
target: index.entry_by_pos(self.target).commit_id(),
edge_type: self.edge_type,
}
Expand Down Expand Up @@ -200,7 +200,7 @@ impl<'a> RevsetGraphWalk<'a> {
let parent_edges = self.edges_from_external_commit(index, parent);
if parent_edges
.iter()
.all(|edge| edge.edge_type == RevsetGraphEdgeType::Missing)
.all(|edge| edge.edge_type == GraphEdgeType::Missing)
{
edges.push(IndexGraphEdge::missing(parent_position));
} else {
Expand Down Expand Up @@ -240,7 +240,7 @@ impl<'a> RevsetGraphWalk<'a> {
} else if let Some(parent_edges) = self.edges.get(&parent_position) {
if parent_edges
.iter()
.all(|edge| edge.edge_type == RevsetGraphEdgeType::Missing)
.all(|edge| edge.edge_type == GraphEdgeType::Missing)
{
edges.push(IndexGraphEdge::missing(parent_position));
} else {
Expand Down Expand Up @@ -275,7 +275,7 @@ impl<'a> RevsetGraphWalk<'a> {
) -> Vec<IndexGraphEdge> {
if !edges
.iter()
.any(|edge| edge.edge_type == RevsetGraphEdgeType::Indirect)
.any(|edge| edge.edge_type == GraphEdgeType::Indirect)
{
return edges;
}
Expand All @@ -285,7 +285,7 @@ impl<'a> RevsetGraphWalk<'a> {
// To start with, add the edges one step after the input edges.
for edge in &edges {
initial_targets.insert(edge.target);
if edge.edge_type != RevsetGraphEdgeType::Missing {
if edge.edge_type != GraphEdgeType::Missing {
assert!(self.look_ahead.contains(&edge.target));
let entry = index.entry_by_pos(edge.target);
min_generation = min(min_generation, entry.generation_number());
Expand All @@ -295,7 +295,7 @@ impl<'a> RevsetGraphWalk<'a> {
// Find commits reachable transitively and add them to the `unwanted` set.
let mut unwanted = HashSet::new();
while let Some(edge) = work.pop() {
if edge.edge_type == RevsetGraphEdgeType::Missing || edge.target < self.min_position {
if edge.edge_type == GraphEdgeType::Missing || edge.target < self.min_position {
continue;
}
if !unwanted.insert(edge.target) {
Expand Down Expand Up @@ -333,7 +333,7 @@ impl<'a> RevsetGraphWalk<'a> {
}

impl RevWalk<CompositeIndex> for RevsetGraphWalk<'_> {
type Item = (CommitId, Vec<RevsetGraphEdge>);
type Item = (CommitId, Vec<GraphEdge<CommitId>>);

fn next(&mut self, index: &CompositeIndex) -> Option<Self::Item> {
let position = self.next_index_position(index)?;
Expand Down
Loading

0 comments on commit 6ce6efa

Please sign in to comment.