changeset 48872:cc92ad0e8185 stable

rhg: correctly handle the case where diffs are encoded relative to nullrev returning a valid entry for nullrev fix chain that delta against nullrev.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Sun, 22 May 2022 14:21:59 +0200
parents 2dd53a33aefa
children c95e5ba4de1e
files rust/hg-core/src/revlog/revlog.rs tests/test-revlog.t
diffstat 2 files changed, 20 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/revlog.rs	Sun May 22 23:26:06 2022 +0200
+++ b/rust/hg-core/src/revlog/revlog.rs	Sun May 22 14:21:59 2022 +0200
@@ -32,6 +32,8 @@
     | REVISION_FLAG_EXTSTORED
     | REVISION_FLAG_HASCOPIESINFO;
 
+const NULL_REVLOG_ENTRY_FLAGS: u16 = 0;
+
 #[derive(derive_more::From)]
 pub enum RevlogError {
     InvalidRevision,
@@ -262,11 +264,29 @@
         }
     }
 
+    pub fn make_null_entry(&self) -> RevlogEntry {
+        RevlogEntry {
+            revlog: self,
+            rev: NULL_REVISION,
+            bytes: b"",
+            compressed_len: 0,
+            uncompressed_len: 0,
+            base_rev_or_base_of_delta_chain: None,
+            p1: NULL_REVISION,
+            p2: NULL_REVISION,
+            flags: NULL_REVLOG_ENTRY_FLAGS,
+            hash: NULL_NODE,
+        }
+    }
+
     /// Get an entry of the revlog.
     pub fn get_entry(
         &self,
         rev: Revision,
     ) -> Result<RevlogEntry, RevlogError> {
+        if rev == NULL_REVISION {
+            return Ok(self.make_null_entry());
+        }
         let index_entry = self
             .index
             .get_entry(rev)
--- a/tests/test-revlog.t	Sun May 22 23:26:06 2022 +0200
+++ b/tests/test-revlog.t	Sun May 22 14:21:59 2022 +0200
@@ -78,12 +78,6 @@
   $ hg debugdeltachain a
       rev  chain# chainlen     prev   delta       size    rawsize  chainsize     ratio   lindist extradist extraratio   readsize largestblk rddensity srchunks
         0       1        2       -1      p1         15          3         15   5.00000        15         0    0.00000         15         15   1.00000        1
-#if rhg
-  $ hg cat --config rhg.cat=true -r 0 a
-  abort: corrupted revlog
-  [255]
-#else
   $ hg cat --config rhg.cat=true -r 0 a
   hi
-#endif
   $ cd ..