mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-24 12:48:55 +00:00
graph: inline ReverseGraphIterator to callers
This commit is contained in:
parent
ec853027be
commit
6f00c565b2
3 changed files with 6 additions and 35 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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> = (N, Vec<GraphEdge<N>>);
|
||||
|
||||
|
@ -74,32 +72,8 @@ fn reachable_targets<N>(edges: &[GraphEdge<N>]) -> impl DoubleEndedIterator<Item
|
|||
.map(|edge| &edge.target)
|
||||
}
|
||||
|
||||
pub struct ReverseGraphIterator<N> {
|
||||
items: std::vec::IntoIter<GraphNode<N>>,
|
||||
}
|
||||
|
||||
impl<N> ReverseGraphIterator<N>
|
||||
where
|
||||
N: Hash + Eq + Clone,
|
||||
{
|
||||
pub fn new(
|
||||
input: impl Iterator<Item = Result<GraphNode<N>, RevsetEvaluationError>>,
|
||||
) -> Result<Self, RevsetEvaluationError> {
|
||||
let items = reverse_graph(input)?.into_iter();
|
||||
Ok(Self { items })
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> Iterator for ReverseGraphIterator<N> {
|
||||
type Item = Result<GraphNode<N>, RevsetEvaluationError>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.items.next().map(Ok)
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates new graph in which nodes and edges are reversed.
|
||||
fn reverse_graph<N: Clone + Eq + Hash, E>(
|
||||
pub fn reverse_graph<N: Clone + Eq + Hash, E>(
|
||||
input: impl Iterator<Item = Result<GraphNode<N>, E>>,
|
||||
) -> Result<Vec<GraphNode<N>>, E> {
|
||||
let mut entries = vec![];
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue