changeset 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 ee943a920606
children 0ae3ddb4fbed 261d37b94d31
files mercurial/revlog.py rust/hg-cpython/src/cindex.rs tests/test-rust-ancestor.py
diffstat 3 files changed, 15 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlog.py	Wed Jan 23 07:47:04 2019 -0500
+++ b/mercurial/revlog.py	Wed Jan 23 07:49:36 2019 -0500
@@ -901,8 +901,6 @@
             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)
 
--- a/rust/hg-cpython/src/cindex.rs	Wed Jan 23 07:47:04 2019 -0500
+++ b/rust/hg-cpython/src/cindex.rs	Wed Jan 23 07:49:36 2019 -0500
@@ -16,7 +16,7 @@
 
 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 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)(
--- a/tests/test-rust-ancestor.py	Wed Jan 23 07:47:04 2019 -0500
+++ b/tests/test-rust-ancestor.py	Wed Jan 23 07:49:36 2019 -0500
@@ -2,6 +2,11 @@
 import sys
 import unittest
 
+from mercurial import (
+    error,
+    node,
+)
+
 try:
     from mercurial import rustext
     rustext.__name__  # trigger immediate actual import
@@ -153,6 +158,12 @@
         # 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