rust: error for WdirUnsupported with cpython conversion as exception

This introduces WorkingDirectoryUnsupported as an enum variant
of GraphError in the core and converts it to the expected
`mercurial.error.WdirUnsupported`.
2 files changed, 12 insertions(+), 0 deletions(-)

M rust/hg-core/src/lib.rs
M rust/hg-cpython/src/exceptions.rs
M rust/hg-core/src/lib.rs +1 -0
@@ 33,4 33,5 @@ pub trait Graph {
 #[derive(Clone, Debug, PartialEq)]
 pub enum GraphError {
     ParentOutOfRange(Revision),
+    WorkingDirectoryUnsupported,
 }

          
M rust/hg-cpython/src/exceptions.rs +11 -0
@@ 8,6 8,8 @@ 
 //! Bindings for Rust errors
 //!
 //! [`GraphError`] exposes `hg::GraphError` as a subclass of `ValueError`
+//! but some variants of `hg::GraphError` can be converted directly to other
+//! existing Python exceptions if appropriate.
 //!
 //! [`GraphError`]: struct.GraphError.html
 use cpython::exc::ValueError;

          
@@ 22,6 24,15 @@ impl GraphError {
             hg::GraphError::ParentOutOfRange(r) => {
                 GraphError::new(py, ("ParentOutOfRange", r))
             }
+            hg::GraphError::WorkingDirectoryUnsupported => {
+                match py
+                    .import("mercurial.error")
+                    .and_then(|m| m.get(py, "WdirUnsupported"))
+                {
+                    Err(e) => e,
+                    Ok(cls) => PyErr::from_instance(py, cls),
+                }
+            }
         }
     }
 }