Mercurial > public > mercurial-scm > hg-stable
diff rust/hg-cpython/src/parsers.rs @ 42765:7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
This improves code readability quite a bit, while also adding a layer of
safety because we're checking the state byte against the enum.
Differential Revision: https://phab.mercurial-scm.org/D6629
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Tue, 09 Jul 2019 12:15:09 +0200 |
parents | 7cae6bc29ff9 |
children | 98901eb12245 |
line wrap: on
line diff
--- a/rust/hg-cpython/src/parsers.rs Tue Jul 09 11:49:49 2019 +0200 +++ b/rust/hg-cpython/src/parsers.rs Tue Jul 09 12:15:09 2019 +0200 @@ -37,11 +37,17 @@ match parse_dirstate(&mut dirstate_map, &mut copies, st.data(py)) { Ok(parents) => { for (filename, entry) in dirstate_map { + // Explicitly go through u8 first, then cast to + // platform-specific `c_char` because Into<u8> has a specific + // implementation while `as c_char` would just do a naive enum + // cast. + let state: u8 = entry.state.into(); + dmap.set_item( py, PyBytes::new(py, &filename), decapsule_make_dirstate_tuple(py)?( - entry.state as c_char, + state as c_char, entry.mode, entry.size, entry.mtime, @@ -130,6 +136,11 @@ }, ) in dirstate_map { + // Explicitly go through u8 first, then cast to + // platform-specific `c_char` because Into<u8> has a specific + // implementation while `as c_char` would just do a naive enum + // cast. + let state: u8 = state.into(); dmap.set_item( py, PyBytes::new(py, &filename[..]),