Skip to content

Commit 56ca4bf

Browse files
committed
refactor
* put error into more specific spot and export it
1 parent fce7095 commit 56ca4bf

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

gix-pack/src/cache/delta/traverse/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub enum Error {
4242
#[error("Failed to spawn thread when switching to work-stealing mode")]
4343
SpawnThread(#[from] std::io::Error),
4444
#[error(transparent)]
45-
Delta(#[from] crate::data::delta::Error),
45+
Delta(#[from] crate::data::delta::apply::Error),
4646
}
4747

4848
/// Additional context passed to the `inspect_object(…)` function of the [`Tree::traverse()`] method.

gix-pack/src/data/delta.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
/// Returned by [`Tree::traverse()`]
2-
#[derive(thiserror::Error, Debug)]
3-
#[allow(missing_docs)]
4-
pub enum Error {
5-
#[error("Encountered unsupported command code: 0")]
6-
UnsupportedCommandCode,
7-
#[error("Delta copy from base: byte slices must match")]
8-
DeltaCopyBaseSliceMismatch,
9-
#[error("Delta copy data: byte slices must match")]
10-
DeltaCopyDataSliceMismatch,
1+
///
2+
pub mod apply {
3+
/// Returned when failing to apply deltas.
4+
#[derive(thiserror::Error, Debug)]
5+
#[allow(missing_docs)]
6+
pub enum Error {
7+
#[error("Encountered unsupported command code: 0")]
8+
UnsupportedCommandCode,
9+
#[error("Delta copy from base: byte slices must match")]
10+
DeltaCopyBaseSliceMismatch,
11+
#[error("Delta copy data: byte slices must match")]
12+
DeltaCopyDataSliceMismatch,
13+
}
1114
}
1215

1316
/// Given the decompressed pack delta `d`, decode a size in bytes (either the base object size or the result object size)
1417
/// Equivalent to [this canonical git function](https://github.com/git/git/blob/311531c9de557d25ac087c1637818bd2aad6eb3a/delta.h#L89)
15-
pub fn decode_header_size(d: &[u8]) -> (u64, usize) {
18+
pub(crate) fn decode_header_size(d: &[u8]) -> (u64, usize) {
1619
let mut i = 0;
1720
let mut size = 0u64;
1821
let mut consumed = 0;
@@ -27,7 +30,7 @@ pub fn decode_header_size(d: &[u8]) -> (u64, usize) {
2730
(size, consumed)
2831
}
2932

30-
pub fn apply(base: &[u8], mut target: &mut [u8], data: &[u8]) -> Result<(), Error> {
33+
pub(crate) fn apply(base: &[u8], mut target: &mut [u8], data: &[u8]) -> Result<(), apply::Error> {
3134
let mut i = 0;
3235
while let Some(cmd) = data.get(i) {
3336
i += 1;
@@ -67,12 +70,12 @@ pub fn apply(base: &[u8], mut target: &mut [u8], data: &[u8]) -> Result<(), Erro
6770
}
6871
let ofs = ofs as usize;
6972
std::io::Write::write(&mut target, &base[ofs..ofs + size as usize])
70-
.map_err(|_e| Error::DeltaCopyBaseSliceMismatch)?;
73+
.map_err(|_e| apply::Error::DeltaCopyBaseSliceMismatch)?;
7174
}
72-
0 => return Err(Error::UnsupportedCommandCode),
75+
0 => return Err(apply::Error::UnsupportedCommandCode),
7376
size => {
7477
std::io::Write::write(&mut target, &data[i..i + *size as usize])
75-
.map_err(|_e| Error::DeltaCopyDataSliceMismatch)?;
78+
.map_err(|_e| apply::Error::DeltaCopyDataSliceMismatch)?;
7679
i += *size as usize;
7780
}
7881
}

gix-pack/src/data/file/decode/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub enum Error {
2020
#[error("Entry too large to fit in memory")]
2121
OutOfMemory,
2222
#[error(transparent)]
23-
Delta(#[from] crate::data::delta::Error),
23+
Delta(#[from] crate::data::delta::apply::Error),
2424
}
2525

2626
impl From<TryReserveError> for Error {

gix-pack/src/data/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,5 @@ impl File {
128128
}
129129
}
130130

131-
pub(crate) mod delta;
131+
///
132+
pub mod delta;

0 commit comments

Comments
 (0)