Mercurial > public > mercurial-scm > hg
comparison rust/hg-core/src/revlog/patch.rs @ 52761: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 | bd8081e9fd62 |
children |
comparison
equal
deleted
inserted
replaced
52760:94e2547e6f3d | 52761:8497cfb0d76c |
---|---|
10 /// - an insertion when `!data.is_empty() && start == end` | 10 /// - an insertion when `!data.is_empty() && start == end` |
11 /// - an deletion when `data.is_empty() && start < end` | 11 /// - an deletion when `data.is_empty() && start < end` |
12 /// - a replacement when `!data.is_empty() && start < end` | 12 /// - a replacement when `!data.is_empty() && start < end` |
13 /// - not doing anything when `data.is_empty() && start == end` | 13 /// - not doing anything when `data.is_empty() && start == end` |
14 #[derive(Debug, Clone)] | 14 #[derive(Debug, Clone)] |
15 struct Chunk<'a> { | 15 pub(crate) struct Chunk<'a> { |
16 /// The start position of the chunk of data to replace | 16 /// The start position of the chunk of data to replace |
17 start: u32, | 17 pub(crate) start: u32, |
18 /// The end position of the chunk of data to replace (open end interval) | 18 /// The end position of the chunk of data to replace (open end interval) |
19 end: u32, | 19 pub(crate) end: u32, |
20 /// The data replacing the chunk | 20 /// The data replacing the chunk |
21 data: &'a [u8], | 21 pub(crate) data: &'a [u8], |
22 } | 22 } |
23 | 23 |
24 impl Chunk<'_> { | 24 impl Chunk<'_> { |
25 /// Adjusted start of the chunk to replace. | 25 /// Adjusted start of the chunk to replace. |
26 /// | 26 /// |
58 /// | 58 /// |
59 /// Those chunks are: | 59 /// Those chunks are: |
60 /// - ordered from the left-most replacement to the right-most replacement | 60 /// - ordered from the left-most replacement to the right-most replacement |
61 /// - non-overlapping, meaning that two chucks can not change the same | 61 /// - non-overlapping, meaning that two chucks can not change the same |
62 /// chunk of the patched data | 62 /// chunk of the patched data |
63 chunks: Vec<Chunk<'a>>, | 63 pub(crate) chunks: Vec<Chunk<'a>>, |
64 } | 64 } |
65 | 65 |
66 impl<'a> PatchList<'a> { | 66 impl<'a> PatchList<'a> { |
67 /// Create a `PatchList` from bytes. | 67 /// Create a `PatchList` from bytes. |
68 pub fn new(data: &'a [u8]) -> Result<Self, RevlogError> { | 68 pub fn new(data: &'a [u8]) -> Result<Self, RevlogError> { |
81 data: &data[12..12 + (len as usize)], | 81 data: &data[12..12 + (len as usize)], |
82 }); | 82 }); |
83 data = &data[12 + (len as usize)..]; | 83 data = &data[12 + (len as usize)..]; |
84 } | 84 } |
85 Ok(PatchList { chunks }) | 85 Ok(PatchList { chunks }) |
86 } | |
87 | |
88 /// Creates a patch for a full snapshot, going from nothing to `data`. | |
89 pub fn full_snapshot(data: &'a [u8]) -> Self { | |
90 Self { | |
91 chunks: vec![Chunk { | |
92 start: 0, | |
93 end: 0, | |
94 data, | |
95 }], | |
96 } | |
86 } | 97 } |
87 | 98 |
88 /// Apply the patch to some data. | 99 /// Apply the patch to some data. |
89 pub fn apply<T>( | 100 pub fn apply<T>( |
90 &self, | 101 &self, |