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 @@ -77,19 +77,20 @@ impl AncestorsIterator { /// is in the ancestors it emits. /// This is meant for iterators actually dedicated to that kind of /// purpose - pub fn contains(&mut self, target: Revision) -> bool { + pub fn contains(&mut self, target: Revision) -> Result { if self.seen.contains(&target) && target != NULL_REVISION { - return true; + return Ok(true); } - for rev in self { + for item in self { + let rev = item?; if rev == target { - return true; + return Ok(true); } if rev < target { - return false; + return Ok(false); } } - false + Ok(false) } } @@ -117,19 +118,19 @@ impl AncestorsIterator { /// concrete caller we target, so we shouldn't need a finer error treatment /// for the time being. impl Iterator for AncestorsIterator { - type Item = Revision; + type Item = Result; - fn next(&mut self) -> Option { + fn next(&mut self) -> Option { let current = match self.visit.peek() { None => { return None; } Some(c) => *c, }; - let (p1, p2) = self - .graph - .parents(current) - .unwrap_or((NULL_REVISION, NULL_REVISION)); + let (p1, p2) = match self.graph.parents(current) { + Ok(ps) => ps, + Err(e) => return Some(Err(e)), + }; if p1 < self.stoprev || self.seen.contains(&p1) { self.visit.pop(); } else { @@ -138,7 +139,7 @@ impl Iterator for AncestorsIte }; self.conditionally_push_rev(p2); - Some(current) + Some(Ok(current)) } } 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 @@ -139,7 +139,11 @@ pub extern "C" fn rustlazyancestors_next #[inline] fn raw_next(raw: *mut AncestorsIterator) -> c_long { let as_ref = unsafe { &mut *raw }; - as_ref.next().unwrap_or(NULL_REVISION) as c_long + let rev = match as_ref.next() { + Some(Ok(rev)) => rev, + Some(Err(_)) | None => NULL_REVISION, + }; + rev as c_long } #[no_mangle] @@ -157,10 +161,10 @@ fn raw_contains( target: c_long, ) -> c_int { let as_ref = unsafe { &mut *raw }; - if as_ref.contains(target as Revision) { - return 1; + match as_ref.contains(target as Revision) { + Ok(r) => r as c_int, + Err(_) => -1, } - 0 } #[cfg(test)]