use crate::{bstr::BString, object, reference};
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
pub enum RefsHint {
#[default]
PreferObjectOnFullLengthHexShaUseRefOtherwise,
PreferObject,
PreferRef,
Fail,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum ObjectKindHint {
Commit,
Committish,
Tree,
Treeish,
Blob,
}
#[derive(Debug, Default, Copy, Clone)]
pub struct Options {
pub refs_hint: RefsHint,
pub object_kind_hint: Option<ObjectKindHint>,
}
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("The rev-spec is malformed and misses a ref name")]
Malformed,
#[error("Unborn heads do not have a reflog yet")]
UnbornHeadsHaveNoRefLog,
#[error("This feature will be implemented once {dependency}")]
Planned { dependency: &'static str },
#[error("Reference {reference:?} does not have a reference log, cannot {action}")]
MissingRefLog { reference: BString, action: &'static str },
#[error("HEAD has {available} prior checkouts and checkout number {desired} is out of range")]
PriorCheckoutOutOfRange { desired: usize, available: usize },
#[error("Reference {:?} has {available} ref-log entries and entry number {desired} is out of range", reference.name.as_bstr())]
RefLogEntryOutOfRange {
reference: gix_ref::Reference,
desired: usize,
available: usize,
},
#[error(
"Commit {oid} has {available} ancestors along the first parent and ancestor number {desired} is out of range"
)]
AncestorOutOfRange {
oid: gix_hash::Prefix,
desired: usize,
available: usize,
},
#[error("Commit {oid} has {available} parents and parent number {desired} is out of range")]
ParentOutOfRange {
oid: gix_hash::Prefix,
desired: usize,
available: usize,
},
#[error("Path {desired_path:?} did not exist in index at stage {desired_stage}{}{}", stage_hint.map(|actual|format!(". It does exist at stage {actual}")).unwrap_or_default(), exists.then(|| ". It exists on disk").unwrap_or(". It does not exist on disk"))]
IndexLookup {
desired_path: BString,
desired_stage: gix_index::entry::Stage,
stage_hint: Option<gix_index::entry::Stage>,
exists: bool,
},
#[error(transparent)]
FindHead(#[from] reference::find::existing::Error),
#[error(transparent)]
Index(#[from] crate::worktree::open_index::Error),
#[error(transparent)]
RevWalkIterInit(#[from] crate::reference::iter::init::Error),
#[error(transparent)]
RevWalkAllReferences(#[from] gix_ref::packed::buffer::open::Error),
#[cfg(feature = "revparse-regex")]
#[error(transparent)]
InvalidRegex(#[from] regex::Error),
#[cfg_attr(
feature = "revparse-regex",
error("None of {commits_searched} commits from {oid} matched regex {regex:?}")
)]
#[cfg_attr(
not(feature = "revparse-regex"),
error("None of {commits_searched} commits from {oid} matched text {regex:?}")
)]
NoRegexMatch {
regex: BString,
oid: gix_hash::Prefix,
commits_searched: usize,
},
#[cfg_attr(
feature = "revparse-regex",
error("None of {commits_searched} commits reached from all references matched regex {regex:?}")
)]
#[cfg_attr(
not(feature = "revparse-regex"),
error("None of {commits_searched} commits reached from all references matched text {regex:?}")
)]
NoRegexMatchAllRefs { regex: BString, commits_searched: usize },
#[error(
"The short hash {prefix} matched both the reference {} and at least one object", reference.name)]
AmbiguousRefAndObject {
prefix: gix_hash::Prefix,
reference: gix_ref::Reference,
},
#[error(transparent)]
IdFromHex(#[from] gix_hash::decode::Error),
#[error(transparent)]
FindReference(#[from] gix_ref::file::find::existing::Error),
#[error(transparent)]
FindObject(#[from] object::find::existing::Error),
#[error(transparent)]
LookupPrefix(#[from] gix_odb::store::prefix::lookup::Error),
#[error(transparent)]
PeelToKind(#[from] object::peel::to_kind::Error),
#[error("Object {oid} was a {actual}, but needed it to be a {expected}")]
ObjectKind {
oid: gix_hash::Prefix,
actual: gix_object::Kind,
expected: gix_object::Kind,
},
#[error(transparent)]
Parse(#[from] gix_revision::spec::parse::Error),
#[error("An object prefixed {prefix} could not be found")]
PrefixNotFound { prefix: gix_hash::Prefix },
#[error("Short id {prefix} is ambiguous. Candidates are:\n{}", info.iter().map(|(oid, info)| format!("\t{oid} {info}")).collect::<Vec<_>>().join("\n"))]
AmbiguousPrefix {
prefix: gix_hash::Prefix,
info: Vec<(gix_hash::Prefix, super::error::CandidateInfo)>,
},
#[error("Could not find path {path:?} in tree {tree} of parent object {object}")]
PathNotFound {
object: gix_hash::Prefix,
tree: gix_hash::Prefix,
path: BString,
},
#[error("{current}")]
Multi {
current: Box<dyn std::error::Error + Send + Sync + 'static>,
#[source]
next: Option<Box<dyn std::error::Error + Send + Sync + 'static>>,
},
#[error(transparent)]
Traverse(#[from] gix_traverse::commit::ancestors::Error),
#[error(transparent)]
Walk(#[from] crate::revision::walk::Error),
#[error("Spec does not contain a single object id")]
SingleNotFound,
}