use crate::content_diff::DiffLimits;
use crate::{ObjectId, ReadLimits};
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub struct Hunk {
pub commit: ObjectId,
pub original_path: Vec<u8>,
pub original_start: usize,
pub final_start: usize,
pub line_count: usize,
}
#[derive(Clone, Copy, Debug)]
#[non_exhaustive]
pub struct Limits {
pub max_steps: usize,
pub max_lines: usize,
pub max_bytes: usize,
pub read: ReadLimits,
pub diff: DiffLimits,
pub rewrites: crate::rewrites::Limits,
}
impl Default for Limits {
fn default() -> Self {
Self {
max_steps: 100_000,
max_lines: 1_000_000,
max_bytes: 512 * 1024 * 1024,
read: ReadLimits::default(),
diff: DiffLimits::default(),
rewrites: crate::rewrites::Limits::default(),
}
}
}
impl Limits {
#[must_use]
pub fn with_max_steps(mut self, value: usize) -> Self {
self.max_steps = value;
self
}
#[must_use]
pub fn with_max_lines(mut self, value: usize) -> Self {
self.max_lines = value;
self
}
#[must_use]
pub fn with_max_bytes(mut self, value: usize) -> Self {
self.max_bytes = value;
self
}
#[must_use]
pub fn with_read(mut self, value: ReadLimits) -> Self {
self.read = value;
self
}
#[must_use]
pub fn with_diff(mut self, value: DiffLimits) -> Self {
self.diff = value;
self
}
#[must_use]
pub fn with_rewrites(mut self, value: crate::rewrites::Limits) -> Self {
self.rewrites = value;
self
}
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("blame cancelled")]
Cancelled,
#[error("blame {0} limit exceeded")]
Limit(&'static str),
#[error("invalid blame path")]
InvalidPath,
#[error("blame path is absent")]
Absent,
#[error("blame requires a regular file")]
NotFile,
#[error("binary blame is unsupported")]
Binary,
#[error("blame reached shallow boundary {0}")]
Shallow(ObjectId),
#[error("blame rename inference was incomplete")]
IncompleteRenames,
#[error(transparent)]
Operation(#[from] crate::Error),
}