Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
mercurial-devel
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mercurial
mercurial-devel
Commits
bb523bff
Commit
bb523bff
authored
4 years ago
by
Antoine cezar
Browse files
Options
Downloads
Patches
Plain Diff
hg-core: use the term `chunk` instead of `frag` (D8958#inline-15000 followup)
Differential Revision:
https://phab.mercurial-scm.org/D9101
parent
49765789
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
rust/hg-core/src/revlog/patch.rs
+31
-31
31 additions, 31 deletions
rust/hg-core/src/revlog/patch.rs
with
31 additions
and
31 deletions
rust/hg-core/src/revlog/patch.rs
+
31
−
31
View file @
bb523bff
...
...
@@ -8,7 +8,7 @@
/// - a replacement when `!data.is_empty() && start < end`
/// - not doing anything when `data.is_empty() && start == end`
#[derive(Debug,
Clone)]
struct
PatchFrag
<
'a
>
{
struct
Chunk
<
'a
>
{
/// The start position of the chunk of data to replace
start
:
i32
,
/// The end position of the chunk of data to replace (open end interval)
...
...
@@ -17,7 +17,7 @@
data
:
&
'a
[
u8
],
}
impl
<
'a
>
PatchFrag
<
'a
>
{
impl
<
'a
>
Chunk
<
'a
>
{
/// Adjusted start of the chunk to replace.
///
/// Offset allow to take into account the growth/shrinkage of data
...
...
@@ -54,9 +54,9 @@
/// - ordered from the left-most replacement to the right-most replacement
/// - non-overlapping, meaning that two chucks can not change the same
/// chunk of the patched data
frag
s
:
Vec
<
PatchFrag
<
'a
>>
,
chunk
s
:
Vec
<
Chunk
<
'a
>>
,
}
impl
<
'a
>
PatchList
<
'a
>
{
/// Create a `PatchList` from bytes.
pub
fn
new
(
data
:
&
'a
[
u8
])
->
Self
{
...
...
@@ -58,12 +58,12 @@
}
impl
<
'a
>
PatchList
<
'a
>
{
/// Create a `PatchList` from bytes.
pub
fn
new
(
data
:
&
'a
[
u8
])
->
Self
{
let
mut
frag
s
=
vec!
[];
let
mut
chunk
s
=
vec!
[];
let
mut
data
=
data
;
while
!
data
.is_empty
()
{
let
start
=
BigEndian
::
read_i32
(
&
data
[
0
..
]);
let
end
=
BigEndian
::
read_i32
(
&
data
[
4
..
]);
let
len
=
BigEndian
::
read_i32
(
&
data
[
8
..
]);
assert!
(
0
<=
start
&&
start
<=
end
&&
len
>=
0
);
...
...
@@ -64,13 +64,13 @@
let
mut
data
=
data
;
while
!
data
.is_empty
()
{
let
start
=
BigEndian
::
read_i32
(
&
data
[
0
..
]);
let
end
=
BigEndian
::
read_i32
(
&
data
[
4
..
]);
let
len
=
BigEndian
::
read_i32
(
&
data
[
8
..
]);
assert!
(
0
<=
start
&&
start
<=
end
&&
len
>=
0
);
frag
s
.push
(
PatchFrag
{
chunk
s
.push
(
Chunk
{
start
,
end
,
data
:
&
data
[
12
..
12
+
(
len
as
usize
)],
});
data
=
&
data
[
12
+
(
len
as
usize
)
..
];
}
...
...
@@ -71,12 +71,12 @@
start
,
end
,
data
:
&
data
[
12
..
12
+
(
len
as
usize
)],
});
data
=
&
data
[
12
+
(
len
as
usize
)
..
];
}
PatchList
{
frag
s
}
PatchList
{
chunk
s
}
}
/// Return the final length of data after patching
/// given its initial length .
fn
size
(
&
self
,
initial_size
:
i32
)
->
i32
{
...
...
@@ -78,7 +78,7 @@
}
/// Return the final length of data after patching
/// given its initial length .
fn
size
(
&
self
,
initial_size
:
i32
)
->
i32
{
self
.
frag
s
self
.
chunk
s
.iter
()
...
...
@@ -84,5 +84,5 @@
.iter
()
.fold
(
initial_size
,
|
acc
,
frag
|
acc
+
frag
.len_diff
())
.fold
(
initial_size
,
|
acc
,
chunk
|
acc
+
chunk
.len_diff
())
}
/// Apply the patch to some data.
...
...
@@ -90,7 +90,7 @@
let
mut
last
:
usize
=
0
;
let
mut
vec
=
Vec
::
with_capacity
(
self
.size
(
initial
.len
()
as
i32
)
as
usize
);
for
PatchFrag
{
start
,
end
,
data
}
in
self
.
frag
s
.iter
()
{
for
Chunk
{
start
,
end
,
data
}
in
self
.
chunk
s
.iter
()
{
vec
.extend
(
&
initial
[
last
..
(
*
start
as
usize
)]);
vec
.extend
(
data
.iter
());
last
=
*
end
as
usize
;
...
...
@@ -105,7 +105,7 @@
/// as the changes introduced by one patch can be overridden by the next.
/// Combining patches optimizes the whole patching sequence.
fn
combine
(
&
mut
self
,
other
:
&
mut
Self
)
->
Self
{
let
mut
frag
s
=
vec!
[];
let
mut
chunk
s
=
vec!
[];
// Keep track of each growth/shrinkage resulting from applying a chunk
// in order to adjust the start/end of subsequent chunks.
...
...
@@ -116,6 +116,6 @@
// For each chunk of `other`, chunks of `self` are processed
// until they start after the end of the current chunk.
for
PatchFrag
{
start
,
end
,
data
}
in
other
.
frag
s
.iter
()
{
for
Chunk
{
start
,
end
,
data
}
in
other
.
chunk
s
.iter
()
{
// Add chunks of `self` that start before this chunk of `other`
// without overlap.
...
...
@@ -120,5 +120,5 @@
// Add chunks of `self` that start before this chunk of `other`
// without overlap.
while
pos
<
self
.
frag
s
.len
()
&&
self
.
frag
s
[
pos
]
.end_offseted_by
(
offset
)
<=
*
start
while
pos
<
self
.
chunk
s
.len
()
&&
self
.
chunk
s
[
pos
]
.end_offseted_by
(
offset
)
<=
*
start
{
...
...
@@ -124,3 +124,3 @@
{
let
first
=
self
.
frag
s
[
pos
]
.clone
();
let
first
=
self
.
chunk
s
[
pos
]
.clone
();
offset
+=
first
.len_diff
();
...
...
@@ -126,5 +126,5 @@
offset
+=
first
.len_diff
();
frag
s
.push
(
first
);
chunk
s
.push
(
first
);
pos
+=
1
;
}
...
...
@@ -132,6 +132,6 @@
// with overlap.
// The left-most part of data is added as an insertion chunk.
// The right-most part data is kept in the chunk.
if
pos
<
self
.
frag
s
.len
()
&&
self
.
frag
s
[
pos
]
.start_offseted_by
(
offset
)
<
*
start
if
pos
<
self
.
chunk
s
.len
()
&&
self
.
chunk
s
[
pos
]
.start_offseted_by
(
offset
)
<
*
start
{
...
...
@@ -137,6 +137,6 @@
{
let
first
=
&
mut
self
.
frag
s
[
pos
];
let
first
=
&
mut
self
.
chunk
s
[
pos
];
let
(
data_left
,
data_right
)
=
first
.data
.split_at
(
(
*
start
-
first
.start_offseted_by
(
offset
))
as
usize
,
);
...
...
@@ -139,8 +139,8 @@
let
(
data_left
,
data_right
)
=
first
.data
.split_at
(
(
*
start
-
first
.start_offseted_by
(
offset
))
as
usize
,
);
let
left
=
PatchFrag
{
let
left
=
Chunk
{
start
:
first
.start
,
end
:
first
.start
,
data
:
data_left
,
...
...
@@ -150,7 +150,7 @@
offset
+=
left
.len_diff
();
frag
s
.push
(
left
);
chunk
s
.push
(
left
);
// There is no index incrementation because the right-most part
// needs further examination.
...
...
@@ -167,6 +167,6 @@
// Discard the chunks of `self` that are totally overridden
// by the current chunk of `other`
while
pos
<
self
.
frag
s
.len
()
&&
self
.
frag
s
[
pos
]
.end_offseted_by
(
next_offset
)
<=
*
end
while
pos
<
self
.
chunk
s
.len
()
&&
self
.
chunk
s
[
pos
]
.end_offseted_by
(
next_offset
)
<=
*
end
{
...
...
@@ -172,8 +172,8 @@
{
let
first
=
&
self
.
frag
s
[
pos
];
let
first
=
&
self
.
chunk
s
[
pos
];
next_offset
+=
first
.len_diff
();
pos
+=
1
;
}
// Truncate the left-most part of chunk of `self` that overlaps
// the current chunk of `other`.
...
...
@@ -174,9 +174,9 @@
next_offset
+=
first
.len_diff
();
pos
+=
1
;
}
// Truncate the left-most part of chunk of `self` that overlaps
// the current chunk of `other`.
if
pos
<
self
.
frag
s
.len
()
&&
self
.
frag
s
[
pos
]
.start_offseted_by
(
next_offset
)
<
*
end
if
pos
<
self
.
chunk
s
.len
()
&&
self
.
chunk
s
[
pos
]
.start_offseted_by
(
next_offset
)
<
*
end
{
...
...
@@ -182,5 +182,5 @@
{
let
first
=
&
mut
self
.
frag
s
[
pos
];
let
first
=
&
mut
self
.
chunk
s
[
pos
];
let
how_much_to_discard
=
*
end
-
first
.start_offseted_by
(
next_offset
);
...
...
@@ -191,7 +191,7 @@
}
// Add the chunk of `other` with adjusted position.
frag
s
.push
(
PatchFrag
{
chunk
s
.push
(
Chunk
{
start
:
*
start
-
offset
,
end
:
*
end
-
next_offset
,
data
,
...
...
@@ -202,6 +202,6 @@
}
// Add remaining chunks of `self`.
for
elt
in
&
self
.
frag
s
[
pos
..
]
{
frag
s
.push
(
elt
.clone
());
for
elt
in
&
self
.
chunk
s
[
pos
..
]
{
chunk
s
.push
(
elt
.clone
());
}
...
...
@@ -207,5 +207,5 @@
}
PatchList
{
frag
s
}
PatchList
{
chunk
s
}
}
}
...
...
@@ -213,7 +213,7 @@
pub
fn
fold_patch_lists
<
'a
>
(
lists
:
&
[
PatchList
<
'a
>
])
->
PatchList
<
'a
>
{
if
lists
.len
()
<=
1
{
if
lists
.is_empty
()
{
PatchList
{
frag
s
:
vec!
[]
}
PatchList
{
chunk
s
:
vec!
[]
}
}
else
{
lists
[
0
]
.clone
()
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment