rust/hg-cpython/src/copy_tracing.rs
changeset 46569 34827c95092c
parent 46149 294d5aca4ff5
child 46587 cb4b0b0c6de4
equal deleted inserted replaced
46568:0d840b9d200d 46569:34827c95092c
     1 use cpython::ObjectProtocol;
     1 use cpython::ObjectProtocol;
     2 use cpython::PyBool;
       
     3 use cpython::PyBytes;
     2 use cpython::PyBytes;
     4 use cpython::PyDict;
     3 use cpython::PyDict;
     5 use cpython::PyList;
     4 use cpython::PyList;
     6 use cpython::PyModule;
     5 use cpython::PyModule;
     7 use cpython::PyObject;
     6 use cpython::PyObject;
    24     py: Python,
    23     py: Python,
    25     revs: PyList,
    24     revs: PyList,
    26     children_count: PyDict,
    25     children_count: PyDict,
    27     target_rev: Revision,
    26     target_rev: Revision,
    28     rev_info: PyObject,
    27     rev_info: PyObject,
    29     is_ancestor: PyObject,
       
    30 ) -> PyResult<PyDict> {
    28 ) -> PyResult<PyDict> {
    31     let revs: PyResult<_> =
    29     let revs: PyResult<_> =
    32         revs.iter(py).map(|r| Ok(r.extract(py)?)).collect();
    30         revs.iter(py).map(|r| Ok(r.extract(py)?)).collect();
    33 
       
    34     // Wrap the `is_ancestor` python callback as a Rust closure
       
    35     //
       
    36     // No errors are expected from the Python side, and they will should only
       
    37     // happens in case of programing error or severe data corruption. Such
       
    38     // errors will raise panic and the rust-cpython harness will turn them into
       
    39     // Python exception.
       
    40     let is_ancestor_wrap = |anc: Revision, desc: Revision| -> bool {
       
    41         is_ancestor
       
    42             .call(py, (anc, desc), None)
       
    43             .expect(
       
    44                 "rust-copy-tracing: python call  to `is_ancestor` \
       
    45                 failed",
       
    46             )
       
    47             .cast_into::<PyBool>(py)
       
    48             .expect(
       
    49                 "rust-copy-tracing: python call  to `is_ancestor` \
       
    50                 returned unexpected non-Bool value",
       
    51             )
       
    52             .is_true()
       
    53     };
       
    54 
    31 
    55     // Wrap the `rev_info_maker` python callback as a Rust closure
    32     // Wrap the `rev_info_maker` python callback as a Rust closure
    56     //
    33     //
    57     // No errors are expected from the Python side, and they will should only
    34     // No errors are expected from the Python side, and they will should only
    58     // happens in case of programing error or severe data corruption. Such
    35     // happens in case of programing error or severe data corruption. Such
   102     let res = combine_changeset_copies(
    79     let res = combine_changeset_copies(
   103         revs?,
    80         revs?,
   104         children_count?,
    81         children_count?,
   105         target_rev,
    82         target_rev,
   106         rev_info_maker,
    83         rev_info_maker,
   107         &is_ancestor_wrap,
       
   108     );
    84     );
   109     let out = PyDict::new(py);
    85     let out = PyDict::new(py);
   110     for (dest, source) in res.into_iter() {
    86     for (dest, source) in res.into_iter() {
   111         out.set_item(
    87         out.set_item(
   112             py,
    88             py,
   132             py,
   108             py,
   133             combine_changeset_copies_wrapper(
   109             combine_changeset_copies_wrapper(
   134                 revs: PyList,
   110                 revs: PyList,
   135                 children: PyDict,
   111                 children: PyDict,
   136                 target_rev: Revision,
   112                 target_rev: Revision,
   137                 rev_info: PyObject,
   113                 rev_info: PyObject
   138                 is_ancestor: PyObject
       
   139             )
   114             )
   140         ),
   115         ),
   141     )?;
   116     )?;
   142 
   117 
   143     let sys = PyModule::import(py, "sys")?;
   118     let sys = PyModule::import(py, "sys")?;