use super::{EntryKey, Kind, TreeData};
#[derive(Debug, PartialEq, Eq)]
pub enum EnsureBlockError {
BadDirname(Vec<u8>),
}
impl std::fmt::Display for EnsureBlockError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
EnsureBlockError::BadDirname(dirname) => write!(f, "bad dirname {:?}", dirname),
}
}
}
impl std::error::Error for EnsureBlockError {}
#[derive(Debug, PartialEq, Eq)]
pub enum EntriesToStateError {
Empty,
MissingRootRow { key: EntryKey },
SplitFailed(SplitRootError),
}
impl std::fmt::Display for EntriesToStateError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
EntriesToStateError::Empty => write!(f, "new_entries is empty"),
EntriesToStateError::MissingRootRow { key } => {
write!(
f,
"Missing root row ({:?}, {:?}, {:?})",
key.dirname, key.basename, key.file_id
)
}
EntriesToStateError::SplitFailed(err) => {
write!(f, "split_root_dirblock_into_contents: {}", err)
}
}
}
}
impl std::error::Error for EntriesToStateError {}
#[derive(Debug, Clone)]
pub struct BasisAdd {
pub old_path: Option<Vec<u8>>,
pub new_path: Vec<u8>,
pub file_id: Vec<u8>,
pub new_details: TreeData,
pub real_add: bool,
}
#[derive(Debug, PartialEq, Eq)]
pub enum BasisApplyError {
Invalid {
path: Vec<u8>,
file_id: Vec<u8>,
reason: String,
},
NotImplemented { reason: String },
Internal { reason: String },
NotVersioned { path: Vec<u8> },
MismatchedEntryFileId {
new_path: Vec<u8>,
file_id: Vec<u8>,
entry_debug: String,
},
NewPathWithoutEntry { new_path: Vec<u8>, file_id: Vec<u8> },
}
impl std::fmt::Display for BasisApplyError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
BasisApplyError::Invalid {
path,
file_id,
reason,
} => write!(
f,
"inconsistent delta at {:?} ({:?}): {}",
path, file_id, reason
),
BasisApplyError::NotImplemented { reason } => {
write!(f, "not implemented: {}", reason)
}
BasisApplyError::Internal { reason } => write!(f, "internal error: {}", reason),
BasisApplyError::NotVersioned { path } => {
write!(f, "not versioned: {:?}", path)
}
BasisApplyError::MismatchedEntryFileId {
new_path,
file_id,
entry_debug,
} => write!(
f,
"mismatched entry file_id at {:?} ({:?}): {}",
new_path, file_id, entry_debug
),
BasisApplyError::NewPathWithoutEntry { new_path, file_id } => {
write!(
f,
"new_path with no entry at {:?} ({:?})",
new_path, file_id
)
}
}
}
}
impl std::error::Error for BasisApplyError {}
#[derive(Debug, Clone)]
pub struct FlatDeltaEntry {
pub old_path: Option<Vec<u8>>,
pub new_path: Option<Vec<u8>>,
pub file_id: Vec<u8>,
pub parent_id: Option<Vec<u8>>,
pub minikind: Kind,
pub executable: bool,
pub fingerprint: Vec<u8>,
}
#[derive(Debug, Clone)]
pub struct FlatBasisDeltaEntry {
pub old_path: Option<Vec<u8>>,
pub new_path: Option<Vec<u8>>,
pub file_id: Vec<u8>,
pub parent_id: Option<Vec<u8>>,
pub details: Option<(Kind, Vec<u8>, u64, bool, Vec<u8>)>,
}
#[derive(Debug, Clone)]
pub struct ValidateError(pub String);
impl std::fmt::Display for ValidateError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.0)
}
}
impl std::error::Error for ValidateError {}
#[derive(Debug, PartialEq, Eq)]
pub enum MakeAbsentError {
BlockNotFound { key: EntryKey },
EntryNotFound { key: EntryKey },
UpdateBlockNotFound { key: EntryKey },
UpdateEntryNotFound { key: EntryKey },
BadRow { key: EntryKey },
}
impl std::fmt::Display for MakeAbsentError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
MakeAbsentError::BlockNotFound { key } => {
write!(f, "could not find block for {:?}", key)
}
MakeAbsentError::EntryNotFound { key } => {
write!(f, "could not find entry for {:?}", key)
}
MakeAbsentError::UpdateBlockNotFound { key } => {
write!(f, "could not find block for {:?}", key)
}
MakeAbsentError::UpdateEntryNotFound { key } => {
write!(f, "could not find entry for {:?}", key)
}
MakeAbsentError::BadRow { key } => write!(f, "bad row for {:?}", key),
}
}
}
impl std::error::Error for MakeAbsentError {}
#[derive(Debug, PartialEq, Eq)]
pub enum SplitRootError {
MissingSentinels,
BadSecondSentinel {
dirname: Vec<u8>,
entry_count: usize,
},
}
impl std::fmt::Display for SplitRootError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SplitRootError::MissingSentinels => {
write!(f, "dirblocks missing the expected sentinel entries")
}
SplitRootError::BadSecondSentinel {
dirname,
entry_count,
} => {
write!(
f,
"bad dirblock start ({:?}, {} entries)",
dirname, entry_count
)
}
}
}
}
#[derive(Debug)]
pub enum LoadError {
Header(super::HeaderError),
Dirblocks(super::DirblocksError),
SplitRoot(SplitRootError),
}
impl std::fmt::Display for LoadError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
LoadError::Header(e) => write!(f, "dirstate header: {e}"),
LoadError::Dirblocks(e) => write!(f, "dirstate dirblocks: {e}"),
LoadError::SplitRoot(e) => write!(f, "dirstate root block: {e}"),
}
}
}
impl std::error::Error for LoadError {}
impl std::error::Error for SplitRootError {}
#[derive(Debug)]
pub enum UpdateEntryError {
EntryNotFound,
UnexpectedKind(Kind),
Io(std::io::Error),
Other(String),
}
impl std::fmt::Display for UpdateEntryError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
UpdateEntryError::EntryNotFound => f.write_str("update_entry: entry not found"),
UpdateEntryError::UnexpectedKind(k) => {
write!(f, "update_entry: unexpected minikind {:?}", k)
}
UpdateEntryError::Io(e) => write!(f, "update_entry: i/o error: {}", e),
UpdateEntryError::Other(s) => write!(f, "update_entry: {}", s),
}
}
}
impl std::error::Error for UpdateEntryError {}
#[derive(Debug, PartialEq, Eq)]
pub enum SetPathIdError {
NonRootPath,
Internal { reason: String },
}
impl std::fmt::Display for SetPathIdError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SetPathIdError::NonRootPath => write!(f, "set_path_id only supports the root path"),
SetPathIdError::Internal { reason } => write!(f, "internal error: {}", reason),
}
}
}
impl std::error::Error for SetPathIdError {}
#[derive(Debug, PartialEq, Eq)]
pub enum AddError {
DuplicateFileId { file_id: Vec<u8>, info: String },
AlreadyAdded { path: Vec<u8> },
NotVersioned { path: Vec<u8> },
AlreadyAddedAssertion { basename: Vec<u8>, file_id: Vec<u8> },
Internal { reason: String },
InvalidNormalization { path: String },
InvalidEntryName { name: String },
}
impl std::fmt::Display for AddError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
AddError::DuplicateFileId { file_id, info } => {
write!(f, "duplicate file_id {:?}: {}", file_id, info)
}
AddError::AlreadyAdded { path } => {
write!(f, "adding already added path {:?}", path)
}
AddError::NotVersioned { path } => write!(f, "not versioned: {:?}", path),
AddError::AlreadyAddedAssertion { basename, file_id } => {
write!(f, "{:?}({:?}) already added", basename, file_id)
}
AddError::Internal { reason } => write!(f, "internal error: {}", reason),
AddError::InvalidNormalization { path } => {
write!(f, "path not unicode-normalized: {:?}", path)
}
AddError::InvalidEntryName { name } => write!(f, "invalid entry name: {:?}", name),
}
}
}
impl std::error::Error for AddError {}