changeset 52771:2fb13c3f4496

rust: add GraphError::ParentOutOfOrder This will be used in a follow-up commit that creates a data structure optimized for inserting revisions in descending order, since it will need to fail if a revision number is greater than its descendant (meaning the graph is corrupted).
author Mitchell Kember <mkember@janestreet.com>
date Fri, 07 Feb 2025 16:07:35 -0500
parents 7b4548a075ab
children e9ced84aeef4
files rust/hg-core/src/revlog/mod.rs rust/hg-cpython/src/cindex.rs rust/hg-cpython/src/exceptions.rs rust/hg-cpython/src/revlog.rs rust/hg-pyo3/src/exceptions.rs
diffstat 5 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/mod.rs	Fri Feb 07 16:03:35 2025 -0500
+++ b/rust/hg-core/src/revlog/mod.rs	Fri Feb 07 16:07:35 2025 -0500
@@ -136,7 +136,10 @@
 
 #[derive(Clone, Debug, PartialEq)]
 pub enum GraphError {
+    /// Parent revision does not exist, i.e. below 0 or above max revision.
     ParentOutOfRange(Revision),
+    /// Parent revision number is greater than one of its descendants.
+    ParentOutOfOrder(Revision),
 }
 
 impl std::fmt::Display for GraphError {
@@ -145,6 +148,9 @@
             GraphError::ParentOutOfRange(revision) => {
                 write!(f, "parent out of range ({})", revision)
             }
+            GraphError::ParentOutOfOrder(revision) => {
+                write!(f, "parent out of order ({})", revision)
+            }
         }
     }
 }
--- a/rust/hg-cpython/src/cindex.rs	Fri Feb 07 16:03:35 2025 -0500
+++ b/rust/hg-cpython/src/cindex.rs	Fri Feb 07 16:07:35 2025 -0500
@@ -171,6 +171,9 @@
             Err(GraphError::ParentOutOfRange(rev)) => {
                 Err(vcsgraph::graph::GraphReadError::KeyedInvalidKey(rev.0))
             }
+            Err(GraphError::ParentOutOfOrder(_)) => {
+                Err(vcsgraph::graph::GraphReadError::InconsistentGraphData)
+            }
         }
     }
 }
--- a/rust/hg-cpython/src/exceptions.rs	Fri Feb 07 16:03:35 2025 -0500
+++ b/rust/hg-cpython/src/exceptions.rs	Fri Feb 07 16:07:35 2025 -0500
@@ -28,6 +28,9 @@
             hg::GraphError::ParentOutOfRange(r) => {
                 GraphError::new(py, ("ParentOutOfRange", PyRevision(r.0)))
             }
+            hg::GraphError::ParentOutOfOrder(r) => {
+                GraphError::new(py, ("ParentOutOfOrder", PyRevision(r.0)))
+            }
         }
     }
 
--- a/rust/hg-cpython/src/revlog.rs	Fri Feb 07 16:03:35 2025 -0500
+++ b/rust/hg-cpython/src/revlog.rs	Fri Feb 07 16:07:35 2025 -0500
@@ -95,6 +95,9 @@
             Err(hg::GraphError::ParentOutOfRange(rev)) => {
                 Err(vcsgraph::graph::GraphReadError::KeyedInvalidKey(rev.0))
             }
+            Err(hg::GraphError::ParentOutOfOrder(_)) => {
+                Err(vcsgraph::graph::GraphReadError::InconsistentGraphData)
+            }
         }
     }
 }
--- a/rust/hg-pyo3/src/exceptions.rs	Fri Feb 07 16:03:35 2025 -0500
+++ b/rust/hg-pyo3/src/exceptions.rs	Fri Feb 07 16:07:35 2025 -0500
@@ -13,6 +13,9 @@
             hg::GraphError::ParentOutOfRange(r) => {
                 GraphError::new_err(("ParentOutOfRange", PyRevision(r.0)))
             }
+            hg::GraphError::ParentOutOfOrder(r) => {
+                GraphError::new_err(("ParentOutOfOrder", PyRevision(r.0)))
+            }
         }
     }
     pub fn from_vcsgraph(inner: vcsgraph::graph::GraphReadError) -> PyErr {