Show More
@@ -57,9 +57,9 b' impl<G: Graph> AncestorsIterator<G> {' | |||||
57 | }; |
|
57 | }; | |
58 | this.seen.insert(NULL_REVISION); |
|
58 | this.seen.insert(NULL_REVISION); | |
59 | for rev in filtered_initrevs { |
|
59 | for rev in filtered_initrevs { | |
60 |
|
|
60 | for parent in this.graph.parents(rev)?.iter().cloned() { | |
61 |
this.conditionally_push_rev(parent |
|
61 | this.conditionally_push_rev(parent); | |
62 | this.conditionally_push_rev(parents.1); |
|
62 | } | |
63 | } |
|
63 | } | |
64 | Ok(this) |
|
64 | Ok(this) | |
65 | } |
|
65 | } | |
@@ -115,7 +115,7 b' impl<G: Graph> Iterator for AncestorsIte' | |||||
115 | } |
|
115 | } | |
116 | Some(c) => *c, |
|
116 | Some(c) => *c, | |
117 | }; |
|
117 | }; | |
118 |
let |
|
118 | let [p1, p2] = match self.graph.parents(current) { | |
119 | Ok(ps) => ps, |
|
119 | Ok(ps) => ps, | |
120 | Err(e) => return Some(Err(e)), |
|
120 | Err(e) => return Some(Err(e)), | |
121 | }; |
|
121 | }; | |
@@ -141,25 +141,22 b' mod tests {' | |||||
141 |
|
141 | |||
142 | /// This is the same as the dict from test-ancestors.py |
|
142 | /// This is the same as the dict from test-ancestors.py | |
143 | impl Graph for Stub { |
|
143 | impl Graph for Stub { | |
144 | fn parents( |
|
144 | fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> { | |
145 | &self, |
|
|||
146 | rev: Revision, |
|
|||
147 | ) -> Result<(Revision, Revision), GraphError> { |
|
|||
148 | match rev { |
|
145 | match rev { | |
149 |
0 => Ok( |
|
146 | 0 => Ok([-1, -1]), | |
150 |
1 => Ok( |
|
147 | 1 => Ok([0, -1]), | |
151 |
2 => Ok( |
|
148 | 2 => Ok([1, -1]), | |
152 |
3 => Ok( |
|
149 | 3 => Ok([1, -1]), | |
153 |
4 => Ok( |
|
150 | 4 => Ok([2, -1]), | |
154 |
5 => Ok( |
|
151 | 5 => Ok([4, -1]), | |
155 |
6 => Ok( |
|
152 | 6 => Ok([4, -1]), | |
156 |
7 => Ok( |
|
153 | 7 => Ok([4, -1]), | |
157 |
8 => Ok( |
|
154 | 8 => Ok([-1, -1]), | |
158 |
9 => Ok( |
|
155 | 9 => Ok([6, 7]), | |
159 |
10 => Ok( |
|
156 | 10 => Ok([5, -1]), | |
160 |
11 => Ok( |
|
157 | 11 => Ok([3, 7]), | |
161 |
12 => Ok( |
|
158 | 12 => Ok([9, -1]), | |
162 |
13 => Ok( |
|
159 | 13 => Ok([8, -1]), | |
163 | r => Err(GraphError::ParentOutOfRange(r)), |
|
160 | r => Err(GraphError::ParentOutOfRange(r)), | |
164 | } |
|
161 | } | |
165 | } |
|
162 | } | |
@@ -231,12 +228,9 b' mod tests {' | |||||
231 | struct Corrupted; |
|
228 | struct Corrupted; | |
232 |
|
229 | |||
233 | impl Graph for Corrupted { |
|
230 | impl Graph for Corrupted { | |
234 | fn parents( |
|
231 | fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> { | |
235 | &self, |
|
|||
236 | rev: Revision, |
|
|||
237 | ) -> Result<(Revision, Revision), GraphError> { |
|
|||
238 | match rev { |
|
232 | match rev { | |
239 |
1 => Ok( |
|
233 | 1 => Ok([0, -1]), | |
240 | r => Err(GraphError::ParentOutOfRange(r)), |
|
234 | r => Err(GraphError::ParentOutOfRange(r)), | |
241 | } |
|
235 | } | |
242 | } |
|
236 | } |
@@ -15,7 +15,7 b' pub const NULL_REVISION: Revision = -1;' | |||||
15 |
|
15 | |||
16 | /// The simplest expression of what we need of Mercurial DAGs. |
|
16 | /// The simplest expression of what we need of Mercurial DAGs. | |
17 | pub trait Graph { |
|
17 | pub trait Graph { | |
18 |
fn parents(&self, Revision) -> Result< |
|
18 | fn parents(&self, Revision) -> Result<[Revision; 2], GraphError>; | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | #[derive(Clone, Debug, PartialEq)] |
|
21 | #[derive(Clone, Debug, PartialEq)] |
@@ -44,12 +44,12 b' impl Index {' | |||||
44 |
|
44 | |||
45 | impl Graph for Index { |
|
45 | impl Graph for Index { | |
46 | /// wrap a call to the C extern parents function |
|
46 | /// wrap a call to the C extern parents function | |
47 |
fn parents(&self, rev: Revision) -> Result< |
|
47 | fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> { | |
48 | let mut res: [c_int; 2] = [0; 2]; |
|
48 | let mut res: [c_int; 2] = [0; 2]; | |
49 | let code = |
|
49 | let code = | |
50 | unsafe { HgRevlogIndex_GetParents(self.index, rev, &mut res as *mut [c_int; 2]) }; |
|
50 | unsafe { HgRevlogIndex_GetParents(self.index, rev, &mut res as *mut [c_int; 2]) }; | |
51 | match code { |
|
51 | match code { | |
52 |
0 => Ok( |
|
52 | 0 => Ok(res), | |
53 | _ => Err(GraphError::ParentOutOfRange(rev)), |
|
53 | _ => Err(GraphError::ParentOutOfRange(rev)), | |
54 | } |
|
54 | } | |
55 | } |
|
55 | } | |
@@ -176,10 +176,10 b' mod tests {' | |||||
176 | struct Stub; |
|
176 | struct Stub; | |
177 |
|
177 | |||
178 | impl Graph for Stub { |
|
178 | impl Graph for Stub { | |
179 |
fn parents(&self, r: Revision) -> Result< |
|
179 | fn parents(&self, r: Revision) -> Result<[Revision; 2], GraphError> { | |
180 | match r { |
|
180 | match r { | |
181 | 25 => Err(GraphError::ParentOutOfRange(25)), |
|
181 | 25 => Err(GraphError::ParentOutOfRange(25)), | |
182 |
_ => Ok( |
|
182 | _ => Ok([1, 2]), | |
183 | } |
|
183 | } | |
184 | } |
|
184 | } | |
185 | } |
|
185 | } |
General Comments 0
You need to be logged in to leave comments.
Login now