use std::collections::HashSet;
use gix_hash::ObjectId;
use gix_macros::momo;
use gix_revision::spec::parse;
use crate::{bstr::BStr, revision::Spec, Repository};
mod types;
pub use types::{Error, ObjectKindHint, Options, RefsHint};
pub mod single {
use crate::bstr::BString;
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error(transparent)]
Parse(#[from] super::Error),
#[error("revspec {spec:?} did not resolve to a single object")]
RangedRev { spec: BString },
}
}
pub mod error;
impl<'repo> Spec<'repo> {
#[momo]
pub fn from_bstr<'a>(spec: impl Into<&'a BStr>, repo: &'repo Repository, opts: Options) -> Result<Self, Error> {
let mut delegate = Delegate::new(repo, opts);
match gix_revision::spec::parse(spec.into(), &mut delegate) {
Err(parse::Error::Delegate) => Err(delegate.into_err()),
Err(err) => Err(err.into()),
Ok(()) => delegate.into_rev_spec(),
}
}
}
struct Delegate<'repo> {
refs: [Option<gix_ref::Reference>; 2],
objs: [Option<HashSet<ObjectId>>; 2],
ambiguous_objects: [Option<HashSet<ObjectId>>; 2],
idx: usize,
kind: Option<gix_revision::spec::Kind>,
opts: Options,
err: Vec<Error>,
prefix: [Option<gix_hash::Prefix>; 2],
last_call_was_disambiguate_prefix: [bool; 2],
repo: &'repo Repository,
}
mod delegate;