Show More
@@ -209,15 +209,11 b' impl<G: Graph + Clone> LazyAncestors<G> ' | |||||
209 |
|
209 | |||
210 | impl<G: Graph> MissingAncestors<G> { |
|
210 | impl<G: Graph> MissingAncestors<G> { | |
211 | pub fn new(graph: G, bases: impl IntoIterator<Item = Revision>) -> Self { |
|
211 | pub fn new(graph: G, bases: impl IntoIterator<Item = Revision>) -> Self { | |
212 |
|
|
212 | MissingAncestors { graph: graph, bases: bases.into_iter().collect() } | |
213 | if bases.is_empty() { |
|
|||
214 | bases.insert(NULL_REVISION); |
|
|||
215 | } |
|
|||
216 | MissingAncestors { graph, bases } |
|
|||
217 | } |
|
213 | } | |
218 |
|
214 | |||
219 | pub fn has_bases(&self) -> bool { |
|
215 | pub fn has_bases(&self) -> bool { | |
220 | self.bases.iter().any(|&b| b != NULL_REVISION) |
|
216 | !self.bases.is_empty() | |
221 | } |
|
217 | } | |
222 |
|
218 | |||
223 | /// Return a reference to current bases. |
|
219 | /// Return a reference to current bases. | |
@@ -245,7 +241,8 b' impl<G: Graph> MissingAncestors<G> {' | |||||
245 | &mut self, |
|
241 | &mut self, | |
246 | new_bases: impl IntoIterator<Item = Revision>, |
|
242 | new_bases: impl IntoIterator<Item = Revision>, | |
247 | ) { |
|
243 | ) { | |
248 |
self.bases |
|
244 | self.bases | |
|
245 | .extend(new_bases.into_iter().filter(|&rev| rev != NULL_REVISION)); | |||
249 | } |
|
246 | } | |
250 |
|
247 | |||
251 | /// Remove all ancestors of self.bases from the revs set (in place) |
|
248 | /// Remove all ancestors of self.bases from the revs set (in place) | |
@@ -254,7 +251,10 b' impl<G: Graph> MissingAncestors<G> {' | |||||
254 | revs: &mut HashSet<Revision>, |
|
251 | revs: &mut HashSet<Revision>, | |
255 | ) -> Result<(), GraphError> { |
|
252 | ) -> Result<(), GraphError> { | |
256 | revs.retain(|r| !self.bases.contains(r)); |
|
253 | revs.retain(|r| !self.bases.contains(r)); | |
257 | // the null revision is always an ancestor |
|
254 | // the null revision is always an ancestor. Logically speaking | |
|
255 | // it's debatable in case bases is empty, but the Python | |||
|
256 | // implementation always adds NULL_REVISION to bases, making it | |||
|
257 | // unconditionnally true. | |||
258 | revs.remove(&NULL_REVISION); |
|
258 | revs.remove(&NULL_REVISION); | |
259 | if revs.is_empty() { |
|
259 | if revs.is_empty() { | |
260 | return Ok(()); |
|
260 | return Ok(()); | |
@@ -265,8 +265,7 b' impl<G: Graph> MissingAncestors<G> {' | |||||
265 | // we shouldn't need to iterate each time on bases |
|
265 | // we shouldn't need to iterate each time on bases | |
266 | let start = match self.bases.iter().cloned().max() { |
|
266 | let start = match self.bases.iter().cloned().max() { | |
267 | Some(m) => m, |
|
267 | Some(m) => m, | |
268 | None => { |
|
268 | None => { // self.bases is empty | |
269 | // bases is empty (shouldn't happen, but let's be safe) |
|
|||
270 | return Ok(()); |
|
269 | return Ok(()); | |
271 | } |
|
270 | } | |
272 | }; |
|
271 | }; |
General Comments 0
You need to be logged in to leave comments.
Login now