comparison rust/hg-cpython/src/revlog.rs @ 44508:b581231ae9d1

rust-nodemap: add binding for `nodemap_data_all` Differential Revision: https://phab.mercurial-scm.org/D8158
author Georges Racinet <georges.racinet@octobus.net>
date Wed, 12 Feb 2020 10:51:17 +0100
parents 857cc79247ac
children 5bbf887275b0
comparison
equal deleted inserted replaced
44507:857cc79247ac 44508:b581231ae9d1
258 .extract(py) 258 .extract(py)
259 } 259 }
260 } 260 }
261 } 261 }
262 262
263 def nodemap_data_all(&self) -> PyResult<PyBytes> {
264 self.inner_nodemap_data_all(py)
265 }
266
263 267
264 }); 268 });
265 269
266 impl MixedIndex { 270 impl MixedIndex {
267 fn new(py: Python, cindex: PyObject) -> PyResult<MixedIndex> { 271 fn new(py: Python, cindex: PyObject) -> PyResult<MixedIndex> {
318 } 322 }
319 323
320 pub fn clone_cindex(&self, py: Python) -> cindex::Index { 324 pub fn clone_cindex(&self, py: Python) -> cindex::Index {
321 self.cindex(py).borrow().clone_ref(py) 325 self.cindex(py).borrow().clone_ref(py)
322 } 326 }
327
328 /// Returns the full nodemap bytes to be written as-is to disk
329 fn inner_nodemap_data_all(&self, py: Python) -> PyResult<PyBytes> {
330 let nodemap = self.get_nodetree(py)?.borrow_mut().take().unwrap();
331 let (readonly, bytes) = nodemap.into_readonly_and_added_bytes();
332
333 // If there's anything readonly, we need to build the data again from
334 // scratch
335 let bytes = if readonly.len() > 0 {
336 let mut nt = NodeTree::load_bytes(Box::new(vec![]), 0);
337 self.fill_nodemap(py, &mut nt)?;
338
339 let (readonly, bytes) = nt.into_readonly_and_added_bytes();
340 assert_eq!(readonly.len(), 0);
341
342 bytes
343 } else {
344 bytes
345 };
346
347 let bytes = PyBytes::new(py, &bytes);
348 Ok(bytes)
349 }
323 } 350 }
324 351
325 fn revlog_error(py: Python) -> PyErr { 352 fn revlog_error(py: Python) -> PyErr {
326 match py 353 match py
327 .import("mercurial.error") 354 .import("mercurial.error")