author | Gregory Szorc <gregory.szorc@gmail.com> |
Sat, 07 Dec 2019 13:06:25 -0800 | |
changeset 43818 | ce088b38f92b |
parent 43456 | ab9b0a20b9e6 |
child 43915 | 8c77826116f7 |
permissions | -rw-r--r-- |
43273
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
1 |
// status.rs |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
2 |
// |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
3 |
// Copyright 2019, Raphaël Gomès <rgomes@octobus.net> |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
4 |
// |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
5 |
// This software may be used and distributed according to the terms of the |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
6 |
// GNU General Public License version 2 or any later version. |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
7 |
|
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
8 |
//! Bindings for the `hg::status` module provided by the |
43431
21a1b2094649
rust-cpython: run cargo fmt
Yuya Nishihara <yuya@tcha.org>
parents:
43273
diff
changeset
|
9 |
//! `hg-core` crate. From Python, this will be seen as |
21a1b2094649
rust-cpython: run cargo fmt
Yuya Nishihara <yuya@tcha.org>
parents:
43273
diff
changeset
|
10 |
//! `rustext.dirstate.status`. |
43273
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
11 |
|
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
12 |
use crate::dirstate::DirstateMap; |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
13 |
use cpython::exc::ValueError; |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
14 |
use cpython::{ |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
15 |
PyBytes, PyErr, PyList, PyObject, PyResult, Python, PythonObject, |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
16 |
ToPyObject, |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
17 |
}; |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
18 |
use hg::utils::files::get_path_from_bytes; |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
19 |
|
43456
ab9b0a20b9e6
rust-status: remove dead code
Raphaël Gomès <rgomes@octobus.net>
parents:
43431
diff
changeset
|
20 |
use hg::status; |
43273
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
21 |
use hg::utils::hg_path::HgPath; |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
22 |
|
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
23 |
/// This will be useless once trait impls for collection are added to `PyBytes` |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
24 |
/// upstream. |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
25 |
fn collect_pybytes_list<P: AsRef<HgPath>>( |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
26 |
py: Python, |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
27 |
collection: &[P], |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
28 |
) -> PyList { |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
29 |
let list = PyList::new(py, &[]); |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
30 |
|
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
31 |
for (i, path) in collection.iter().enumerate() { |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
32 |
list.insert_item( |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
33 |
py, |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
34 |
i, |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
35 |
PyBytes::new(py, path.as_ref().as_bytes()).into_object(), |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
36 |
) |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
37 |
} |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
38 |
|
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
39 |
list |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
40 |
} |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
41 |
|
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
42 |
pub fn status_wrapper( |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
43 |
py: Python, |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
44 |
dmap: DirstateMap, |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
45 |
root_dir: PyObject, |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
46 |
list_clean: bool, |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
47 |
last_normal_time: i64, |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
48 |
check_exec: bool, |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
49 |
) -> PyResult<(PyList, PyList, PyList, PyList, PyList, PyList, PyList)> { |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
50 |
let bytes = root_dir.extract::<PyBytes>(py)?; |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
51 |
let root_dir = get_path_from_bytes(bytes.data(py)); |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
52 |
|
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
53 |
let dmap: DirstateMap = dmap.to_py_object(py); |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
54 |
let dmap = dmap.get_inner(py); |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
55 |
|
43456
ab9b0a20b9e6
rust-status: remove dead code
Raphaël Gomès <rgomes@octobus.net>
parents:
43431
diff
changeset
|
56 |
let (lookup, status_res) = |
ab9b0a20b9e6
rust-status: remove dead code
Raphaël Gomès <rgomes@octobus.net>
parents:
43431
diff
changeset
|
57 |
status(&dmap, &root_dir, list_clean, last_normal_time, check_exec) |
ab9b0a20b9e6
rust-status: remove dead code
Raphaël Gomès <rgomes@octobus.net>
parents:
43431
diff
changeset
|
58 |
.map_err(|e| PyErr::new::<ValueError, _>(py, e.to_string()))?; |
43273
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
59 |
|
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
60 |
let modified = collect_pybytes_list(py, status_res.modified.as_ref()); |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
61 |
let added = collect_pybytes_list(py, status_res.added.as_ref()); |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
62 |
let removed = collect_pybytes_list(py, status_res.removed.as_ref()); |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
63 |
let deleted = collect_pybytes_list(py, status_res.deleted.as_ref()); |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
64 |
let clean = collect_pybytes_list(py, status_res.clean.as_ref()); |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
65 |
let lookup = collect_pybytes_list(py, lookup.as_ref()); |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
66 |
let unknown = PyList::new(py, &[]); |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
67 |
|
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
68 |
Ok((lookup, modified, added, removed, deleted, unknown, clean)) |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
69 |
} |