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)), } } 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-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]), } } }