Mercurial > hg
annotate rust/hg-cpython/src/dirstate/status.rs @ 48391:b80e5e75d51e
dirstate: remove `lastnormaltime` mechanism
This is now redundant with the new, simpler `mtime_boundary` one.
Differential Revision: https://phab.mercurial-scm.org/D11795
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 25 Oct 2021 11:36:22 +0200 |
parents | 269ff8978086 |
children | 473af5cbc209 |
rev | line source |
---|---|
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 |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
12 use crate::{dirstate::DirstateMap, exceptions::FallbackError}; |
45861
c9c3c277e5a5
rust-status: properly translate OSError to Python
Raphaël Gomès <rgomes@octobus.net>
parents:
45610
diff
changeset
|
13 use cpython::exc::OSError; |
43273
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
14 use cpython::{ |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
15 exc::ValueError, ObjectProtocol, PyBytes, PyErr, PyList, PyObject, |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
16 PyResult, PyTuple, Python, PythonObject, ToPyObject, |
43273
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
17 }; |
43916
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
18 use hg::{ |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
19 matchers::{AlwaysMatcher, FileMatcher, IncludeMatcher}, |
47093
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
20 parse_pattern_syntax, |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
21 utils::{ |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
22 files::{get_bytes_from_path, get_path_from_bytes}, |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
23 hg_path::{HgPath, HgPathBuf}, |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
24 }, |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
25 BadMatch, DirstateStatus, IgnorePattern, PatternFileWarning, StatusError, |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
26 StatusOptions, |
43916
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
27 }; |
47110
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
28 use std::borrow::Borrow; |
43273
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
29 |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
30 /// 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
|
31 /// upstream. |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
32 fn collect_pybytes_list( |
43273
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
33 py: Python, |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
34 collection: &[impl AsRef<HgPath>], |
43273
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
35 ) -> PyList { |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
36 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
|
37 |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
38 for path in collection.iter() { |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
39 list.append( |
43273
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
40 py, |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
41 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
|
42 ) |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
43 } |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
44 |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
45 list |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
46 } |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
47 |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
48 fn collect_bad_matches( |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
49 py: Python, |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
50 collection: &[(impl AsRef<HgPath>, BadMatch)], |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
51 ) -> PyResult<PyList> { |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
52 let list = PyList::new(py, &[]); |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
53 |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
54 let os = py.import("os")?; |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
55 let get_error_message = |code: i32| -> PyResult<_> { |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
56 os.call( |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
57 py, |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
58 "strerror", |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
59 PyTuple::new(py, &[code.to_py_object(py).into_object()]), |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
60 None, |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
61 ) |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
62 }; |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
63 |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
64 for (path, bad_match) in collection.iter() { |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
65 let message = match bad_match { |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
66 BadMatch::OsError(code) => get_error_message(*code)?, |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
67 BadMatch::BadType(bad_type) => format!( |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
68 "unsupported file type (type is {})", |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
69 bad_type.to_string() |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
70 ) |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
71 .to_py_object(py) |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
72 .into_object(), |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
73 }; |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
74 list.append( |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
75 py, |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
76 (PyBytes::new(py, path.as_ref().as_bytes()), message) |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
77 .to_py_object(py) |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
78 .into_object(), |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
79 ) |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
80 } |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
81 |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
82 Ok(list) |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
83 } |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
84 |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
85 fn handle_fallback(py: Python, err: StatusError) -> PyErr { |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
86 match err { |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
87 StatusError::Pattern(e) => { |
44572
245aec57d76a
rust-status: add trace-level logging for Rust status fallback for debugging
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
88 let as_string = e.to_string(); |
245aec57d76a
rust-status: add trace-level logging for Rust status fallback for debugging
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
89 log::trace!("Rust status fallback: `{}`", &as_string); |
245aec57d76a
rust-status: add trace-level logging for Rust status fallback for debugging
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
90 |
245aec57d76a
rust-status: add trace-level logging for Rust status fallback for debugging
Raphaël Gomès <rgomes@octobus.net>
parents:
44529
diff
changeset
|
91 PyErr::new::<FallbackError, _>(py, &as_string) |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
92 } |
45861
c9c3c277e5a5
rust-status: properly translate OSError to Python
Raphaël Gomès <rgomes@octobus.net>
parents:
45610
diff
changeset
|
93 StatusError::IO(e) => PyErr::new::<OSError, _>(py, e.to_string()), |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
94 e => PyErr::new::<ValueError, _>(py, e.to_string()), |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
95 } |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
96 } |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
97 |
43273
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
98 pub fn status_wrapper( |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
99 py: Python, |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
100 dmap: DirstateMap, |
43916
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
101 matcher: PyObject, |
43273
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
102 root_dir: PyObject, |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
103 ignore_files: PyList, |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
104 check_exec: bool, |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
105 list_clean: bool, |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
106 list_ignored: bool, |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
107 list_unknown: bool, |
44839
01afda7e7d6c
rust-hg-cpython: update status bridge with the new `traversedir` support
Raphaël Gomès <rgomes@octobus.net>
parents:
44597
diff
changeset
|
108 collect_traversed_dirs: bool, |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
109 ) -> PyResult<PyTuple> { |
43273
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
110 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
|
111 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
|
112 |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
113 let dmap: DirstateMap = dmap.to_py_object(py); |
47112
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
114 let mut dmap = dmap.get_inner_mut(py); |
43273
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
115 |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
116 let ignore_files: PyResult<Vec<_>> = ignore_files |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
117 .iter(py) |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
118 .map(|b| { |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
119 let file = b.extract::<PyBytes>(py)?; |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
120 Ok(get_path_from_bytes(file.data(py)).to_owned()) |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
121 }) |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
122 .collect(); |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
123 let ignore_files = ignore_files?; |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
124 |
43916
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
125 match matcher.get_type(py).name(py).borrow() { |
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
126 "alwaysmatcher" => { |
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
127 let matcher = AlwaysMatcher; |
47110
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
128 let (status_res, warnings) = dmap |
47093
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
129 .status( |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
130 &matcher, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
131 root_dir.to_path_buf(), |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
132 ignore_files, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
133 StatusOptions { |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
134 check_exec, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
135 list_clean, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
136 list_ignored, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
137 list_unknown, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
138 collect_traversed_dirs, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
139 }, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
140 ) |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
141 .map_err(|e| handle_fallback(py, e))?; |
47110
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
142 build_response(py, status_res, warnings) |
43916
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
143 } |
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
144 "exactmatcher" => { |
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
145 let files = matcher.call_method( |
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
146 py, |
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
147 "files", |
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
148 PyTuple::new(py, &[]), |
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
149 None, |
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
150 )?; |
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
151 let files: PyList = files.cast_into(py)?; |
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
152 let files: PyResult<Vec<HgPathBuf>> = files |
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
153 .iter(py) |
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
154 .map(|f| { |
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
155 Ok(HgPathBuf::from_bytes( |
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
156 f.extract::<PyBytes>(py)?.data(py), |
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
157 )) |
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
158 }) |
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
159 .collect(); |
43915
8c77826116f7
rust-dirstate-status: add `walk_explicit` implementation, use `Matcher` trait
Raphaël Gomès <rgomes@octobus.net>
parents:
43818
diff
changeset
|
160 |
43916
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
161 let files = files?; |
45610
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45111
diff
changeset
|
162 let matcher = FileMatcher::new(files.as_ref()) |
43916
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
163 .map_err(|e| PyErr::new::<ValueError, _>(py, e.to_string()))?; |
47110
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
164 let (status_res, warnings) = dmap |
47093
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
165 .status( |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
166 &matcher, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
167 root_dir.to_path_buf(), |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
168 ignore_files, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
169 StatusOptions { |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
170 check_exec, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
171 list_clean, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
172 list_ignored, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
173 list_unknown, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
174 collect_traversed_dirs, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
175 }, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
176 ) |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
177 .map_err(|e| handle_fallback(py, e))?; |
47110
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
178 build_response(py, status_res, warnings) |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
179 } |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
180 "includematcher" => { |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
181 // Get the patterns from Python even though most of them are |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
182 // redundant with those we will parse later on, as they include |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
183 // those passed from the command line. |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
184 let ignore_patterns: PyResult<Vec<_>> = matcher |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
185 .getattr(py, "_kindpats")? |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
186 .iter(py)? |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
187 .map(|k| { |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
188 let k = k?; |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
189 let syntax = parse_pattern_syntax( |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
190 &[ |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
191 k.get_item(py, 0)? |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
192 .extract::<PyBytes>(py)? |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
193 .data(py), |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
194 &b":"[..], |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
195 ] |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
196 .concat(), |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
197 ) |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
198 .map_err(|e| { |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
199 handle_fallback(py, StatusError::Pattern(e)) |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
200 })?; |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
201 let pattern = k.get_item(py, 1)?.extract::<PyBytes>(py)?; |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
202 let pattern = pattern.data(py); |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
203 let source = k.get_item(py, 2)?.extract::<PyBytes>(py)?; |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
204 let source = get_path_from_bytes(source.data(py)); |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
205 let new = IgnorePattern::new(syntax, pattern, source); |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
206 Ok(new) |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
207 }) |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
208 .collect(); |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
209 |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
210 let ignore_patterns = ignore_patterns?; |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
211 |
47379
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47350
diff
changeset
|
212 let matcher = IncludeMatcher::new(ignore_patterns) |
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47350
diff
changeset
|
213 .map_err(|e| handle_fallback(py, e.into()))?; |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
214 |
47110
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
215 let (status_res, warnings) = dmap |
47093
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
216 .status( |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
217 &matcher, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
218 root_dir.to_path_buf(), |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
219 ignore_files, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
220 StatusOptions { |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
221 check_exec, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
222 list_clean, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
223 list_ignored, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
224 list_unknown, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
225 collect_traversed_dirs, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
226 }, |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
227 ) |
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
45861
diff
changeset
|
228 .map_err(|e| handle_fallback(py, e))?; |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
229 |
47379
f6bb181c75f8
rust: Parse "subinclude"d files along the way, not later
Simon Sapin <simon.sapin@octobus.net>
parents:
47350
diff
changeset
|
230 build_response(py, status_res, warnings) |
43916
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
231 } |
44973
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44839
diff
changeset
|
232 e => Err(PyErr::new::<ValueError, _>( |
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44839
diff
changeset
|
233 py, |
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44839
diff
changeset
|
234 format!("Unsupported matcher {}", e), |
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44839
diff
changeset
|
235 )), |
43916
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
236 } |
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
237 } |
43273
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
238 |
43916
6a88ced33c40
rust-dirstate-status: update bridge for new rust version of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43915
diff
changeset
|
239 fn build_response( |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
240 py: Python, |
44525
f13d19549efd
rust-status: rename `StatusResult` to `DirstateStatus`
Raphaël Gomès <rgomes@octobus.net>
parents:
44232
diff
changeset
|
241 status_res: DirstateStatus, |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
242 warnings: Vec<PatternFileWarning>, |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
243 ) -> PyResult<PyTuple> { |
43273
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
244 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
|
245 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
|
246 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
|
247 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
|
248 let clean = collect_pybytes_list(py, status_res.clean.as_ref()); |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
249 let ignored = collect_pybytes_list(py, status_res.ignored.as_ref()); |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
250 let unknown = collect_pybytes_list(py, status_res.unknown.as_ref()); |
47110
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
251 let unsure = collect_pybytes_list(py, status_res.unsure.as_ref()); |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
252 let bad = collect_bad_matches(py, status_res.bad.as_ref())?; |
44839
01afda7e7d6c
rust-hg-cpython: update status bridge with the new `traversedir` support
Raphaël Gomès <rgomes@octobus.net>
parents:
44597
diff
changeset
|
253 let traversed = collect_pybytes_list(py, status_res.traversed.as_ref()); |
47350
04d1f17f49e7
dirstate-v2: Write .hg/dirstate back to disk on directory cache changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
254 let dirty = status_res.dirty.to_py_object(py); |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
255 let py_warnings = PyList::new(py, &[]); |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
256 for warning in warnings.iter() { |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
257 // We use duck-typing on the Python side for dispatch, good enough for |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
258 // now. |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
259 match warning { |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
260 PatternFileWarning::InvalidSyntax(file, syn) => { |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
261 py_warnings.append( |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
262 py, |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
263 ( |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
264 PyBytes::new(py, &get_bytes_from_path(&file)), |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
265 PyBytes::new(py, syn), |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
266 ) |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
267 .to_py_object(py) |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
268 .into_object(), |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
269 ); |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
270 } |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
271 PatternFileWarning::NoSuchFile(file) => py_warnings.append( |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
272 py, |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
273 PyBytes::new(py, &get_bytes_from_path(&file)).into_object(), |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
274 ), |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
275 } |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
276 } |
43273
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
277 |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
278 Ok(PyTuple::new( |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
279 py, |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
280 &[ |
47110
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
281 unsure.into_object(), |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
282 modified.into_object(), |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
283 added.into_object(), |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
284 removed.into_object(), |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
285 deleted.into_object(), |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
286 clean.into_object(), |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
287 ignored.into_object(), |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
288 unknown.into_object(), |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
289 py_warnings.into_object(), |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
290 bad.into_object(), |
44839
01afda7e7d6c
rust-hg-cpython: update status bridge with the new `traversedir` support
Raphaël Gomès <rgomes@octobus.net>
parents:
44597
diff
changeset
|
291 traversed.into_object(), |
47350
04d1f17f49e7
dirstate-v2: Write .hg/dirstate back to disk on directory cache changes
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
292 dirty.into_object(), |
44529
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
293 ][..], |
f96b28aa4b79
rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents:
44525
diff
changeset
|
294 )) |
43273
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
295 } |