# HG changeset patch # User Georges Racinet # Date 2023-07-06 09:53:40 # Node ID 124c44b5cfad1dbfff6f078d5b61bdc6903a1a30 # Parent 3338c6ffdaa3ae25470bd9923f6bdccf0f3b6327 rust-revlog: fix RevlogEntry.data() for NULL_REVISION Before this change, the pseudo-entry returned by `Revlog.get_entry` for `NULL_REVISION` would trigger errors in application code using it. For example, this fixes a crash spotted with changelog data while implementing RHGitaly: `Changelog.data_for_rev(-1)` was already returning the pseudo content as expected, e.g., for `hg log`, but `Changelog.entry_for_rev(-1).data()` would still crash with "corrupted revlog, hash check failed for revision -1". There is an added test for this scenario. diff --git a/rust/hg-core/src/revlog/changelog.rs b/rust/hg-core/src/revlog/changelog.rs --- a/rust/hg-core/src/revlog/changelog.rs +++ b/rust/hg-core/src/revlog/changelog.rs @@ -336,6 +336,11 @@ message", changelog.data_for_rev(NULL_REVISION)?, ChangelogRevisionData::null() ); + // same with the intermediate entry object + assert_eq!( + changelog.entry_for_rev(NULL_REVISION)?.data()?, + ChangelogRevisionData::null() + ); Ok(()) } } diff --git a/rust/hg-core/src/revlog/mod.rs b/rust/hg-core/src/revlog/mod.rs --- a/rust/hg-core/src/revlog/mod.rs +++ b/rust/hg-core/src/revlog/mod.rs @@ -562,6 +562,9 @@ impl<'revlog> RevlogEntry<'revlog> { pub fn data(&self) -> Result, HgError> { let data = self.rawdata()?; + if self.rev == NULL_REVISION { + return Ok(data); + } if self.is_censored() { return Err(HgError::CensoredNodeError); } @@ -688,6 +691,9 @@ mod tests { revlog.rev_from_node(NULL_NODE.into()).unwrap(), NULL_REVISION ); + let null_entry = revlog.get_entry(NULL_REVISION).ok().unwrap(); + assert_eq!(null_entry.revision(), NULL_REVISION); + assert!(null_entry.data().unwrap().is_empty()); } #[test]