comparison rust/hg-core/src/ancestors.rs @ 41133:a1b3800c8a19

rust-ancestors: remove unreachable conditions from missing_ancestors()
author Yuya Nishihara <yuya@tcha.org>
date Wed, 19 Dec 2018 21:52:40 +0900
parents 55dc1da8df2f
children 17a195676472
comparison
equal deleted inserted replaced
41132:55dc1da8df2f 41133:a1b3800c8a19
336 bases_visit.insert(p); 336 bases_visit.insert(p);
337 both_visit.insert(p); 337 both_visit.insert(p);
338 } 338 }
339 continue; 339 continue;
340 } 340 }
341 // in Rust, one can't just use mutable variables assignation
342 // to be more straightforward. Instead of Python's
343 // thisvisit and othervisit, we'll differentiate with a boolean
344 let this_visit_is_revs;
345 if revs_visit.remove(&curr) { 341 if revs_visit.remove(&curr) {
346 missing.push(curr); 342 missing.push(curr);
347 this_visit_is_revs = true;
348 for p in self.graph.parents(curr)?.iter().cloned() { 343 for p in self.graph.parents(curr)?.iter().cloned() {
349 if p == NULL_REVISION { 344 if p == NULL_REVISION {
350 continue; 345 continue;
351 } 346 }
352 let in_other_visit = if this_visit_is_revs { 347 if bases_visit.contains(&p) || both_visit.contains(&p) {
353 bases_visit.contains(&p)
354 } else {
355 revs_visit.contains(&p)
356 };
357 if in_other_visit || both_visit.contains(&p) {
358 // p is implicitely in this_visit. 348 // p is implicitely in this_visit.
359 // This means p is or should be in bothvisit 349 // This means p is or should be in bothvisit
360 // TODO optim: hence if bothvisit, we look up twice 350 // TODO optim: hence if bothvisit, we look up twice
361 revs_visit.remove(&p); 351 revs_visit.remove(&p);
362 bases_visit.insert(p); 352 bases_visit.insert(p);
363 both_visit.insert(p); 353 both_visit.insert(p);
364 } else { 354 } else {
365 // visit later 355 // visit later
366 if this_visit_is_revs { 356 revs_visit.insert(p);
367 revs_visit.insert(p);
368 } else {
369 bases_visit.insert(p);
370 }
371 } 357 }
372 } 358 }
373 } else if bases_visit.contains(&curr) { 359 } else if bases_visit.contains(&curr) {
374 this_visit_is_revs = false;
375 for p in self.graph.parents(curr)?.iter().cloned() { 360 for p in self.graph.parents(curr)?.iter().cloned() {
376 if p == NULL_REVISION { 361 if p == NULL_REVISION {
377 continue; 362 continue;
378 } 363 }
379 let in_other_visit = if this_visit_is_revs { 364 if revs_visit.contains(&p) || both_visit.contains(&p) {
380 bases_visit.contains(&p)
381 } else {
382 revs_visit.contains(&p)
383 };
384 if in_other_visit || both_visit.contains(&p) {
385 // p is implicitely in this_visit. 365 // p is implicitely in this_visit.
386 // This means p is or should be in bothvisit 366 // This means p is or should be in bothvisit
387 // TODO optim: hence if bothvisit, we look up twice 367 // TODO optim: hence if bothvisit, we look up twice
388 revs_visit.remove(&p); 368 revs_visit.remove(&p);
389 bases_visit.insert(p); 369 bases_visit.insert(p);
390 both_visit.insert(p); 370 both_visit.insert(p);
391 } else { 371 } else {
392 // visit later 372 // visit later
393 if this_visit_is_revs { 373 bases_visit.insert(p);
394 revs_visit.insert(p);
395 } else {
396 bases_visit.insert(p);
397 }
398 } 374 }
399 } 375 }
400 } else { 376 } else {
401 // not an ancestor of revs or bases: ignore 377 // not an ancestor of revs or bases: ignore
402 } 378 }