##// END OF EJS Templates
rust: propagate error of index_get_parents() properly...
Yuya Nishihara -
r41244:443eb4bc default
parent child Browse files
Show More
@@ -77,19 +77,20 b' impl<G: Graph> AncestorsIterator<G> {'
77 /// is in the ancestors it emits.
77 /// is in the ancestors it emits.
78 /// This is meant for iterators actually dedicated to that kind of
78 /// This is meant for iterators actually dedicated to that kind of
79 /// purpose
79 /// purpose
80 pub fn contains(&mut self, target: Revision) -> bool {
80 pub fn contains(&mut self, target: Revision) -> Result<bool, GraphError> {
81 if self.seen.contains(&target) && target != NULL_REVISION {
81 if self.seen.contains(&target) && target != NULL_REVISION {
82 return true;
82 return Ok(true);
83 }
83 }
84 for rev in self {
84 for item in self {
85 let rev = item?;
85 if rev == target {
86 if rev == target {
86 return true;
87 return Ok(true);
87 }
88 }
88 if rev < target {
89 if rev < target {
89 return false;
90 return Ok(false);
90 }
91 }
91 }
92 }
92 false
93 Ok(false)
93 }
94 }
94 }
95 }
95
96
@@ -117,19 +118,19 b' impl<G: Graph> AncestorsIterator<G> {'
117 /// concrete caller we target, so we shouldn't need a finer error treatment
118 /// concrete caller we target, so we shouldn't need a finer error treatment
118 /// for the time being.
119 /// for the time being.
119 impl<G: Graph> Iterator for AncestorsIterator<G> {
120 impl<G: Graph> Iterator for AncestorsIterator<G> {
120 type Item = Revision;
121 type Item = Result<Revision, GraphError>;
121
122
122 fn next(&mut self) -> Option<Revision> {
123 fn next(&mut self) -> Option<Self::Item> {
123 let current = match self.visit.peek() {
124 let current = match self.visit.peek() {
124 None => {
125 None => {
125 return None;
126 return None;
126 }
127 }
127 Some(c) => *c,
128 Some(c) => *c,
128 };
129 };
129 let (p1, p2) = self
130 let (p1, p2) = match self.graph.parents(current) {
130 .graph
131 Ok(ps) => ps,
131 .parents(current)
132 Err(e) => return Some(Err(e)),
132 .unwrap_or((NULL_REVISION, NULL_REVISION));
133 };
133 if p1 < self.stoprev || self.seen.contains(&p1) {
134 if p1 < self.stoprev || self.seen.contains(&p1) {
134 self.visit.pop();
135 self.visit.pop();
135 } else {
136 } else {
@@ -138,7 +139,7 b' impl<G: Graph> Iterator for AncestorsIte'
138 };
139 };
139
140
140 self.conditionally_push_rev(p2);
141 self.conditionally_push_rev(p2);
141 Some(current)
142 Some(Ok(current))
142 }
143 }
143 }
144 }
144
145
@@ -139,7 +139,11 b' pub extern "C" fn rustlazyancestors_next'
139 #[inline]
139 #[inline]
140 fn raw_next<G: Graph>(raw: *mut AncestorsIterator<G>) -> c_long {
140 fn raw_next<G: Graph>(raw: *mut AncestorsIterator<G>) -> c_long {
141 let as_ref = unsafe { &mut *raw };
141 let as_ref = unsafe { &mut *raw };
142 as_ref.next().unwrap_or(NULL_REVISION) as c_long
142 let rev = match as_ref.next() {
143 Some(Ok(rev)) => rev,
144 Some(Err(_)) | None => NULL_REVISION,
145 };
146 rev as c_long
143 }
147 }
144
148
145 #[no_mangle]
149 #[no_mangle]
@@ -157,10 +161,10 b' fn raw_contains<G: Graph>('
157 target: c_long,
161 target: c_long,
158 ) -> c_int {
162 ) -> c_int {
159 let as_ref = unsafe { &mut *raw };
163 let as_ref = unsafe { &mut *raw };
160 if as_ref.contains(target as Revision) {
164 match as_ref.contains(target as Revision) {
161 return 1;
165 Ok(r) => r as c_int,
166 Err(_) => -1,
162 }
167 }
163 0
164 }
168 }
165
169
166 #[cfg(test)]
170 #[cfg(test)]
General Comments 0
You need to be logged in to leave comments. Login now