changeset 47518:f6f25ab6bfc8

rust-dirstatemap: expand the wrapping code a bit This is easier to read. Differential Revision: https://phab.mercurial-scm.org/D10960
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sun, 04 Jul 2021 19:42:03 +0200
parents 28632eb3ca3e
children b68d61af85a9
files rust/hg-cpython/src/dirstate/dirstate_map.rs
diffstat 1 files changed, 24 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs	Sun Jul 04 01:14:15 2021 +0200
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs	Sun Jul 04 19:42:03 2021 +0200
@@ -112,23 +112,31 @@
         size: PyObject,
         mtime: PyObject
     ) -> PyResult<PyObject> {
+        let f = f.extract::<PyBytes>(py)?;
+        let filename = HgPath::new(f.data(py));
+        let oldstate = oldstate.extract::<PyBytes>(py)?.data(py)[0]
+            .try_into()
+            .map_err(|e: HgError| {
+                PyErr::new::<exc::ValueError, _>(py, e.to_string())
+            })?;
+        let state = state.extract::<PyBytes>(py)?.data(py)[0]
+            .try_into()
+            .map_err(|e: HgError| {
+                PyErr::new::<exc::ValueError, _>(py, e.to_string())
+            })?;
+        let mode = mode.extract(py)?;
+        let size = size.extract(py)?;
+        let mtime = mtime.extract(py)?;
+        let entry = DirstateEntry {
+            state: state,
+            mode: mode,
+            size: size,
+            mtime: mtime,
+        };
         self.inner(py).borrow_mut().add_file(
-            HgPath::new(f.extract::<PyBytes>(py)?.data(py)),
-            oldstate.extract::<PyBytes>(py)?.data(py)[0]
-                .try_into()
-                .map_err(|e: HgError| {
-                    PyErr::new::<exc::ValueError, _>(py, e.to_string())
-                })?,
-            DirstateEntry {
-                state: state.extract::<PyBytes>(py)?.data(py)[0]
-                    .try_into()
-                    .map_err(|e: HgError| {
-                        PyErr::new::<exc::ValueError, _>(py, e.to_string())
-                    })?,
-                mode: mode.extract(py)?,
-                size: size.extract(py)?,
-                mtime: mtime.extract(py)?,
-            },
+            filename,
+            oldstate,
+            entry,
         ).and(Ok(py.None())).or_else(|e: DirstateError| {
             Err(PyErr::new::<exc::ValueError, _>(py, e.to_string()))
         })