From 6f00c565b298c78b758a5a076622e98dbee2e054 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sun, 22 Dec 2024 10:28:14 +0900 Subject: [PATCH] graph: inline ReverseGraphIterator to callers --- cli/src/commands/log.rs | 4 ++-- lib/src/graph.rs | 28 +--------------------------- lib/tests/test_revset.rs | 9 +++------ 3 files changed, 6 insertions(+), 35 deletions(-) diff --git a/cli/src/commands/log.rs b/cli/src/commands/log.rs index 3ef67cf565..8492e4fa9a 100644 --- a/cli/src/commands/log.rs +++ b/cli/src/commands/log.rs @@ -17,8 +17,8 @@ use clap_complete::ArgValueCompleter; use jj_lib::backend::CommitId; use jj_lib::config::ConfigGetError; use jj_lib::config::ConfigGetResultExt as _; +use jj_lib::graph::reverse_graph; use jj_lib::graph::GraphEdgeType; -use jj_lib::graph::ReverseGraphIterator; use jj_lib::graph::TopoGroupedGraphIterator; use jj_lib::repo::Repo; use jj_lib::revset::RevsetEvaluationError; @@ -208,7 +208,7 @@ pub(crate) fn cmd_log( } } if args.reversed { - Box::new(ReverseGraphIterator::new(forward_iter)?) + Box::new(reverse_graph(forward_iter)?.into_iter().map(Ok)) } else { Box::new(forward_iter) } diff --git a/lib/src/graph.rs b/lib/src/graph.rs index 4e2282a8c7..26d2041fea 100644 --- a/lib/src/graph.rs +++ b/lib/src/graph.rs @@ -19,8 +19,6 @@ use std::collections::HashSet; use std::collections::VecDeque; use std::hash::Hash; -use crate::revset::RevsetEvaluationError; - /// Node and edges pair of type `N`. pub type GraphNode = (N, Vec>); @@ -74,32 +72,8 @@ fn reachable_targets(edges: &[GraphEdge]) -> impl DoubleEndedIterator { - items: std::vec::IntoIter>, -} - -impl ReverseGraphIterator -where - N: Hash + Eq + Clone, -{ - pub fn new( - input: impl Iterator, RevsetEvaluationError>>, - ) -> Result { - let items = reverse_graph(input)?.into_iter(); - Ok(Self { items }) - } -} - -impl Iterator for ReverseGraphIterator { - type Item = Result, RevsetEvaluationError>; - - fn next(&mut self) -> Option { - self.items.next().map(Ok) - } -} - /// Creates new graph in which nodes and edges are reversed. -fn reverse_graph( +pub fn reverse_graph( input: impl Iterator, E>>, ) -> Result>, E> { let mut entries = vec![]; diff --git a/lib/tests/test_revset.rs b/lib/tests/test_revset.rs index 51ee358de4..3063abea3c 100644 --- a/lib/tests/test_revset.rs +++ b/lib/tests/test_revset.rs @@ -26,8 +26,8 @@ use jj_lib::commit::Commit; use jj_lib::fileset::FilesetExpression; use jj_lib::git; use jj_lib::git_backend::GitBackend; +use jj_lib::graph::reverse_graph; use jj_lib::graph::GraphEdge; -use jj_lib::graph::ReverseGraphIterator; use jj_lib::id_prefix::IdPrefixContext; use jj_lib::object_id::ObjectId; use jj_lib::op_store::RefTarget; @@ -3942,7 +3942,7 @@ fn test_evaluate_expression_conflict() { } #[test] -fn test_reverse_graph_iterator() { +fn test_reverse_graph() { let settings = testutils::user_settings(); let test_repo = TestRepo::init(); let repo = &test_repo.repo; @@ -3977,10 +3977,7 @@ fn test_reverse_graph_iterator() { repo.as_ref(), &[&commit_a, &commit_c, &commit_d, &commit_e, &commit_f], ); - let commits: Vec<_> = ReverseGraphIterator::new(revset.iter_graph()) - .unwrap() - .try_collect() - .unwrap(); + let commits = reverse_graph(revset.iter_graph()).unwrap(); assert_eq!(commits.len(), 5); assert_eq!(commits[0].0, *commit_a.id()); assert_eq!(commits[1].0, *commit_c.id());