( )⚙ D6629 rust-dirstate: use EntryState enum instead of literals

This is an archive of the discontinued Mercurial Phabricator instance.

rust-dirstate: use EntryState enum instead of literals
ClosedPublic

Authored by Alphare on Jul 10 2019, 7:46 AM.

Details

Summary

This improves code readability quite a bit, while also adding a layer of
safety because we're checking the state byte against the enum.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Alphare created this revision.Jul 10 2019, 7:46 AM
Alphare updated this revision to Diff 15898.Jul 12 2019, 5:22 AM
kevincox accepted this revision.Jul 15 2019, 12:08 PM
kevincox added inline comments.
rust/hg-core/src/lib.rs
78

I like using {!r} so that the substituted entry is quoted and unambiguous.

rust/hg-cpython/src/parsers.rs
42

If you are going to a comment I would say why. However in this case it probably isn't worth having a comment.

You can also do this on one line entry.state.into::<u8>() as c_char which I think is simple enough.

Alphare added inline comments.Jul 17 2019, 6:29 AM
rust/hg-core/src/lib.rs
78

Did you mean {:?}. I can't find anything related to your syntax.

rust/hg-cpython/src/parsers.rs
42

The one-liner does not compile, so I improved the comment to explain why (which it really should have in the first place).

kevincox added inline comments.Jul 17 2019, 7:35 AM
rust/hg-core/src/lib.rs
78

Sorry yes. I've been writing too much python at work.

This revision was not accepted when it landed; it landed in state Needs Review.
This revision was automatically updated to reflect the committed changes.