# HG changeset patch # User Raphaël Gomès # Date 2023-10-31 16:58:56 # Node ID eb676c35a29b2954b2a1bc37e1055d2081561a22 # Parent 456e0fe702e86d6adc3a90bee4785a3718c9ca48 rust-index: support `unionrepo`'s compressed length hack Explanations inline. diff --git a/rust/hg-core/src/revlog/index.rs b/rust/hg-core/src/revlog/index.rs --- a/rust/hg-core/src/revlog/index.rs +++ b/rust/hg-core/src/revlog/index.rs @@ -479,7 +479,18 @@ impl Index { } else { e.raw_offset() }, - data_compressed_length: e.compressed_len().try_into().unwrap(), + data_compressed_length: e + .compressed_len() + .try_into() + .unwrap_or_else(|_| { + // Python's `unionrepo` sets the compressed length to be + // `-1` (or `u32::MAX` if transmuted to `u32`) because it + // cannot know the correct compressed length of a given + // revision. I'm not sure if this is true, but having this + // edge case won't hurt other use cases, let's handle it. + assert_eq!(e.compressed_len(), u32::MAX); + NULL_REVISION.0 + }), data_uncompressed_length: e.uncompressed_len(), data_delta_base: e.base_revision_or_base_of_delta_chain().0, link_rev: e.link_revision().0,