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.
3 files changed, 15 insertions(+), 3 deletions(-)

M mercurial/revlog.py
M rust/hg-cpython/src/cindex.rs
M tests/test-rust-ancestor.py
M mercurial/revlog.py +0 -2
@@ 901,8 901,6 @@ class revlog(object):
             common = [nullrev]
 
         if rustext is not None:
-            # TODO: WdirUnsupported should be raised instead of GraphError
-            # if common includes wdirrev
             return rustext.ancestor.MissingAncestors(self.index, common)
         return ancestor.incrementalmissingancestors(self.parentrevs, common)
 

          
M rust/hg-cpython/src/cindex.rs +4 -1
@@ 16,7 16,7 @@ extern crate python3_sys as python_sys;
 
 use self::python_sys::PyCapsule_Import;
 use cpython::{PyClone, PyErr, PyObject, PyResult, Python};
-use hg::{Graph, GraphError, Revision};
+use hg::{Graph, GraphError, Revision, WORKING_DIRECTORY_REVISION};
 use libc::c_int;
 use std::ffi::CStr;
 use std::mem::transmute;

          
@@ 86,6 86,9 @@ impl Clone for Index {
 impl Graph for Index {
     /// wrap a call to the C extern parents function
     fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> {
+        if rev == WORKING_DIRECTORY_REVISION {
+            return Err(GraphError::WorkingDirectoryUnsupported);
+        }
         let mut res: [c_int; 2] = [0; 2];
         let code = unsafe {
             (self.parents)(

          
M tests/test-rust-ancestor.py +11 -0
@@ 2,6 2,11 @@ from __future__ import absolute_import
 import sys
 import unittest
 
+from mercurial import (
+    error,
+    node,
+)
+
 try:
     from mercurial import rustext
     rustext.__name__  # trigger immediate actual import

          
@@ 153,6 158,12 @@ class rustancestorstest(unittest.TestCas
         # rust-cpython issues appropriate str instances for Python 2 and 3
         self.assertEqual(exc.args, ('ParentOutOfRange', 1))
 
+    def testwdirunsupported(self):
+        # trying to access ancestors of the working directory raises
+        # WdirUnsupported directly
+        idx = self.parseindex()
+        with self.assertRaises(error.WdirUnsupported):
+            list(AncestorsIterator(idx, [node.wdirrev], -1, False))
 
 if __name__ == '__main__':
     import silenttestrunner