changeset 51230:e9d47e2f5dcf

rust-index: add missing special case for null rev This was an oversight, it was never a problem because we didn't use the index much for user-facing things in the past, which is the only real way of getting to this edge case.
author Raphaël Gomès <rgomes@octobus.net>
date Thu, 03 Aug 2023 14:50:17 +0200
parents 274abd1562a2
children 72d16685d63a
files rust/hg-core/src/revlog/index.rs
diffstat 1 files changed, 4 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/index.rs	Wed Aug 02 16:49:17 2023 +0200
+++ b/rust/hg-core/src/revlog/index.rs	Thu Aug 03 14:50:17 2023 +0200
@@ -7,7 +7,7 @@
 
 use super::REVIDX_KNOWN_FLAGS;
 use crate::errors::HgError;
-use crate::node::{NODE_BYTES_LENGTH, STORED_NODE_ID_BYTES};
+use crate::node::{NODE_BYTES_LENGTH, NULL_NODE, STORED_NODE_ID_BYTES};
 use crate::revlog::node::Node;
 use crate::revlog::{Revision, NULL_REVISION};
 use crate::{Graph, GraphError, RevlogError, RevlogIndex, UncheckedRevision};
@@ -537,6 +537,9 @@
     }
 
     fn node(&self, rev: Revision) -> Option<&Node> {
+        if rev == NULL_REVISION {
+            return Some(&NULL_NODE);
+        }
         self.get_entry(rev).map(|entry| entry.hash())
     }
 }