diff --git a/mercurial/revlog.py b/mercurial/revlog.py --- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -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) diff --git a/rust/hg-cpython/src/cindex.rs b/rust/hg-cpython/src/cindex.rs --- a/rust/hg-cpython/src/cindex.rs +++ b/rust/hg-cpython/src/cindex.rs @@ -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)( diff --git a/tests/test-rust-ancestor.py b/tests/test-rust-ancestor.py --- a/tests/test-rust-ancestor.py +++ b/tests/test-rust-ancestor.py @@ -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