Mercurial > public > mercurial-scm > hg
comparison rust/hg-cpython/src/parsers.rs @ 42749: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 |
comparison
equal
deleted
inserted
replaced
42748:7cae6bc29ff9 | 42749:7ceded4419a3 |
---|---|
35 let mut copies = HashMap::new(); | 35 let mut copies = HashMap::new(); |
36 | 36 |
37 match parse_dirstate(&mut dirstate_map, &mut copies, st.data(py)) { | 37 match parse_dirstate(&mut dirstate_map, &mut copies, st.data(py)) { |
38 Ok(parents) => { | 38 Ok(parents) => { |
39 for (filename, entry) in dirstate_map { | 39 for (filename, entry) in dirstate_map { |
40 // Explicitly go through u8 first, then cast to | |
41 // platform-specific `c_char` because Into<u8> has a specific | |
42 // implementation while `as c_char` would just do a naive enum | |
43 // cast. | |
44 let state: u8 = entry.state.into(); | |
45 | |
40 dmap.set_item( | 46 dmap.set_item( |
41 py, | 47 py, |
42 PyBytes::new(py, &filename), | 48 PyBytes::new(py, &filename), |
43 decapsule_make_dirstate_tuple(py)?( | 49 decapsule_make_dirstate_tuple(py)?( |
44 entry.state as c_char, | 50 state as c_char, |
45 entry.mode, | 51 entry.mode, |
46 entry.size, | 52 entry.size, |
47 entry.mtime, | 53 entry.mtime, |
48 ), | 54 ), |
49 )?; | 55 )?; |
128 size, | 134 size, |
129 mtime, | 135 mtime, |
130 }, | 136 }, |
131 ) in dirstate_map | 137 ) in dirstate_map |
132 { | 138 { |
139 // Explicitly go through u8 first, then cast to | |
140 // platform-specific `c_char` because Into<u8> has a specific | |
141 // implementation while `as c_char` would just do a naive enum | |
142 // cast. | |
143 let state: u8 = state.into(); | |
133 dmap.set_item( | 144 dmap.set_item( |
134 py, | 145 py, |
135 PyBytes::new(py, &filename[..]), | 146 PyBytes::new(py, &filename[..]), |
136 decapsule_make_dirstate_tuple(py)?( | 147 decapsule_make_dirstate_tuple(py)?( |
137 state as c_char, | 148 state as c_char, |