use std::borrow::Cow;
use bstr::BStr;
use gix_hash::oid;
use crate::RefSpecRef;
#[derive(Default, Debug, Clone)]
pub struct MatchGroup<'a> {
pub specs: Vec<RefSpecRef<'a>>,
}
pub mod match_lhs {
use crate::{match_group::Mapping, MatchGroup};
#[derive(Debug, Clone)]
pub struct Outcome<'spec, 'item> {
pub group: MatchGroup<'spec>,
pub mappings: Vec<Mapping<'item, 'spec>>,
}
}
pub mod match_rhs {
use crate::{match_group::Mapping, MatchGroup};
#[derive(Debug, Clone)]
pub struct Outcome<'spec, 'item> {
pub group: MatchGroup<'spec>,
pub mappings: Vec<Mapping<'spec, 'item>>,
}
}
#[derive(Debug, Copy, Clone)]
pub struct Item<'a> {
pub full_ref_name: &'a BStr,
pub target: &'a oid,
pub object: Option<&'a oid>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SourceRef<'a> {
FullName(Cow<'a, BStr>),
ObjectId(gix_hash::ObjectId),
}
impl SourceRef<'_> {
pub fn into_owned(self) -> Source {
match self {
SourceRef::ObjectId(id) => Source::ObjectId(id),
SourceRef::FullName(name) => Source::FullName(name.into_owned().into()),
}
}
}
impl std::fmt::Display for SourceRef<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SourceRef::FullName(name) => name.fmt(f),
SourceRef::ObjectId(id) => id.fmt(f),
}
}
}
pub type Source = SourceRef<'static>;
#[derive(Debug, Clone)]
pub struct Mapping<'a, 'b> {
pub item_index: Option<usize>,
pub lhs: SourceRef<'a>,
pub rhs: Option<Cow<'b, BStr>>,
pub spec_index: usize,
}
impl std::hash::Hash for Mapping<'_, '_> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.lhs.hash(state);
self.rhs.hash(state);
}
}