Mercurial > public > mercurial-scm > hg
annotate rust/hg-core/src/revlog/patch.rs @ 53042:cdd7bf612c7b stable tip
bundle-spec: properly format boolean parameter (issue6960)
This was breaking automatic clone bundle generation. This changeset fixes it and
add a test to catch it in the future.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 11 Mar 2025 02:29:42 +0100 |
parents | 8497cfb0d76c |
children |
rev | line source |
---|---|
45526
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 |
52178
bd8081e9fd62
rust: don't star export from the `revlog` module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52160
diff
changeset
|
3 use crate::revlog::RevlogError; |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
4 |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
5 use super::inner_revlog::RevisionBuffer; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
6 |
45526
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)] |
52761
8497cfb0d76c
rust-manifest: add Manifestlog::inexact_data_delta_parents
Mitchell Kember <mkember@janestreet.com>
parents:
52178
diff
changeset
|
15 pub(crate) struct Chunk<'a> { |
45526
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 |
52761
8497cfb0d76c
rust-manifest: add Manifestlog::inexact_data_delta_parents
Mitchell Kember <mkember@janestreet.com>
parents:
52178
diff
changeset
|
17 pub(crate) start: u32, |
45526
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) |
52761
8497cfb0d76c
rust-manifest: add Manifestlog::inexact_data_delta_parents
Mitchell Kember <mkember@janestreet.com>
parents:
52178
diff
changeset
|
19 pub(crate) end: u32, |
45526
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 |
52761
8497cfb0d76c
rust-manifest: add Manifestlog::inexact_data_delta_parents
Mitchell Kember <mkember@janestreet.com>
parents:
52178
diff
changeset
|
21 pub(crate) data: &'a [u8], |
45526
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 |
45598
412a5827ad02
hg-core: use anonymous lifetime for `impl Chunk` (D8958#inline-15003 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45597
diff
changeset
|
24 impl Chunk<'_> { |
45526
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 /// |
45599
cee7a8e37e9c
hg-core: minor rewording in docstring (D8958#inline-15005 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45598
diff
changeset
|
27 /// The offset, taking into account the growth/shrinkage of data |
45526
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. |
45600
b68b19104d16
hg-core: renaming of `Chunk` offset methods (D8958#inline-15002 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45599
diff
changeset
|
29 fn start_offset_by(&self, offset: i32) -> u32 { |
45597
d07e4656ff5a
hg-core: use `u32` instead of `i32` in `Chunk` (D8958#inline-15001 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45596
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:
45596
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:
45596
diff
changeset
|
32 start as u32 |
45526
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 /// |
45599
cee7a8e37e9c
hg-core: minor rewording in docstring (D8958#inline-15005 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45598
diff
changeset
|
37 /// The offset, taking into account the growth/shrinkage of data |
45526
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. |
45600
b68b19104d16
hg-core: renaming of `Chunk` offset methods (D8958#inline-15002 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45599
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:
45599
diff
changeset
|
40 self.start_offset_by(offset) + self.data.len() as u32 |
45526
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. |
45597
d07e4656ff5a
hg-core: use `u32` instead of `i32` in `Chunk` (D8958#inline-15001 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45596
diff
changeset
|
44 fn replaced_len(&self) -> u32 { |
45526
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 { |
45597
d07e4656ff5a
hg-core: use `u32` instead of `i32` in `Chunk` (D8958#inline-15001 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45596
diff
changeset
|
50 self.data.len() as i32 - self.replaced_len() as i32 |
45526
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 |
52761
8497cfb0d76c
rust-manifest: add Manifestlog::inexact_data_delta_parents
Mitchell Kember <mkember@janestreet.com>
parents:
52178
diff
changeset
|
63 pub(crate) chunks: Vec<Chunk<'a>>, |
45526
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. |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
68 pub fn new(data: &'a [u8]) -> Result<Self, RevlogError> { |
45596
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45594
diff
changeset
|
69 let mut chunks = vec![]; |
45526
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() { |
45597
d07e4656ff5a
hg-core: use `u32` instead of `i32` in `Chunk` (D8958#inline-15001 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45596
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:
45596
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:
45596
diff
changeset
|
74 let len = BigEndian::read_u32(&data[8..]); |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
75 if start > end { |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
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:
45600
diff
changeset
|
77 } |
45596
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45594
diff
changeset
|
78 chunks.push(Chunk { |
45526
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 } |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
85 Ok(PatchList { chunks }) |
45526
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 |
52761
8497cfb0d76c
rust-manifest: add Manifestlog::inexact_data_delta_parents
Mitchell Kember <mkember@janestreet.com>
parents:
52178
diff
changeset
|
88 /// Creates a patch for a full snapshot, going from nothing to `data`. |
8497cfb0d76c
rust-manifest: add Manifestlog::inexact_data_delta_parents
Mitchell Kember <mkember@janestreet.com>
parents:
52178
diff
changeset
|
89 pub fn full_snapshot(data: &'a [u8]) -> Self { |
8497cfb0d76c
rust-manifest: add Manifestlog::inexact_data_delta_parents
Mitchell Kember <mkember@janestreet.com>
parents:
52178
diff
changeset
|
90 Self { |
8497cfb0d76c
rust-manifest: add Manifestlog::inexact_data_delta_parents
Mitchell Kember <mkember@janestreet.com>
parents:
52178
diff
changeset
|
91 chunks: vec![Chunk { |
8497cfb0d76c
rust-manifest: add Manifestlog::inexact_data_delta_parents
Mitchell Kember <mkember@janestreet.com>
parents:
52178
diff
changeset
|
92 start: 0, |
8497cfb0d76c
rust-manifest: add Manifestlog::inexact_data_delta_parents
Mitchell Kember <mkember@janestreet.com>
parents:
52178
diff
changeset
|
93 end: 0, |
8497cfb0d76c
rust-manifest: add Manifestlog::inexact_data_delta_parents
Mitchell Kember <mkember@janestreet.com>
parents:
52178
diff
changeset
|
94 data, |
8497cfb0d76c
rust-manifest: add Manifestlog::inexact_data_delta_parents
Mitchell Kember <mkember@janestreet.com>
parents:
52178
diff
changeset
|
95 }], |
8497cfb0d76c
rust-manifest: add Manifestlog::inexact_data_delta_parents
Mitchell Kember <mkember@janestreet.com>
parents:
52178
diff
changeset
|
96 } |
8497cfb0d76c
rust-manifest: add Manifestlog::inexact_data_delta_parents
Mitchell Kember <mkember@janestreet.com>
parents:
52178
diff
changeset
|
97 } |
8497cfb0d76c
rust-manifest: add Manifestlog::inexact_data_delta_parents
Mitchell Kember <mkember@janestreet.com>
parents:
52178
diff
changeset
|
98 |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
99 /// Apply the patch to some data. |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
100 pub fn apply<T>( |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
101 &self, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
102 buffer: &mut dyn RevisionBuffer<Target = T>, |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
103 initial: &[u8], |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
104 ) { |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
105 let mut last: usize = 0; |
45596
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45594
diff
changeset
|
106 for Chunk { start, end, data } in self.chunks.iter() { |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
107 let slice = &initial[last..(*start as usize)]; |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
108 buffer.extend_from_slice(slice); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
109 buffer.extend_from_slice(data); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
110 last = *end as usize; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
111 } |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
112 buffer.extend_from_slice(&initial[last..]); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
113 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
114 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
115 /// 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
|
116 /// |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
117 /// 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
|
118 /// 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
|
119 /// 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
|
120 fn combine(&mut self, other: &mut Self) -> Self { |
45596
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45594
diff
changeset
|
121 let mut chunks = vec![]; |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
122 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
123 // 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
|
124 // 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
|
125 let mut offset = 0i32; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
126 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
127 // 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
|
128 let mut pos = 0; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
129 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
130 // 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
|
131 // until they start after the end of the current chunk. |
45596
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45594
diff
changeset
|
132 for Chunk { start, end, data } in other.chunks.iter() { |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
133 // 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
|
134 // without overlap. |
45596
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45594
diff
changeset
|
135 while pos < self.chunks.len() |
45600
b68b19104d16
hg-core: renaming of `Chunk` offset methods (D8958#inline-15002 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45599
diff
changeset
|
136 && self.chunks[pos].end_offset_by(offset) <= *start |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
137 { |
45596
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45594
diff
changeset
|
138 let first = self.chunks[pos].clone(); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
139 offset += first.len_diff(); |
45596
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45594
diff
changeset
|
140 chunks.push(first); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
141 pos += 1; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
142 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
143 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
144 // 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
|
145 // with overlap. |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
146 // 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
|
147 // The right-most part data is kept in the chunk. |
45596
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45594
diff
changeset
|
148 if pos < self.chunks.len() |
45600
b68b19104d16
hg-core: renaming of `Chunk` offset methods (D8958#inline-15002 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45599
diff
changeset
|
149 && self.chunks[pos].start_offset_by(offset) < *start |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
150 { |
45596
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45594
diff
changeset
|
151 let first = &mut self.chunks[pos]; |
45526
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 let (data_left, data_right) = first.data.split_at( |
45600
b68b19104d16
hg-core: renaming of `Chunk` offset methods (D8958#inline-15002 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45599
diff
changeset
|
154 (*start - first.start_offset_by(offset)) as usize, |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
155 ); |
45596
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45594
diff
changeset
|
156 let left = Chunk { |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
157 start: first.start, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
158 end: first.start, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
159 data: data_left, |
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 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
162 first.data = data_right; |
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 offset += left.len_diff(); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
165 |
45596
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45594
diff
changeset
|
166 chunks.push(left); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
167 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
168 // 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
|
169 // needs further examination. |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
170 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
171 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
172 // 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
|
173 // the current chunk of `other`. |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
174 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
175 // `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
|
176 // chunk of `other`. |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
177 // 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
|
178 // 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
|
179 let mut next_offset = offset; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
180 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
181 // 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
|
182 // by the current chunk of `other` |
45596
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45594
diff
changeset
|
183 while pos < self.chunks.len() |
45600
b68b19104d16
hg-core: renaming of `Chunk` offset methods (D8958#inline-15002 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45599
diff
changeset
|
184 && self.chunks[pos].end_offset_by(next_offset) <= *end |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
185 { |
45596
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45594
diff
changeset
|
186 let first = &self.chunks[pos]; |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
187 next_offset += first.len_diff(); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
188 pos += 1; |
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 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
191 // 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
|
192 // the current chunk of `other`. |
45596
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45594
diff
changeset
|
193 if pos < self.chunks.len() |
45600
b68b19104d16
hg-core: renaming of `Chunk` offset methods (D8958#inline-15002 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45599
diff
changeset
|
194 && self.chunks[pos].start_offset_by(next_offset) < *end |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
195 { |
45596
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45594
diff
changeset
|
196 let first = &mut self.chunks[pos]; |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
197 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
198 let how_much_to_discard = |
45600
b68b19104d16
hg-core: renaming of `Chunk` offset methods (D8958#inline-15002 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45599
diff
changeset
|
199 *end - first.start_offset_by(next_offset); |
45526
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 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
|
202 |
45597
d07e4656ff5a
hg-core: use `u32` instead of `i32` in `Chunk` (D8958#inline-15001 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45596
diff
changeset
|
203 next_offset += how_much_to_discard as i32; |
45526
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 the chunk of `other` with adjusted position. |
45596
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45594
diff
changeset
|
207 chunks.push(Chunk { |
45597
d07e4656ff5a
hg-core: use `u32` instead of `i32` in `Chunk` (D8958#inline-15001 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45596
diff
changeset
|
208 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:
45596
diff
changeset
|
209 end: (*end as i32 - next_offset) as u32, |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
210 data, |
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 // 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
|
214 offset = next_offset; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
215 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
216 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
217 // Add remaining chunks of `self`. |
45596
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45594
diff
changeset
|
218 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:
45594
diff
changeset
|
219 chunks.push(elt.clone()); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
220 } |
45596
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45594
diff
changeset
|
221 PatchList { chunks } |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
222 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
223 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
224 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
225 /// 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
|
226 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
|
227 if lists.len() <= 1 { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
228 if lists.is_empty() { |
45596
bb523bff068b
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45594
diff
changeset
|
229 PatchList { chunks: vec![] } |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
230 } else { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
231 lists[0].clone() |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
232 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
233 } else { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
234 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
|
235 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
|
236 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
|
237 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
|
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 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
241 #[cfg(test)] |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
242 mod tests { |
52178
bd8081e9fd62
rust: don't star export from the `revlog` module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52160
diff
changeset
|
243 use crate::revlog::inner_revlog::CoreRevisionBuffer; |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
244 |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
245 use super::*; |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
246 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
247 struct PatchDataBuilder { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
248 data: Vec<u8>, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
249 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
250 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
251 impl PatchDataBuilder { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
252 pub fn new() -> Self { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
253 Self { data: vec![] } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
254 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
255 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
256 pub fn replace( |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
257 &mut self, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
258 start: usize, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
259 end: usize, |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
260 data: &[u8], |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
261 ) -> &mut Self { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
262 assert!(start <= end); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
263 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
|
264 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
|
265 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
|
266 self.data.extend(data.iter()); |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
267 self |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
268 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
269 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
270 pub fn get(&mut self) -> &[u8] { |
45594
48438e8968a2
hg-core: remove useless code (D8958#inline-14988 followup)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45526
diff
changeset
|
271 &self.data |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
272 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
273 } |
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 #[test] |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
276 fn test_ends_before() { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
277 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
|
278 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
|
279 patch1_data.replace(0, 1, &[1, 2]); |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
280 let mut patch1 = PatchList::new(patch1_data.get()).unwrap(); |
45526
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 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
|
283 patch2_data.replace(2, 4, &[3, 4]); |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
284 let mut patch2 = PatchList::new(patch2_data.get()).unwrap(); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
285 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
286 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
|
287 |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
288 let mut buffer = CoreRevisionBuffer::new(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
289 patch.apply(&mut buffer, &data); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
290 |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
291 assert_eq!(buffer.finish(), vec![1u8, 2, 3, 4]); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
292 } |
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 #[test] |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
295 fn test_starts_after() { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
296 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
|
297 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
|
298 patch1_data.replace(2, 3, &[3]); |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
299 let mut patch1 = PatchList::new(patch1_data.get()).unwrap(); |
45526
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 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
|
302 patch2_data.replace(1, 2, &[1, 2]); |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
303 let mut patch2 = PatchList::new(patch2_data.get()).unwrap(); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
304 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
305 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
|
306 |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
307 let mut buffer = CoreRevisionBuffer::new(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
308 patch.apply(&mut buffer, &data); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
309 |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
310 assert_eq!(buffer.finish(), vec![0u8, 1, 2, 3]); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
311 } |
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 #[test] |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
314 fn test_overridden() { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
315 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
|
316 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
|
317 patch1_data.replace(1, 2, &[3, 4]); |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
318 let mut patch1 = PatchList::new(patch1_data.get()).unwrap(); |
45526
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 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
|
321 patch2_data.replace(1, 4, &[1, 2, 3]); |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
322 let mut patch2 = PatchList::new(patch2_data.get()).unwrap(); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
323 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
324 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
|
325 |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
326 let mut buffer = CoreRevisionBuffer::new(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
327 patch.apply(&mut buffer, &data); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
328 |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
329 assert_eq!(buffer.finish(), vec![0u8, 1, 2, 3]); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
330 } |
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 #[test] |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
333 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
|
334 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
|
335 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
|
336 patch1_data.replace(0, 1, &[1, 3]); |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
337 let mut patch1 = PatchList::new(patch1_data.get()).unwrap(); |
45526
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 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
|
340 patch2_data.replace(1, 4, &[2, 3, 4]); |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
341 let mut patch2 = PatchList::new(patch2_data.get()).unwrap(); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
342 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
343 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
|
344 |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
345 let mut buffer = CoreRevisionBuffer::new(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
346 patch.apply(&mut buffer, &data); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
347 |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
348 assert_eq!(buffer.finish(), vec![1u8, 2, 3, 4]); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
349 } |
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 #[test] |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
352 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
|
353 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
|
354 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
|
355 patch1_data.replace(1, 3, &[1, 3, 4]); |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
356 let mut patch1 = PatchList::new(patch1_data.get()).unwrap(); |
45526
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 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
|
359 patch2_data.replace(0, 2, &[1, 2]); |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
360 let mut patch2 = PatchList::new(patch2_data.get()).unwrap(); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
361 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
362 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
|
363 |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
364 let mut buffer = CoreRevisionBuffer::new(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
365 patch.apply(&mut buffer, &data); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
366 |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
367 assert_eq!(buffer.finish(), vec![1u8, 2, 3, 4]); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
368 } |
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 #[test] |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
371 fn test_mid_is_overridden() { |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
372 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
|
373 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
|
374 patch1_data.replace(0, 3, &[1, 3, 3, 4]); |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
375 let mut patch1 = PatchList::new(patch1_data.get()).unwrap(); |
45526
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 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
|
378 patch2_data.replace(1, 3, &[2, 3]); |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
379 let mut patch2 = PatchList::new(patch2_data.get()).unwrap(); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
380 |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
381 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
|
382 |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
383 let mut buffer = CoreRevisionBuffer::new(); |
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
384 patch.apply(&mut buffer, &data); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
385 |
52160
e01e84e5e426
rust-revlog: add a Rust-only `InnerRevlog`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45600
diff
changeset
|
386 assert_eq!(buffer.finish(), vec![1u8, 2, 3, 4]); |
45526
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
387 } |
26c53ee51c68
hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
388 } |