Skip to content
Snippets Groups Projects
Commit 124c44b5 authored by Georges Racinet's avatar Georges Racinet
Browse files

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.
parent 3338c6ff
No related branches found
No related tags found
2 merge requests!634merge stable into default,!633rust-revlog: fixing issue with pseudo data for NULL_REVISION
...@@ -336,6 +336,11 @@ ...@@ -336,6 +336,11 @@
changelog.data_for_rev(NULL_REVISION)?, changelog.data_for_rev(NULL_REVISION)?,
ChangelogRevisionData::null() ChangelogRevisionData::null()
); );
// same with the intermediate entry object
assert_eq!(
changelog.entry_for_rev(NULL_REVISION)?.data()?,
ChangelogRevisionData::null()
);
Ok(()) Ok(())
} }
} }
...@@ -562,6 +562,9 @@ ...@@ -562,6 +562,9 @@
pub fn data(&self) -> Result<Cow<'revlog, [u8]>, HgError> { pub fn data(&self) -> Result<Cow<'revlog, [u8]>, HgError> {
let data = self.rawdata()?; let data = self.rawdata()?;
if self.rev == NULL_REVISION {
return Ok(data);
}
if self.is_censored() { if self.is_censored() {
return Err(HgError::CensoredNodeError); return Err(HgError::CensoredNodeError);
} }
...@@ -688,6 +691,9 @@ ...@@ -688,6 +691,9 @@
revlog.rev_from_node(NULL_NODE.into()).unwrap(), revlog.rev_from_node(NULL_NODE.into()).unwrap(),
NULL_REVISION 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] #[test]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment