rust/hg-cpython/src/revlog.rs
changeset 51213 65c9032e2e5a
parent 51212 13f58ce70299
child 51214 e79b0a4be3a7
equal deleted inserted replaced
51212:13f58ce70299 51213:65c9032e2e5a
    16     ObjectProtocol, PyBytes, PyClone, PyDict, PyErr, PyInt, PyModule,
    16     ObjectProtocol, PyBytes, PyClone, PyDict, PyErr, PyInt, PyModule,
    17     PyObject, PyResult, PyString, PyTuple, Python, PythonObject, ToPyObject,
    17     PyObject, PyResult, PyString, PyTuple, Python, PythonObject, ToPyObject,
    18 };
    18 };
    19 use hg::{
    19 use hg::{
    20     index::IndexHeader,
    20     index::IndexHeader,
       
    21     index::{RevisionDataParams, COMPRESSION_MODE_INLINE},
    21     nodemap::{Block, NodeMapError, NodeTree},
    22     nodemap::{Block, NodeMapError, NodeTree},
    22     revlog::{nodemap::NodeMap, NodePrefix, RevlogIndex},
    23     revlog::{nodemap::NodeMap, NodePrefix, RevlogIndex},
    23     BaseRevision, Revision, UncheckedRevision,
    24     BaseRevision, Revision, UncheckedRevision,
    24 };
    25 };
    25 use std::cell::RefCell;
    26 use std::cell::RefCell;
   143 
   144 
   144         let mut idx = self.cindex(py).borrow_mut();
   145         let mut idx = self.cindex(py).borrow_mut();
   145 
   146 
   146         // This is ok since we will just add the revision to the index
   147         // This is ok since we will just add the revision to the index
   147         let rev = Revision(idx.len() as BaseRevision);
   148         let rev = Revision(idx.len() as BaseRevision);
   148         idx.append(py, tup)?;
   149         idx.append(py, tup.clone_ref(py))?;
   149 
   150         self.index(py)
       
   151             .borrow_mut()
       
   152             .append(py_tuple_to_revision_data_params(py, tup)?)
       
   153             .unwrap();
   150         self.get_nodetree(py)?.borrow_mut().as_mut().unwrap()
   154         self.get_nodetree(py)?.borrow_mut().as_mut().unwrap()
   151             .insert(&*idx, &node, rev)
   155             .insert(&*idx, &node, rev)
   152             .map_err(|e| nodemap_error(py, e))?;
   156             .map_err(|e| nodemap_error(py, e))?;
   153         Ok(py.None())
   157         Ok(py.None())
   154     }
   158     }
   359     };
   363     };
   360 
   364 
   361     Ok((buf, Box::new(bytes)))
   365     Ok((buf, Box::new(bytes)))
   362 }
   366 }
   363 
   367 
       
   368 fn py_tuple_to_revision_data_params(
       
   369     py: Python,
       
   370     tuple: PyTuple,
       
   371 ) -> PyResult<RevisionDataParams> {
       
   372     if tuple.len(py) < 8 {
       
   373         // this is better than the panic promised by tup.get_item()
       
   374         return Err(PyErr::new::<IndexError, _>(
       
   375             py,
       
   376             "tuple index out of range",
       
   377         ));
       
   378     }
       
   379     let offset_or_flags: u64 = tuple.get_item(py, 0).extract(py)?;
       
   380     let node_id = tuple
       
   381         .get_item(py, 7)
       
   382         .extract::<PyBytes>(py)?
       
   383         .data(py)
       
   384         .try_into()
       
   385         .unwrap();
       
   386     let flags = (offset_or_flags & 0xFFFF) as u16;
       
   387     let data_offset = offset_or_flags >> 16;
       
   388     Ok(RevisionDataParams {
       
   389         flags,
       
   390         data_offset,
       
   391         data_compressed_length: tuple.get_item(py, 1).extract(py)?,
       
   392         data_uncompressed_length: tuple.get_item(py, 2).extract(py)?,
       
   393         data_delta_base: tuple.get_item(py, 3).extract(py)?,
       
   394         link_rev: tuple.get_item(py, 4).extract(py)?,
       
   395         parent_rev_1: tuple.get_item(py, 5).extract(py)?,
       
   396         parent_rev_2: tuple.get_item(py, 6).extract(py)?,
       
   397         node_id,
       
   398         _sidedata_offset: 0,
       
   399         _sidedata_compressed_length: 0,
       
   400         data_compression_mode: COMPRESSION_MODE_INLINE,
       
   401         _sidedata_compression_mode: COMPRESSION_MODE_INLINE,
       
   402         _rank: -1,
       
   403     })
       
   404 }
       
   405 
   364 impl MixedIndex {
   406 impl MixedIndex {
   365     fn new(
   407     fn new(
   366         py: Python,
   408         py: Python,
   367         cindex: PyObject,
   409         cindex: PyObject,
   368         data: PyObject,
   410         data: PyObject,