comparison rust/hg-cpython/src/revlog.rs @ 51213:62e39bef36ca

rust-index: add support for delta-chain computation
author Raphaël Gomès <rgomes@octobus.net>
date Thu, 03 Aug 2023 15:50:14 +0200
parents 9b06e7f32bc5
children 050098d60c30
comparison
equal deleted inserted replaced
51212:9b06e7f32bc5 51213:62e39bef36ca
308 Ok(py.None()) 308 Ok(py.None())
309 } 309 }
310 310
311 /// determine revisions with deltas to reconstruct fulltext 311 /// determine revisions with deltas to reconstruct fulltext
312 def deltachain(&self, *args, **kw) -> PyResult<PyObject> { 312 def deltachain(&self, *args, **kw) -> PyResult<PyObject> {
313 self.call_cindex(py, "deltachain", args, kw) 313 let index = self.index(py).borrow();
314 let rev = args.get_item(py, 0).extract::<BaseRevision>(py)?.into();
315 let stop_rev =
316 args.get_item(py, 1).extract::<Option<BaseRevision>>(py)?;
317 let rev = index.check_revision(rev).ok_or_else(|| {
318 nodemap_error(py, NodeMapError::RevisionNotInIndex(rev))
319 })?;
320 let stop_rev = if let Some(stop_rev) = stop_rev {
321 let stop_rev = UncheckedRevision(stop_rev);
322 Some(index.check_revision(stop_rev).ok_or_else(|| {
323 nodemap_error(py, NodeMapError::RevisionNotInIndex(stop_rev))
324 })?)
325 } else {None};
326 let (chain, stopped) = index.delta_chain(rev, stop_rev).map_err(|e| {
327 PyErr::new::<cpython::exc::ValueError, _>(py, e.to_string())
328 })?;
329
330 let cresult = self.call_cindex(py, "deltachain", args, kw)?;
331 let cchain: Vec<BaseRevision> =
332 cresult.get_item(py, 0)?.extract::<Vec<BaseRevision>>(py)?;
333 let chain: Vec<_> = chain.into_iter().map(|r| r.0).collect();
334 assert_eq!(chain, cchain);
335 assert_eq!(stopped, cresult.get_item(py, 1)?.extract(py)?);
336
337 Ok(
338 PyTuple::new(
339 py,
340 &[
341 chain.into_py_object(py).into_object(),
342 stopped.into_py_object(py).into_object()
343 ]
344 ).into_object()
345 )
346
314 } 347 }
315 348
316 /// slice planned chunk read to reach a density threshold 349 /// slice planned chunk read to reach a density threshold
317 def slicechunktodensity(&self, *args, **kw) -> PyResult<PyObject> { 350 def slicechunktodensity(&self, *args, **kw) -> PyResult<PyObject> {
318 self.call_cindex(py, "slicechunktodensity", args, kw) 351 self.call_cindex(py, "slicechunktodensity", args, kw)