Patchwork D5415: rust: changed Graph.parents to return [Revision; 2]

login
register
mail settings
Submitter phabricator
Date Dec. 12, 2018, 4:26 p.m.
Message ID <f6805c75895c0eeb2ecdf052ffc048d7@localhost.localdomain>
Download mbox | patch
Permalink /patch/37126/
State Not Applicable
Headers show

Comments

phabricator - Dec. 12, 2018, 4:26 p.m.
gracinet updated this revision to Diff 12831.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5415?vs=12828&id=12831

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

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

CHANGE DETAILS




To: gracinet, #hg-reviewers
Cc: durin42, kevincox, mercurial-devel

Patch

diff --git a/rust/hg-direct-ffi/src/ancestors.rs b/rust/hg-direct-ffi/src/ancestors.rs
--- a/rust/hg-direct-ffi/src/ancestors.rs
+++ b/rust/hg-direct-ffi/src/ancestors.rs
@@ -44,12 +44,12 @@ 
 
 impl Graph for Index {
     /// wrap a call to the C extern parents function
-    fn parents(&self, rev: Revision) -> Result<(Revision, Revision), GraphError> {
+    fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> {
         let mut res: [c_int; 2] = [0; 2];
         let code =
             unsafe { HgRevlogIndex_GetParents(self.index, rev, &mut res as *mut [c_int; 2]) };
         match code {
-            0 => Ok((res[0], res[1])),
+            0 => Ok(res),
             _ => Err(GraphError::ParentOutOfRange(rev)),
         }
     }
@@ -176,10 +176,10 @@ 
     struct Stub;
 
     impl Graph for Stub {
-        fn parents(&self, r: Revision) -> Result<(Revision, Revision), GraphError> {
+        fn parents(&self, r: Revision) -> Result<[Revision; 2], GraphError> {
             match r {
                 25 => Err(GraphError::ParentOutOfRange(25)),
-                _ => Ok((1, 2)),
+                _ => Ok([1, 2]),
             }
         }
     }
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
@@ -15,7 +15,7 @@ 
 
 /// The simplest expression of what we need of Mercurial DAGs.
 pub trait Graph {
-    fn parents(&self, Revision) -> Result<(Revision, Revision), GraphError>;
+    fn parents(&self, Revision) -> Result<[Revision; 2], GraphError>;
 }
 
 #[derive(Clone, Debug, PartialEq)]
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
@@ -57,9 +57,9 @@ 
         };
         this.seen.insert(NULL_REVISION);
         for rev in filtered_initrevs {
-            let parents = this.graph.parents(rev)?;
-            this.conditionally_push_rev(parents.0);
-            this.conditionally_push_rev(parents.1);
+            for parent in this.graph.parents(rev)?.iter().cloned() {
+                this.conditionally_push_rev(parent);
+            }
         }
         Ok(this)
     }
@@ -115,7 +115,7 @@ 
             }
             Some(c) => *c,
         };
-        let (p1, p2) = match self.graph.parents(current) {
+        let [p1, p2] = match self.graph.parents(current) {
             Ok(ps) => ps,
             Err(e) => return Some(Err(e)),
         };
@@ -141,25 +141,22 @@ 
 
     /// This is the same as the dict from test-ancestors.py
     impl Graph for Stub {
-        fn parents(
-            &self,
-            rev: Revision,
-        ) -> Result<(Revision, Revision), GraphError> {
+        fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> {
             match rev {
-                0 => Ok((-1, -1)),
-                1 => Ok((0, -1)),
-                2 => Ok((1, -1)),
-                3 => Ok((1, -1)),
-                4 => Ok((2, -1)),
-                5 => Ok((4, -1)),
-                6 => Ok((4, -1)),
-                7 => Ok((4, -1)),
-                8 => Ok((-1, -1)),
-                9 => Ok((6, 7)),
-                10 => Ok((5, -1)),
-                11 => Ok((3, 7)),
-                12 => Ok((9, -1)),
-                13 => Ok((8, -1)),
+                0 => Ok([-1, -1]),
+                1 => Ok([0, -1]),
+                2 => Ok([1, -1]),
+                3 => Ok([1, -1]),
+                4 => Ok([2, -1]),
+                5 => Ok([4, -1]),
+                6 => Ok([4, -1]),
+                7 => Ok([4, -1]),
+                8 => Ok([-1, -1]),
+                9 => Ok([6, 7]),
+                10 => Ok([5, -1]),
+                11 => Ok([3, 7]),
+                12 => Ok([9, -1]),
+                13 => Ok([8, -1]),
                 r => Err(GraphError::ParentOutOfRange(r)),
             }
         }
@@ -231,12 +228,9 @@ 
     struct Corrupted;
 
     impl Graph for Corrupted {
-        fn parents(
-            &self,
-            rev: Revision,
-        ) -> Result<(Revision, Revision), GraphError> {
+        fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> {
             match rev {
-                1 => Ok((0, -1)),
+                1 => Ok([0, -1]),
                 r => Err(GraphError::ParentOutOfRange(r)),
             }
         }