Skip to content

Commit 9060ae1

Browse files
committed
change!: use separate error types for the eol and ident filters
Prepare for hashing becoming fallible.
1 parent 1efbe16 commit 9060ae1

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

gix-filter/src/eol/convert_to_worktree.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,22 @@ use crate::{
55
eol::{AttributesDigest, Configuration, Mode, Stats},
66
};
77

8+
/// The error produced by [`convert_to_worktree()`].
9+
#[derive(Debug, thiserror::Error)]
10+
#[allow(missing_docs)]
11+
pub enum Error {
12+
#[error("Could not allocate buffer")]
13+
OutOfMemory(#[from] std::collections::TryReserveError),
14+
}
15+
816
/// Convert all `\n` in `src` to `crlf` if `digest` and `config` indicate it, returning `true` if `buf` holds the result, or `false`
917
/// if no change was made after all.
1018
pub fn convert_to_worktree(
1119
src: &[u8],
1220
digest: AttributesDigest,
1321
buf: &mut Vec<u8>,
1422
config: Configuration,
15-
) -> Result<bool, std::collections::TryReserveError> {
23+
) -> Result<bool, Error> {
1624
if src.is_empty() || digest.to_eol(config) != Some(Mode::CrLf) {
1725
return Ok(false);
1826
}

gix-filter/src/eol/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
pub mod convert_to_git;
33
pub use convert_to_git::function::convert_to_git;
44

5-
mod convert_to_worktree;
5+
///
6+
pub mod convert_to_worktree;
67
pub use convert_to_worktree::convert_to_worktree;
78

89
mod utils;

gix-filter/src/ident.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ pub fn undo(src: &[u8], buf: &mut Vec<u8>) -> Result<bool, std::collections::Try
4040
Ok(initialized)
4141
}
4242

43+
///
44+
pub mod apply {
45+
/// The error produced by [`super::apply()`].
46+
#[derive(Debug, thiserror::Error)]
47+
#[allow(missing_docs)]
48+
pub enum Error {
49+
#[error("Could not allocate buffer")]
50+
OutOfMemory(#[from] std::collections::TryReserveError),
51+
}
52+
}
53+
4354
/// Substitute all occurrences of `$Id$` with `$Id: <hexsha-of-input>$` if present in `src` and write all changes to `buf`,
4455
/// with `object_hash` being used accordingly. Return `true` if `buf` was written to or `false` if no change was made
4556
/// (as there was nothing to do).
@@ -48,11 +59,7 @@ pub fn undo(src: &[u8], buf: &mut Vec<u8>) -> Result<bool, std::collections::Try
4859
///
4960
/// `Git` also tries to cleanup 'stray' substituted `$Id: <hex>$`, but we don't do that, sticking exactly to what ought to be done.
5061
/// The respective code is up to 16 years old and one might assume that `git` by now handles checking and checkout filters correctly.
51-
pub fn apply(
52-
src: &[u8],
53-
object_hash: gix_hash::Kind,
54-
buf: &mut Vec<u8>,
55-
) -> Result<bool, std::collections::TryReserveError> {
62+
pub fn apply(src: &[u8], object_hash: gix_hash::Kind, buf: &mut Vec<u8>) -> Result<bool, apply::Error> {
5663
const HASH_LEN: usize = ": ".len() + gix_hash::Kind::longest().len_in_hex();
5764
let mut id = None;
5865
let mut ofs = 0;

gix-filter/src/pipeline/convert.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ pub mod to_worktree {
4949
#[derive(Debug, thiserror::Error)]
5050
#[allow(missing_docs)]
5151
pub enum Error {
52+
#[error(transparent)]
53+
Ident(#[from] crate::ident::apply::Error),
54+
#[error(transparent)]
55+
Eol(#[from] crate::eol::convert_to_worktree::Error),
5256
#[error(transparent)]
5357
Worktree(#[from] crate::worktree::encode_to_worktree::Error),
5458
#[error(transparent)]
5559
Driver(#[from] crate::driver::apply::Error),
5660
#[error(transparent)]
5761
Configuration(#[from] super::configuration::Error),
58-
#[error("Could not allocate buffer")]
59-
OutOfMemory(#[from] std::collections::TryReserveError),
6062
}
6163
}
6264

0 commit comments

Comments
 (0)