Mercurial > hg
comparison rust/hg-cpython/src/dirstate.rs @ 42748:7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Both `parse_dirstate` and `pack_dirstate` can operate directly on the data
they're passed, which prevents the creation of intermediate data structures,
simplifies the function signatures and reduces boilerplate. They are exposed
directly to the Python for now, but a later patch will make use of them inside
`hg-core`.
Differential Revision: https://phab.mercurial-scm.org/D6628
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Tue, 09 Jul 2019 11:49:49 +0200 |
parents | 760a7851e9ba |
children | 7ceded4419a3 |
comparison
equal
deleted
inserted
replaced
42747:760a7851e9ba | 42748:7cae6bc29ff9 |
---|---|
12 mod dirs_multiset; | 12 mod dirs_multiset; |
13 use crate::dirstate::dirs_multiset::Dirs; | 13 use crate::dirstate::dirs_multiset::Dirs; |
14 use cpython::{ | 14 use cpython::{ |
15 PyBytes, PyDict, PyErr, PyModule, PyObject, PyResult, PySequence, Python, | 15 PyBytes, PyDict, PyErr, PyModule, PyObject, PyResult, PySequence, Python, |
16 }; | 16 }; |
17 use hg::{DirstateEntry, DirstateVec}; | 17 use hg::{DirstateEntry, StateMap}; |
18 use libc::{c_char, c_int}; | 18 use libc::{c_char, c_int}; |
19 #[cfg(feature = "python27")] | 19 #[cfg(feature = "python27")] |
20 use python27_sys::PyCapsule_Import; | 20 use python27_sys::PyCapsule_Import; |
21 #[cfg(feature = "python3")] | 21 #[cfg(feature = "python3")] |
22 use python3_sys::PyCapsule_Import; | 22 use python3_sys::PyCapsule_Import; |
52 } | 52 } |
53 Ok(transmute(from_caps)) | 53 Ok(transmute(from_caps)) |
54 } | 54 } |
55 } | 55 } |
56 | 56 |
57 pub fn extract_dirstate_vec( | 57 pub fn extract_dirstate(py: Python, dmap: &PyDict) -> Result<StateMap, PyErr> { |
58 py: Python, | |
59 dmap: &PyDict, | |
60 ) -> Result<DirstateVec, PyErr> { | |
61 dmap.items(py) | 58 dmap.items(py) |
62 .iter() | 59 .iter() |
63 .map(|(filename, stats)| { | 60 .map(|(filename, stats)| { |
64 let stats = stats.extract::<PySequence>(py)?; | 61 let stats = stats.extract::<PySequence>(py)?; |
65 let state = stats.get_item(py, 0)?.extract::<PyBytes>(py)?; | 62 let state = stats.get_item(py, 0)?.extract::<PyBytes>(py)?; |