Mercurial > public > mercurial-scm > hg-stable
diff rust/hg-core/src/revlog/mod.rs @ 52775:8497cfb0d76c
rust-manifest: add Manifestlog::inexact_data_delta_parents
This is similar to manifestctx.read_delta_parents(exact=False) in manifest.py.
It is useful to determine if a file was added in a changeset without
delta-resolving the entire manifest. I will use it for rhg annotate.
author | Mitchell Kember <mkember@janestreet.com> |
---|---|
date | Tue, 14 Jan 2025 17:44:02 -0500 |
parents | df7fb698f7a8 |
children | 169ccd142ef8 |
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/mod.rs Thu Jan 16 13:15:02 2025 -0500 +++ b/rust/hg-core/src/revlog/mod.rs Tue Jan 14 17:44:02 2025 -0500 @@ -439,6 +439,26 @@ self.get_entry(rev)?.data() } + /// Gets the raw uncompressed data stored for a revision, which is either + /// the full text or a delta. Panics if `rev` is null. + pub fn get_data_incr( + &self, + rev: Revision, + ) -> Result<RawdataBuf, RevlogError> { + let index = self.index(); + let entry = index.get_entry(rev).expect("rev should not be null"); + let delta_base = entry.base_revision_or_base_of_delta_chain(); + let base = if UncheckedRevision::from(rev) == delta_base { + None + } else if index.uses_generaldelta() { + Some(delta_base) + } else { + Some(UncheckedRevision(rev.0 - 1)) + }; + let data = self.inner.chunk_for_rev(rev)?; + Ok(RawdataBuf { base, data }) + } + /// Check the hash of some given data against the recorded hash. pub fn check_hash( &self, @@ -471,6 +491,21 @@ } } +pub struct RawdataBuf { + // If `Some`, data is a delta. + base: Option<UncheckedRevision>, + data: std::sync::Arc<[u8]>, +} + +impl RawdataBuf { + fn as_patch_list(&self) -> Result<patch::PatchList, RevlogError> { + match self.base { + None => Ok(patch::PatchList::full_snapshot(&self.data)), + Some(_) => patch::PatchList::new(&self.data), + } + } +} + type IndexData = Box<dyn Deref<Target = [u8]> + Send + Sync>; /// TODO We should check for version 5.14+ at runtime, but we either should