Mercurial > hg
comparison rust/hg-core/src/revlog/mod.rs @ 50746:124c44b5cfad stable
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.
author | Georges Racinet <georges.racinet@octobus.net> |
---|---|
date | Thu, 06 Jul 2023 11:53:40 +0200 |
parents | 3338c6ffdaa3 |
children | c950fdba7472 363620b934aa |
comparison
equal
deleted
inserted
replaced
50745:3338c6ffdaa3 | 50746:124c44b5cfad |
---|---|
560 } | 560 } |
561 } | 561 } |
562 | 562 |
563 pub fn data(&self) -> Result<Cow<'revlog, [u8]>, HgError> { | 563 pub fn data(&self) -> Result<Cow<'revlog, [u8]>, HgError> { |
564 let data = self.rawdata()?; | 564 let data = self.rawdata()?; |
565 if self.rev == NULL_REVISION { | |
566 return Ok(data); | |
567 } | |
565 if self.is_censored() { | 568 if self.is_censored() { |
566 return Err(HgError::CensoredNodeError); | 569 return Err(HgError::CensoredNodeError); |
567 } | 570 } |
568 self.check_data(data) | 571 self.check_data(data) |
569 } | 572 } |
686 assert!(!revlog.has_rev(0)); | 689 assert!(!revlog.has_rev(0)); |
687 assert_eq!( | 690 assert_eq!( |
688 revlog.rev_from_node(NULL_NODE.into()).unwrap(), | 691 revlog.rev_from_node(NULL_NODE.into()).unwrap(), |
689 NULL_REVISION | 692 NULL_REVISION |
690 ); | 693 ); |
694 let null_entry = revlog.get_entry(NULL_REVISION).ok().unwrap(); | |
695 assert_eq!(null_entry.revision(), NULL_REVISION); | |
696 assert!(null_entry.data().unwrap().is_empty()); | |
691 } | 697 } |
692 | 698 |
693 #[test] | 699 #[test] |
694 fn test_inline() { | 700 fn test_inline() { |
695 let temp = tempfile::tempdir().unwrap(); | 701 let temp = tempfile::tempdir().unwrap(); |