D5416: rust: translation of missingancestors

Yuya Nishihara yuya at tcha.org
Wed Dec 19 08:55:42 EST 2018


>   >  +            // in Rust, one can't just use mutable variables assignation
>   >  +            // to be more straightforward. Instead of Python's
>   >  +            // thisvisit and othervisit, we'll differentiate with a boolean
>   >  +            let this_visit_is_revs = {
>   >  +                if revs_visit.remove(&curr) {
>   >  +                    missing.push(curr);
>   >  +                    true
>   >  +                } else if bases_visit.contains(&curr) {
>   >  +                    false
>   >  +                } else {
>   >  +                    // not an ancestor of revs or bases: ignore
>   >  +                    continue;
>   >  +                }
>   >  +            };
>   
>   Maybe this could be extracted to a function
>   `visit_parents(&mut revs_visit, &mut bases_visit, select_this, select_other)`
>   where `select_this` and `select_other` are `FnMut(&mut, &mut) -> &mut`, but
>   I don't know if that will improve the readability.

Actually it looks better if I copy-paste the visit loop. I'll send follow-up
patches.

```
            if both_visit.contains(&curr) {
                for p in ...
            } else if revs_visit.remove(&curr) {
                missing.push(curr);
                for p in ...
            } else if bases_visit.contains(&curr) {
                for p in ...
            }
```


More information about the Mercurial-devel mailing list