changeset 48518:8e8737a1fa7d

hg-cpython: implement vcsgraph::Graph for our Index Differential Revision: https://phab.mercurial-scm.org/D11946
author pacien <pacien.trangirard@pacien.net>
date Fri, 10 Dec 2021 15:27:22 +0100
parents 99a0b5422cf5
children 35ebe6f824be
files rust/hg-cpython/src/cindex.rs
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-cpython/src/cindex.rs	Fri Dec 10 15:22:24 2021 +0100
+++ b/rust/hg-cpython/src/cindex.rs	Fri Dec 10 15:27:22 2021 +0100
@@ -155,6 +155,24 @@
     }
 }
 
+impl vcsgraph::graph::Graph for Index {
+    fn parents(
+        &self,
+        rev: Revision,
+    ) -> Result<vcsgraph::graph::Parents, vcsgraph::graph::GraphReadError>
+    {
+        match Graph::parents(self, rev) {
+            Ok(parents) => Ok(vcsgraph::graph::Parents(parents)),
+            Err(GraphError::ParentOutOfRange(rev)) => {
+                Err(vcsgraph::graph::GraphReadError::KeyedInvalidKey(rev))
+            }
+            Err(GraphError::WorkingDirectoryUnsupported) => Err(
+                vcsgraph::graph::GraphReadError::WorkingDirectoryUnsupported,
+            ),
+        }
+    }
+}
+
 impl RevlogIndex for Index {
     /// Note C return type is Py_ssize_t (hence signed), but we shall
     /// force it to unsigned, because it's a length