Mercurial > hg
diff rust/hg-cpython/src/dirstate/dirs_multiset.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 | 849e744b925d |
line wrap: on
line diff
--- a/rust/hg-cpython/src/dirstate/dirs_multiset.rs Tue Jul 09 11:49:49 2019 +0200 +++ b/rust/hg-cpython/src/dirstate/dirs_multiset.rs Tue Jul 09 12:15:09 2019 +0200 @@ -16,7 +16,11 @@ }; use crate::dirstate::extract_dirstate; -use hg::{DirsIterable, DirsMultiset, DirstateMapError}; +use hg::{ + DirsIterable, DirsMultiset, DirstateMapError, DirstateParseError, + EntryState, +}; +use std::convert::TryInto; py_class!(pub class Dirs |py| { data dirs_map: RefCell<DirsMultiset>; @@ -28,9 +32,15 @@ map: PyObject, skip: Option<PyObject> = None ) -> PyResult<Self> { - let mut skip_state: Option<i8> = None; + let mut skip_state: Option<EntryState> = None; if let Some(skip) = skip { - skip_state = Some(skip.extract::<PyBytes>(py)?.data(py)[0] as i8); + skip_state = Some( + skip.extract::<PyBytes>(py)?.data(py)[0] + .try_into() + .map_err(|e: DirstateParseError| { + PyErr::new::<exc::ValueError, _>(py, e.to_string()) + })?, + ); } let inner = if let Ok(map) = map.cast_as::<PyDict>(py) { let dirstate = extract_dirstate(py, &map)?;