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