Mercurial > public > mercurial-scm > hg
annotate rust/hg-cpython/src/vfs.rs @ 52178:bd8081e9fd62
rust: don't star export from the `revlog` module
This made a lot of the imports confusing because they didn't make sense
at the top level (so, outside of `revlog`), and they hide the more common
types when autocompleting.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Thu, 26 Sep 2024 14:26:24 +0200 |
parents | 72bc29f01570 |
children | 735bf027dd1d |
rev | line source |
---|---|
52163
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1 use std::{ |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
2 cell::Cell, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
3 fs::File, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
4 io::Error, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
5 os::fd::{AsRawFd, FromRawFd}, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
6 path::{Path, PathBuf}, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
7 }; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
8 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
9 use cpython::{ |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
10 ObjectProtocol, PyBytes, PyClone, PyDict, PyErr, PyInt, PyObject, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
11 PyResult, PyTuple, Python, PythonObject, ToPyObject, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
12 }; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
13 use hg::{ |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
14 errors::{HgError, IoResultExt}, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
15 exit_codes, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
16 utils::files::{get_bytes_from_path, get_path_from_bytes}, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
17 vfs::Vfs, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
18 }; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
19 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
20 /// Wrapper around a Python VFS object to call back into Python from `hg-core`. |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
21 pub struct PyVfs { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
22 inner: PyObject, |
52172
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52167
diff
changeset
|
23 base: PathBuf, |
52163
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
24 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
25 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
26 impl Clone for PyVfs { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
27 fn clone(&self) -> Self { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
28 let gil = &Python::acquire_gil(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
29 let py = gil.python(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
30 Self { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
31 inner: self.inner.clone_ref(py), |
52172
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52167
diff
changeset
|
32 base: self.base.clone(), |
52163
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
33 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
34 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
35 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
36 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
37 impl PyVfs { |
52172
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52167
diff
changeset
|
38 pub fn new( |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52167
diff
changeset
|
39 _py: Python, |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52167
diff
changeset
|
40 py_vfs: PyObject, |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52167
diff
changeset
|
41 base: PathBuf, |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52167
diff
changeset
|
42 ) -> PyResult<Self> { |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52167
diff
changeset
|
43 Ok(Self { |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52167
diff
changeset
|
44 inner: py_vfs, |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52167
diff
changeset
|
45 base, |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52167
diff
changeset
|
46 }) |
52163
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
47 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
48 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
49 fn inner_open( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
50 &self, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
51 filename: &Path, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
52 create: bool, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
53 check_ambig: bool, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
54 atomic_temp: bool, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
55 write: bool, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
56 ) -> Result<(File, Option<PathBuf>), HgError> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
57 let gil = &Python::acquire_gil(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
58 let py = gil.python(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
59 let mode = if atomic_temp { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
60 PyBytes::new(py, b"w") |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
61 } else if create { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
62 PyBytes::new(py, b"w+") |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
63 } else if write { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
64 PyBytes::new(py, b"r+") |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
65 } else { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
66 PyBytes::new(py, b"rb") |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
67 }; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
68 let res = self.inner.call( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
69 py, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
70 ( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
71 PyBytes::new(py, &get_bytes_from_path(filename)), |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
72 mode, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
73 atomic_temp, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
74 check_ambig, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
75 ), |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
76 None, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
77 ); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
78 match res { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
79 Ok(tup) => { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
80 let tup = tup |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
81 .extract::<PyTuple>(py) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
82 .map_err(|e| vfs_error("vfs did not return a tuple", e))?; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
83 let fileno = tup.get_item(py, 0).extract(py).map_err(|e| { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
84 vfs_error("vfs did not return a valid fileno", e) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
85 })?; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
86 let temp_name = tup.get_item(py, 1); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
87 // Safety: this must be a valid owned file descriptor, and |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
88 // Python has just given it to us, it will only exist here now |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
89 let file = unsafe { File::from_raw_fd(fileno) }; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
90 let temp_name = if atomic_temp { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
91 Some( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
92 get_path_from_bytes( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
93 temp_name |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
94 .extract::<PyBytes>(py) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
95 .map_err(|e| vfs_error("invalid tempname", e))? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
96 .data(py), |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
97 ) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
98 .to_owned(), |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
99 ) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
100 } else { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
101 None |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
102 }; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
103 Ok((file, temp_name)) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
104 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
105 Err(mut e) => { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
106 // TODO surely there is a better way of comparing |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
107 if e.instance(py).get_type(py).name(py) == "FileNotFoundError" |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
108 { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
109 return Err(HgError::IoError { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
110 error: Error::new( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
111 std::io::ErrorKind::NotFound, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
112 e.instance(py).to_string(), |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
113 ), |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
114 context: hg::errors::IoErrorContext::ReadingFile( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
115 filename.to_owned(), |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
116 ), |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
117 }); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
118 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
119 Err(vfs_error("failed to call opener", e)) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
120 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
121 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
122 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
123 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
124 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
125 fn vfs_error(reason: impl Into<String>, mut error: PyErr) -> HgError { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
126 let gil = &Python::acquire_gil(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
127 let py = gil.python(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
128 HgError::abort( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
129 format!("{}: {}", reason.into(), error.instance(py)), |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
130 exit_codes::ABORT, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
131 None, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
132 ) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
133 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
134 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
135 py_class!(pub class PyFile |py| { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
136 data number: Cell<i32>; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
137 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
138 def fileno(&self) -> PyResult<PyInt> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
139 Ok(self.number(py).get().to_py_object(py)) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
140 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
141 }); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
142 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
143 impl Vfs for PyVfs { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
144 fn open(&self, filename: &Path) -> Result<File, HgError> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
145 self.inner_open(filename, false, false, false, true) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
146 .map(|(f, _)| f) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
147 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
148 fn open_read(&self, filename: &Path) -> Result<File, HgError> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
149 self.inner_open(filename, false, false, false, false) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
150 .map(|(f, _)| f) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
151 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
152 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
153 fn open_check_ambig( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
154 &self, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
155 filename: &Path, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
156 ) -> Result<std::fs::File, HgError> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
157 self.inner_open(filename, false, true, false, true) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
158 .map(|(f, _)| f) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
159 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
160 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
161 fn create(&self, filename: &Path) -> Result<std::fs::File, HgError> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
162 self.inner_open(filename, true, false, false, true) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
163 .map(|(f, _)| f) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
164 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
165 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
166 fn create_atomic( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
167 &self, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
168 filename: &Path, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
169 check_ambig: bool, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
170 ) -> Result<hg::vfs::AtomicFile, HgError> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
171 self.inner_open(filename, true, false, true, true).map( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
172 |(fp, temp_name)| { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
173 hg::vfs::AtomicFile::new( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
174 fp, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
175 check_ambig, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
176 temp_name.expect("temp name should exist"), |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
177 filename.to_owned(), |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
178 ) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
179 }, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
180 ) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
181 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
182 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
183 fn file_size(&self, file: &File) -> Result<u64, HgError> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
184 let gil = &Python::acquire_gil(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
185 let py = gil.python(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
186 let raw_fd = file.as_raw_fd(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
187 let py_fd = PyFile::create_instance(py, Cell::new(raw_fd)) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
188 .expect("create_instance cannot fail"); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
189 let fstat = self |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
190 .inner |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
191 .call_method(py, "fstat", (py_fd,), None) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
192 .map_err(|e| { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
193 vfs_error(format!("failed to fstat fd '{}'", raw_fd), e) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
194 })?; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
195 fstat |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
196 .getattr(py, "st_size") |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
197 .map(|v| { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
198 v.extract(py).map_err(|e| { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
199 vfs_error(format!("invalid size for fd '{}'", raw_fd), e) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
200 }) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
201 }) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
202 .map_err(|e| { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
203 vfs_error(format!("failed to get size of fd '{}'", raw_fd), e) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
204 })? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
205 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
206 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
207 fn exists(&self, filename: &Path) -> bool { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
208 let gil = &Python::acquire_gil(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
209 let py = gil.python(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
210 self.inner |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
211 .call_method( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
212 py, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
213 "exists", |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
214 (PyBytes::new(py, &get_bytes_from_path(filename)),), |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
215 None, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
216 ) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
217 .unwrap_or_else(|_| false.into_py_object(py).into_object()) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
218 .extract(py) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
219 .unwrap() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
220 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
221 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
222 fn unlink(&self, filename: &Path) -> Result<(), HgError> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
223 let gil = &Python::acquire_gil(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
224 let py = gil.python(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
225 if let Err(e) = self.inner.call_method( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
226 py, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
227 "unlink", |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
228 (PyBytes::new(py, &get_bytes_from_path(filename)),), |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
229 None, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
230 ) { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
231 return Err(vfs_error( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
232 format!("failed to unlink '{}'", filename.display()), |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
233 e, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
234 )); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
235 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
236 Ok(()) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
237 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
238 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
239 fn rename( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
240 &self, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
241 from: &Path, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
242 to: &Path, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
243 check_ambig: bool, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
244 ) -> Result<(), HgError> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
245 let gil = &Python::acquire_gil(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
246 let py = gil.python(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
247 let kwargs = PyDict::new(py); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
248 kwargs |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
249 .set_item(py, "checkambig", check_ambig) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
250 .map_err(|e| vfs_error("dict setitem failed", e))?; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
251 if let Err(e) = self.inner.call_method( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
252 py, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
253 "rename", |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
254 ( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
255 PyBytes::new(py, &get_bytes_from_path(from)), |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
256 PyBytes::new(py, &get_bytes_from_path(to)), |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
257 ), |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
258 Some(&kwargs), |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
259 ) { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
260 let msg = format!( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
261 "failed to rename '{}' to '{}'", |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
262 from.display(), |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
263 to.display() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
264 ); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
265 return Err(vfs_error(msg, e)); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
266 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
267 Ok(()) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
268 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
269 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
270 fn copy(&self, from: &Path, to: &Path) -> Result<(), HgError> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
271 let gil = &Python::acquire_gil(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
272 let py = gil.python(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
273 let from = self |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
274 .inner |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
275 .call_method( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
276 py, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
277 "join", |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
278 (PyBytes::new(py, &get_bytes_from_path(from)),), |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
279 None, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
280 ) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
281 .unwrap(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
282 let from = from.extract::<PyBytes>(py).unwrap(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
283 let from = get_path_from_bytes(from.data(py)); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
284 let to = self |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
285 .inner |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
286 .call_method( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
287 py, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
288 "join", |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
289 (PyBytes::new(py, &get_bytes_from_path(to)),), |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
290 None, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
291 ) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
292 .unwrap(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
293 let to = to.extract::<PyBytes>(py).unwrap(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
294 let to = get_path_from_bytes(to.data(py)); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
295 std::fs::copy(from, to).when_writing_file(to)?; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
296 Ok(()) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
297 } |
52167
7be39c5110c9
hg-core: add a complete VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
298 |
7be39c5110c9
hg-core: add a complete VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
299 fn base(&self) -> &Path { |
52172
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52167
diff
changeset
|
300 &self.base |
52167
7be39c5110c9
hg-core: add a complete VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
301 } |
52163
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
302 } |