Mercurial > public > mercurial-scm > hg-stable
comparison rust/hg-core/src/dirstate_tree/dispatch.rs @ 47137:d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
? that has the contents of the `.hg/dirstate` file.
This only applies to the tree-based flavor of `DirstateMap`.
For now only the entire `&[u8]` slice is stored, so this is not useful yet.
Adding a lifetime parameter to the `DirstateMap` struct (in hg-core) makes
Python bindings non-trivial because we keep that struct in a Python object
that has a dynamic lifetime tied to Python?s reference-counting and GC.
As long as we keep the `PyBytes` that owns the borrowed bytes buffer next to
the borrowing struct, the buffer will live long enough for the borrows to stay
valid. However this relationship cannot be expressed in safe Rust code in a
way that would statisfy they borrow-checker. We use `unsafe` code to erase
that lifetime parameter, and encapsulate it in a safe abstraction similar to
the owning-ref crate: https://docs.rs/owning_ref/
Differential Revision: https://phab.mercurial-scm.org/D10557
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Fri, 30 Apr 2021 18:24:54 +0200 |
parents | b6339a993b91 |
children | cd8ca38fccff |
comparison
equal
deleted
inserted
replaced
47136:9aba0cde0ed9 | 47137:d8ac62374943 |
---|---|
71 fn has_dir( | 71 fn has_dir( |
72 &mut self, | 72 &mut self, |
73 directory: &HgPath, | 73 directory: &HgPath, |
74 ) -> Result<bool, DirstateMapError>; | 74 ) -> Result<bool, DirstateMapError>; |
75 | 75 |
76 fn read<'a>( | |
77 &mut self, | |
78 file_contents: &'a [u8], | |
79 ) -> Result<Option<&'a DirstateParents>, DirstateError>; | |
80 | |
81 fn pack( | 76 fn pack( |
82 &mut self, | 77 &mut self, |
83 parents: DirstateParents, | 78 parents: DirstateParents, |
84 now: Timestamp, | 79 now: Timestamp, |
85 ) -> Result<Vec<u8>, DirstateError>; | 80 ) -> Result<Vec<u8>, DirstateError>; |
212 fn has_dir( | 207 fn has_dir( |
213 &mut self, | 208 &mut self, |
214 directory: &HgPath, | 209 directory: &HgPath, |
215 ) -> Result<bool, DirstateMapError> { | 210 ) -> Result<bool, DirstateMapError> { |
216 self.has_dir(directory) | 211 self.has_dir(directory) |
217 } | |
218 | |
219 fn read<'a>( | |
220 &mut self, | |
221 file_contents: &'a [u8], | |
222 ) -> Result<Option<&'a DirstateParents>, DirstateError> { | |
223 self.read(file_contents) | |
224 } | 212 } |
225 | 213 |
226 fn pack( | 214 fn pack( |
227 &mut self, | 215 &mut self, |
228 parents: DirstateParents, | 216 parents: DirstateParents, |