Mercurial > public > mercurial-scm > hg-stable
annotate rust/hg-core/src/revlog/patch.rs @ 52290:e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
This mirrors the Python `InnerRevlog` and will be used in a future patch
to replace said Python implementation. This allows us to start doing more
things in pure Rust, in particular reading and writing operations.
A lot of changes have to be introduced all at once, it wouldn't be very
useful to separate this patch IMO since all of them are either interlocked
or only useful with the rest.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Thu, 10 Oct 2024 10:34:51 +0200 |
parents | b68b19104d16 |
children | bd8081e9fd62 |
rev | line source |
---|---|
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1 use byteorder::{BigEndian, ByteOrder}; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
2 |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
3 use crate::RevlogError; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
4 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
5 use super::inner_revlog::RevisionBuffer; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
6 |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
7 /// A chunk of data to insert, delete or replace in a patch |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
8 /// |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
9 /// A chunk is: |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
10 /// - an insertion when `!data.is_empty() && start == end` |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
11 /// - an deletion when `data.is_empty() && start < end` |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
12 /// - a replacement when `!data.is_empty() && start < end` |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
13 /// - not doing anything when `data.is_empty() && start == end` |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
14 #[derive(Debug, Clone)] |
45599
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
15 struct Chunk<'a> { |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
16 /// The start position of the chunk of data to replace |
45600
d07e4656ff5a
hg-core: use `u32` instead of `i32` in `Chunk` (D8958#inline-15001 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45599
diff
changeset
|
17 start: u32, |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
18 /// The end position of the chunk of data to replace (open end interval) |
45600
d07e4656ff5a
hg-core: use `u32` instead of `i32` in `Chunk` (D8958#inline-15001 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45599
diff
changeset
|
19 end: u32, |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
20 /// The data replacing the chunk |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
21 data: &'a [u8], |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
22 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
23 |
45601
412a5827ad02
hg-core: use anonymous lifetime for `impl Chunk` (D8958#inline-15003 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45600
diff
changeset
|
24 impl Chunk<'_> { |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
25 /// Adjusted start of the chunk to replace. |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
26 /// |
45602
cee7a8e37e9c
hg-core: minor rewording in docstring (D8958#inline-15005 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45601
diff
changeset
|
27 /// The offset, taking into account the growth/shrinkage of data |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
28 /// induced by previously applied chunks. |
45603
b68b19104d16
hg-core: renaming of `Chunk` offset methods (D8958#inline-15002 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45602
diff
changeset
|
29 fn start_offset_by(&self, offset: i32) -> u32 { |
45600
d07e4656ff5a
hg-core: use `u32` instead of `i32` in `Chunk` (D8958#inline-15001 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45599
diff
changeset
|
30 let start = self.start as i32 + offset; |
d07e4656ff5a
hg-core: use `u32` instead of `i32` in `Chunk` (D8958#inline-15001 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45599
diff
changeset
|
31 assert!(start >= 0, "negative chunk start should never happen"); |
d07e4656ff5a
hg-core: use `u32` instead of `i32` in `Chunk` (D8958#inline-15001 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45599
diff
changeset
|
32 start as u32 |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
33 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
34 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
35 /// Adjusted end of the chunk to replace. |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
36 /// |
45602
cee7a8e37e9c
hg-core: minor rewording in docstring (D8958#inline-15005 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45601
diff
changeset
|
37 /// The offset, taking into account the growth/shrinkage of data |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
38 /// induced by previously applied chunks. |
45603
b68b19104d16
hg-core: renaming of `Chunk` offset methods (D8958#inline-15002 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45602
diff
changeset
|
39 fn end_offset_by(&self, offset: i32) -> u32 { |
b68b19104d16
hg-core: renaming of `Chunk` offset methods (D8958#inline-15002 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45602
diff
changeset
|
40 self.start_offset_by(offset) + self.data.len() as u32 |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
41 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
42 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
43 /// Length of the replaced chunk. |
45600
d07e4656ff5a
hg-core: use `u32` instead of `i32` in `Chunk` (D8958#inline-15001 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45599
diff
changeset
|
44 fn replaced_len(&self) -> u32 { |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
45 self.end - self.start |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
46 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
47 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
48 /// Length difference between the replacing data and the replaced data. |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
49 fn len_diff(&self) -> i32 { |
45600
d07e4656ff5a
hg-core: use `u32` instead of `i32` in `Chunk` (D8958#inline-15001 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45599
diff
changeset
|
50 self.data.len() as i32 - self.replaced_len() as i32 |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
51 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
52 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
53 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
54 /// The delta between two revisions data. |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
55 #[derive(Debug, Clone)] |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
56 pub struct PatchList<'a> { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
57 /// A collection of chunks to apply. |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
58 /// |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
59 /// Those chunks are: |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
60 /// - ordered from the left-most replacement to the right-most replacement |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
61 /// - non-overlapping, meaning that two chucks can not change the same |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
62 /// chunk of the patched data |
45599
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
63 chunks: Vec<Chunk<'a>>, |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
64 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
65 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
66 impl<'a> PatchList<'a> { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
67 /// Create a `PatchList` from bytes. |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
68 pub fn new(data: &'a [u8]) -> Result<Self, RevlogError> { |
45599
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
69 let mut chunks = vec![]; |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
70 let mut data = data; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
71 while !data.is_empty() { |
45600
d07e4656ff5a
hg-core: use `u32` instead of `i32` in `Chunk` (D8958#inline-15001 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45599
diff
changeset
|
72 let start = BigEndian::read_u32(&data[0..]); |
d07e4656ff5a
hg-core: use `u32` instead of `i32` in `Chunk` (D8958#inline-15001 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45599
diff
changeset
|
73 let end = BigEndian::read_u32(&data[4..]); |
d07e4656ff5a
hg-core: use `u32` instead of `i32` in `Chunk` (D8958#inline-15001 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45599
diff
changeset
|
74 let len = BigEndian::read_u32(&data[8..]); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
75 if start > end { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
76 return Err(RevlogError::corrupted("patch cannot be decoded")); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
77 } |
45599
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
78 chunks.push(Chunk { |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
79 start, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
80 end, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
81 data: &data[12..12 + (len as usize)], |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
82 }); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
83 data = &data[12 + (len as usize)..]; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
84 } |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
85 Ok(PatchList { chunks }) |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
86 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
87 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
88 /// Apply the patch to some data. |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
89 pub fn apply<T>( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
90 &self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
91 buffer: &mut dyn RevisionBuffer<Target = T>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
92 initial: &[u8], |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
93 ) { |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
94 let mut last: usize = 0; |
45599
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
95 for Chunk { start, end, data } in self.chunks.iter() { |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
96 let slice = &initial[last..(*start as usize)]; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
97 buffer.extend_from_slice(slice); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
98 buffer.extend_from_slice(data); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
99 last = *end as usize; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
100 } |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
101 buffer.extend_from_slice(&initial[last..]); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
102 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
103 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
104 /// Combine two patch lists into a single patch list. |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
105 /// |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
106 /// Applying consecutive patches can lead to waste of time and memory |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
107 /// as the changes introduced by one patch can be overridden by the next. |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
108 /// Combining patches optimizes the whole patching sequence. |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
109 fn combine(&mut self, other: &mut Self) -> Self { |
45599
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
110 let mut chunks = vec![]; |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
111 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
112 // Keep track of each growth/shrinkage resulting from applying a chunk |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
113 // in order to adjust the start/end of subsequent chunks. |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
114 let mut offset = 0i32; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
115 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
116 // Keep track of the chunk of self.chunks to process. |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
117 let mut pos = 0; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
118 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
119 // For each chunk of `other`, chunks of `self` are processed |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
120 // until they start after the end of the current chunk. |
45599
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
121 for Chunk { start, end, data } in other.chunks.iter() { |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
122 // Add chunks of `self` that start before this chunk of `other` |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
123 // without overlap. |
45599
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
124 while pos < self.chunks.len() |
45603
b68b19104d16
hg-core: renaming of `Chunk` offset methods (D8958#inline-15002 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45602
diff
changeset
|
125 && self.chunks[pos].end_offset_by(offset) <= *start |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
126 { |
45599
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
127 let first = self.chunks[pos].clone(); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
128 offset += first.len_diff(); |
45599
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
129 chunks.push(first); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
130 pos += 1; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
131 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
132 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
133 // The current chunk of `self` starts before this chunk of `other` |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
134 // with overlap. |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
135 // The left-most part of data is added as an insertion chunk. |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
136 // The right-most part data is kept in the chunk. |
45599
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
137 if pos < self.chunks.len() |
45603
b68b19104d16
hg-core: renaming of `Chunk` offset methods (D8958#inline-15002 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45602
diff
changeset
|
138 && self.chunks[pos].start_offset_by(offset) < *start |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
139 { |
45599
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
140 let first = &mut self.chunks[pos]; |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
141 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
142 let (data_left, data_right) = first.data.split_at( |
45603
b68b19104d16
hg-core: renaming of `Chunk` offset methods (D8958#inline-15002 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45602
diff
changeset
|
143 (*start - first.start_offset_by(offset)) as usize, |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
144 ); |
45599
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
145 let left = Chunk { |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
146 start: first.start, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
147 end: first.start, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
148 data: data_left, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
149 }; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
150 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
151 first.data = data_right; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
152 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
153 offset += left.len_diff(); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
154 |
45599
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
155 chunks.push(left); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
156 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
157 // There is no index incrementation because the right-most part |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
158 // needs further examination. |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
159 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
160 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
161 // At this point remaining chunks of `self` starts after |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
162 // the current chunk of `other`. |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
163 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
164 // `start_offset` will be used to adjust the start of the current |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
165 // chunk of `other`. |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
166 // Offset tracking continues with `end_offset` to adjust the end |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
167 // of the current chunk of `other`. |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
168 let mut next_offset = offset; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
169 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
170 // Discard the chunks of `self` that are totally overridden |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
171 // by the current chunk of `other` |
45599
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
172 while pos < self.chunks.len() |
45603
b68b19104d16
hg-core: renaming of `Chunk` offset methods (D8958#inline-15002 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45602
diff
changeset
|
173 && self.chunks[pos].end_offset_by(next_offset) <= *end |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
174 { |
45599
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
175 let first = &self.chunks[pos]; |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
176 next_offset += first.len_diff(); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
177 pos += 1; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
178 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
179 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
180 // Truncate the left-most part of chunk of `self` that overlaps |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
181 // the current chunk of `other`. |
45599
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
182 if pos < self.chunks.len() |
45603
b68b19104d16
hg-core: renaming of `Chunk` offset methods (D8958#inline-15002 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45602
diff
changeset
|
183 && self.chunks[pos].start_offset_by(next_offset) < *end |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
184 { |
45599
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
185 let first = &mut self.chunks[pos]; |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
186 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
187 let how_much_to_discard = |
45603
b68b19104d16
hg-core: renaming of `Chunk` offset methods (D8958#inline-15002 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45602
diff
changeset
|
188 *end - first.start_offset_by(next_offset); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
189 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
190 first.data = &first.data[(how_much_to_discard as usize)..]; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
191 |
45600
d07e4656ff5a
hg-core: use `u32` instead of `i32` in `Chunk` (D8958#inline-15001 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45599
diff
changeset
|
192 next_offset += how_much_to_discard as i32; |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
193 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
194 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
195 // Add the chunk of `other` with adjusted position. |
45599
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
196 chunks.push(Chunk { |
45600
d07e4656ff5a
hg-core: use `u32` instead of `i32` in `Chunk` (D8958#inline-15001 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45599
diff
changeset
|
197 start: (*start as i32 - offset) as u32, |
d07e4656ff5a
hg-core: use `u32` instead of `i32` in `Chunk` (D8958#inline-15001 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45599
diff
changeset
|
198 end: (*end as i32 - next_offset) as u32, |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
199 data, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
200 }); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
201 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
202 // Go back to normal offset tracking for the next `o` chunk |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
203 offset = next_offset; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
204 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
205 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
206 // Add remaining chunks of `self`. |
45599
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
207 for elt in &self.chunks[pos..] { |
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
208 chunks.push(elt.clone()); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
209 } |
45599
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
210 PatchList { chunks } |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
211 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
212 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
213 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
214 /// Combine a list of patch list into a single patch optimized patch list. |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
215 pub fn fold_patch_lists<'a>(lists: &[PatchList<'a>]) -> PatchList<'a> { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
216 if lists.len() <= 1 { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
217 if lists.is_empty() { |
45599
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
218 PatchList { chunks: vec![] } |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
219 } else { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
220 lists[0].clone() |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
221 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
222 } else { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
223 let (left, right) = lists.split_at(lists.len() / 2); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
224 let mut left_res = fold_patch_lists(left); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
225 let mut right_res = fold_patch_lists(right); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
226 left_res.combine(&mut right_res) |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
227 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
228 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
229 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
230 #[cfg(test)] |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
231 mod tests { |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
232 use crate::inner_revlog::CoreRevisionBuffer; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
233 |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
234 use super::*; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
235 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
236 struct PatchDataBuilder { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
237 data: Vec<u8>, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
238 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
239 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
240 impl PatchDataBuilder { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
241 pub fn new() -> Self { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
242 Self { data: vec![] } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
243 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
244 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
245 pub fn replace( |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
246 &mut self, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
247 start: usize, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
248 end: usize, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
249 data: &[u8], |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
250 ) -> &mut Self { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
251 assert!(start <= end); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
252 self.data.extend(&(start as i32).to_be_bytes()); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
253 self.data.extend(&(end as i32).to_be_bytes()); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
254 self.data.extend(&(data.len() as i32).to_be_bytes()); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
255 self.data.extend(data.iter()); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
256 self |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
257 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
258 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
259 pub fn get(&mut self) -> &[u8] { |
45597
48438e8968a2
hg-core: remove useless code (D8958#inline-14988 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45532
diff
changeset
|
260 &self.data |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
261 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
262 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
263 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
264 #[test] |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
265 fn test_ends_before() { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
266 let data = vec![0u8, 0u8, 0u8]; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
267 let mut patch1_data = PatchDataBuilder::new(); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
268 patch1_data.replace(0, 1, &[1, 2]); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
269 let mut patch1 = PatchList::new(patch1_data.get()).unwrap(); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
270 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
271 let mut patch2_data = PatchDataBuilder::new(); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
272 patch2_data.replace(2, 4, &[3, 4]); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
273 let mut patch2 = PatchList::new(patch2_data.get()).unwrap(); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
274 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
275 let patch = patch1.combine(&mut patch2); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
276 |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
277 let mut buffer = CoreRevisionBuffer::new(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
278 patch.apply(&mut buffer, &data); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
279 |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
280 assert_eq!(buffer.finish(), vec![1u8, 2, 3, 4]); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
281 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
282 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
283 #[test] |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
284 fn test_starts_after() { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
285 let data = vec![0u8, 0u8, 0u8]; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
286 let mut patch1_data = PatchDataBuilder::new(); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
287 patch1_data.replace(2, 3, &[3]); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
288 let mut patch1 = PatchList::new(patch1_data.get()).unwrap(); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
289 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
290 let mut patch2_data = PatchDataBuilder::new(); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
291 patch2_data.replace(1, 2, &[1, 2]); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
292 let mut patch2 = PatchList::new(patch2_data.get()).unwrap(); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
293 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
294 let patch = patch1.combine(&mut patch2); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
295 |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
296 let mut buffer = CoreRevisionBuffer::new(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
297 patch.apply(&mut buffer, &data); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
298 |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
299 assert_eq!(buffer.finish(), vec![0u8, 1, 2, 3]); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
300 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
301 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
302 #[test] |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
303 fn test_overridden() { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
304 let data = vec![0u8, 0, 0]; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
305 let mut patch1_data = PatchDataBuilder::new(); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
306 patch1_data.replace(1, 2, &[3, 4]); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
307 let mut patch1 = PatchList::new(patch1_data.get()).unwrap(); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
308 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
309 let mut patch2_data = PatchDataBuilder::new(); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
310 patch2_data.replace(1, 4, &[1, 2, 3]); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
311 let mut patch2 = PatchList::new(patch2_data.get()).unwrap(); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
312 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
313 let patch = patch1.combine(&mut patch2); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
314 |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
315 let mut buffer = CoreRevisionBuffer::new(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
316 patch.apply(&mut buffer, &data); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
317 |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
318 assert_eq!(buffer.finish(), vec![0u8, 1, 2, 3]); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
319 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
320 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
321 #[test] |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
322 fn test_right_most_part_is_overridden() { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
323 let data = vec![0u8, 0, 0]; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
324 let mut patch1_data = PatchDataBuilder::new(); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
325 patch1_data.replace(0, 1, &[1, 3]); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
326 let mut patch1 = PatchList::new(patch1_data.get()).unwrap(); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
327 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
328 let mut patch2_data = PatchDataBuilder::new(); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
329 patch2_data.replace(1, 4, &[2, 3, 4]); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
330 let mut patch2 = PatchList::new(patch2_data.get()).unwrap(); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
331 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
332 let patch = patch1.combine(&mut patch2); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
333 |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
334 let mut buffer = CoreRevisionBuffer::new(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
335 patch.apply(&mut buffer, &data); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
336 |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
337 assert_eq!(buffer.finish(), vec![1u8, 2, 3, 4]); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
338 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
339 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
340 #[test] |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
341 fn test_left_most_part_is_overridden() { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
342 let data = vec![0u8, 0, 0]; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
343 let mut patch1_data = PatchDataBuilder::new(); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
344 patch1_data.replace(1, 3, &[1, 3, 4]); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
345 let mut patch1 = PatchList::new(patch1_data.get()).unwrap(); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
346 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
347 let mut patch2_data = PatchDataBuilder::new(); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
348 patch2_data.replace(0, 2, &[1, 2]); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
349 let mut patch2 = PatchList::new(patch2_data.get()).unwrap(); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
350 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
351 let patch = patch1.combine(&mut patch2); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
352 |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
353 let mut buffer = CoreRevisionBuffer::new(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
354 patch.apply(&mut buffer, &data); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
355 |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
356 assert_eq!(buffer.finish(), vec![1u8, 2, 3, 4]); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
357 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
358 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
359 #[test] |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
360 fn test_mid_is_overridden() { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
361 let data = vec![0u8, 0, 0]; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
362 let mut patch1_data = PatchDataBuilder::new(); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
363 patch1_data.replace(0, 3, &[1, 3, 3, 4]); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
364 let mut patch1 = PatchList::new(patch1_data.get()).unwrap(); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
365 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
366 let mut patch2_data = PatchDataBuilder::new(); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
367 patch2_data.replace(1, 3, &[2, 3]); |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
368 let mut patch2 = PatchList::new(patch2_data.get()).unwrap(); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
369 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
370 let patch = patch1.combine(&mut patch2); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
371 |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
372 let mut buffer = CoreRevisionBuffer::new(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
373 patch.apply(&mut buffer, &data); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
374 |
52290
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45603
diff
changeset
|
375 assert_eq!(buffer.finish(), vec![1u8, 2, 3, 4]); |
45532
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
376 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
377 } |