comparison rust/hg-cpython/src/cindex.rs @ 41350:ab0d762d89ef stable

rust-cpython: raising error.WdirUnsupported The Graph implementation of hg-cpython returns the appropriate error upon encounter with the working directory special revision number, and this gives us in particular a code path to test from test-rust-ancestors.py In the current implementation, the exception is actually raised from the iterator instantiation; we are nonetheless consuming the iterator in the test with `list()` in order not to depend on implementation details.
author Georges Racinet <georges.racinet@octobus.net>
date Wed, 23 Jan 2019 07:49:36 -0500
parents ef54bd33b476
children 326fdce22fb2
comparison
equal deleted inserted replaced
41349:ee943a920606 41350:ab0d762d89ef
14 #[cfg(feature = "python3")] 14 #[cfg(feature = "python3")]
15 extern crate python3_sys as python_sys; 15 extern crate python3_sys as python_sys;
16 16
17 use self::python_sys::PyCapsule_Import; 17 use self::python_sys::PyCapsule_Import;
18 use cpython::{PyClone, PyErr, PyObject, PyResult, Python}; 18 use cpython::{PyClone, PyErr, PyObject, PyResult, Python};
19 use hg::{Graph, GraphError, Revision}; 19 use hg::{Graph, GraphError, Revision, WORKING_DIRECTORY_REVISION};
20 use libc::c_int; 20 use libc::c_int;
21 use std::ffi::CStr; 21 use std::ffi::CStr;
22 use std::mem::transmute; 22 use std::mem::transmute;
23 23
24 type IndexParentsFn = unsafe extern "C" fn( 24 type IndexParentsFn = unsafe extern "C" fn(
84 } 84 }
85 85
86 impl Graph for Index { 86 impl Graph for Index {
87 /// wrap a call to the C extern parents function 87 /// wrap a call to the C extern parents function
88 fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> { 88 fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> {
89 if rev == WORKING_DIRECTORY_REVISION {
90 return Err(GraphError::WorkingDirectoryUnsupported);
91 }
89 let mut res: [c_int; 2] = [0; 2]; 92 let mut res: [c_int; 2] = [0; 2];
90 let code = unsafe { 93 let code = unsafe {
91 (self.parents)( 94 (self.parents)(
92 self.index.as_ptr(), 95 self.index.as_ptr(),
93 rev as c_int, 96 rev as c_int,