##// END OF EJS Templates
rust-cpython: run cargo fmt
Yuya Nishihara -
r43612:21a1b209 default
parent child Browse files
Show More
@@ -1,82 +1,83 b''
1 1 // status.rs
2 2 //
3 3 // Copyright 2019, Raphaël Gomès <rgomes@octobus.net>
4 4 //
5 5 // This software may be used and distributed according to the terms of the
6 6 // GNU General Public License version 2 or any later version.
7 7
8 8 //! Bindings for the `hg::status` module provided by the
9 //! `hg-core` crate. From Python, this will be seen as `rustext.dirstate.status`.
9 //! `hg-core` crate. From Python, this will be seen as
10 //! `rustext.dirstate.status`.
10 11 //!
11 12
12 13 use crate::dirstate::DirstateMap;
13 14 use cpython::exc::ValueError;
14 15 use cpython::{
15 16 PyBytes, PyErr, PyList, PyObject, PyResult, Python, PythonObject,
16 17 ToPyObject,
17 18 };
18 19 use hg::utils::files::get_path_from_bytes;
19 20
20 21 use hg::utils::hg_path::HgPath;
21 22 use hg::{status, utils::hg_path::HgPathBuf};
22 23
23 24 /// This will be useless once trait impls for collection are added to `PyBytes`
24 25 /// upstream.
25 26 fn collect_pybytes_list<P: AsRef<HgPath>>(
26 27 py: Python,
27 28 collection: &[P],
28 29 ) -> PyList {
29 30 let list = PyList::new(py, &[]);
30 31
31 32 for (i, path) in collection.iter().enumerate() {
32 33 list.insert_item(
33 34 py,
34 35 i,
35 36 PyBytes::new(py, path.as_ref().as_bytes()).into_object(),
36 37 )
37 38 }
38 39
39 40 list
40 41 }
41 42
42 43 pub fn status_wrapper(
43 44 py: Python,
44 45 dmap: DirstateMap,
45 46 root_dir: PyObject,
46 47 files: PyList,
47 48 list_clean: bool,
48 49 last_normal_time: i64,
49 50 check_exec: bool,
50 51 ) -> PyResult<(PyList, PyList, PyList, PyList, PyList, PyList, PyList)> {
51 52 let bytes = root_dir.extract::<PyBytes>(py)?;
52 53 let root_dir = get_path_from_bytes(bytes.data(py));
53 54
54 55 let dmap: DirstateMap = dmap.to_py_object(py);
55 56 let dmap = dmap.get_inner(py);
56 57
57 58 let files: PyResult<Vec<HgPathBuf>> = files
58 59 .iter(py)
59 60 .map(|f| Ok(HgPathBuf::from_bytes(f.extract::<PyBytes>(py)?.data(py))))
60 61 .collect();
61 62 let files = files?;
62 63
63 64 let (lookup, status_res) = status(
64 65 &dmap,
65 66 &root_dir,
66 67 &files,
67 68 list_clean,
68 69 last_normal_time,
69 70 check_exec,
70 71 )
71 72 .map_err(|e| PyErr::new::<ValueError, _>(py, e.to_string()))?;
72 73
73 74 let modified = collect_pybytes_list(py, status_res.modified.as_ref());
74 75 let added = collect_pybytes_list(py, status_res.added.as_ref());
75 76 let removed = collect_pybytes_list(py, status_res.removed.as_ref());
76 77 let deleted = collect_pybytes_list(py, status_res.deleted.as_ref());
77 78 let clean = collect_pybytes_list(py, status_res.clean.as_ref());
78 79 let lookup = collect_pybytes_list(py, lookup.as_ref());
79 80 let unknown = PyList::new(py, &[]);
80 81
81 82 Ok((lookup, modified, added, removed, deleted, unknown, clean))
82 83 }
General Comments 0
You need to be logged in to leave comments. Login now