Patchwork D11948: hg-core: dedup LazyAncestors Iterator impl

login
register
mail settings
Submitter phabricator
Date Dec. 21, 2021, 3:07 p.m.
Message ID <differential-rev-PHID-DREV-wmpqaoygjt36y3p2nnk3-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50274/
State New
Headers show

Comments

phabricator - Dec. 21, 2021, 3:07 p.m.
pacien created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  … Which has been moved to the vcsgraph crate.
  
  AncestorsIterator cannot yet be removed because it is still being used in
  hg-core.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11948

AFFECTED FILES
  rust/hg-core/src/ancestors.rs
  rust/hg-core/src/lib.rs

CHANGE DETAILS




To: pacien, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/rust/hg-core/src/lib.rs b/rust/hg-core/src/lib.rs
--- a/rust/hg-core/src/lib.rs
+++ b/rust/hg-core/src/lib.rs
@@ -7,7 +7,7 @@ 
 mod ancestors;
 pub mod dagops;
 pub mod errors;
-pub use ancestors::{AncestorsIterator, LazyAncestors, MissingAncestors};
+pub use ancestors::{AncestorsIterator, MissingAncestors};
 pub mod dirstate;
 pub mod dirstate_tree;
 pub mod discovery;
diff --git a/rust/hg-core/src/ancestors.rs b/rust/hg-core/src/ancestors.rs
--- a/rust/hg-core/src/ancestors.rs
+++ b/rust/hg-core/src/ancestors.rs
@@ -26,15 +26,6 @@ 
     stoprev: Revision,
 }
 
-/// Lazy ancestors set, backed by AncestorsIterator
-pub struct LazyAncestors<G: Graph + Clone> {
-    graph: G,
-    containsiter: AncestorsIterator<G>,
-    initrevs: Vec<Revision>,
-    stoprev: Revision,
-    inclusive: bool,
-}
-
 pub struct MissingAncestors<G: Graph> {
     graph: G,
     bases: HashSet<Revision>,
@@ -165,49 +156,6 @@ 
     }
 }
 
-impl<G: Graph + Clone> LazyAncestors<G> {
-    pub fn new(
-        graph: G,
-        initrevs: impl IntoIterator<Item = Revision>,
-        stoprev: Revision,
-        inclusive: bool,
-    ) -> Result<Self, GraphError> {
-        let v: Vec<Revision> = initrevs.into_iter().collect();
-        Ok(LazyAncestors {
-            graph: graph.clone(),
-            containsiter: AncestorsIterator::new(
-                graph,
-                v.iter().cloned(),
-                stoprev,
-                inclusive,
-            )?,
-            initrevs: v,
-            stoprev,
-            inclusive,
-        })
-    }
-
-    pub fn contains(&mut self, rev: Revision) -> Result<bool, GraphError> {
-        self.containsiter.contains(rev)
-    }
-
-    pub fn is_empty(&self) -> bool {
-        self.containsiter.is_empty()
-    }
-
-    pub fn iter(&self) -> AncestorsIterator<G> {
-        // the arguments being the same as for self.containsiter, we know
-        // for sure that AncestorsIterator constructor can't fail
-        AncestorsIterator::new(
-            self.graph.clone(),
-            self.initrevs.iter().cloned(),
-            self.stoprev,
-            self.inclusive,
-        )
-        .unwrap()
-    }
-}
-
 impl<G: Graph> MissingAncestors<G> {
     pub fn new(graph: G, bases: impl IntoIterator<Item = Revision>) -> Self {
         let mut created = MissingAncestors {
@@ -550,39 +498,6 @@ 
     }
 
     #[test]
-    fn test_lazy_iter_contains() {
-        let mut lazy =
-            LazyAncestors::new(SampleGraph, vec![11, 13], 0, false).unwrap();
-
-        let revs: Vec<Revision> = lazy.iter().map(|r| r.unwrap()).collect();
-        // compare with iterator tests on the same initial revisions
-        assert_eq!(revs, vec![8, 7, 4, 3, 2, 1, 0]);
-
-        // contains() results are correct, unaffected by the fact that
-        // we consumed entirely an iterator out of lazy
-        assert_eq!(lazy.contains(2), Ok(true));
-        assert_eq!(lazy.contains(9), Ok(false));
-    }
-
-    #[test]
-    fn test_lazy_contains_iter() {
-        let mut lazy =
-            LazyAncestors::new(SampleGraph, vec![11, 13], 0, false).unwrap(); // reminder: [8, 7, 4, 3, 2, 1, 0]
-
-        assert_eq!(lazy.contains(2), Ok(true));
-        assert_eq!(lazy.contains(6), Ok(false));
-
-        // after consumption of 2 by the inner iterator, results stay
-        // consistent
-        assert_eq!(lazy.contains(2), Ok(true));
-        assert_eq!(lazy.contains(5), Ok(false));
-
-        // iter() still gives us a fresh iterator
-        let revs: Vec<Revision> = lazy.iter().map(|r| r.unwrap()).collect();
-        assert_eq!(revs, vec![8, 7, 4, 3, 2, 1, 0]);
-    }
-
-    #[test]
     /// Test constructor, add/get bases and heads
     fn test_missing_bases() -> Result<(), GraphError> {
         let mut missing_ancestors =