use std::borrow::Cow;
use bstr::{BStr, BString};
use git_hash::oid;
use crate::RefSpecRef;
#[derive(Default, Debug, Clone)]
pub struct MatchGroup<'a> {
pub specs: Vec<RefSpecRef<'a>>,
}
#[derive(Debug, Clone)]
pub struct Outcome<'spec, 'item> {
pub group: MatchGroup<'spec>,
pub mappings: Vec<Mapping<'item, 'spec>>,
}
#[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, Copy, Clone, PartialEq, Eq, Hash)]
pub enum SourceRef<'a> {
FullName(&'a BStr),
ObjectId(git_hash::ObjectId),
}
impl SourceRef<'_> {
pub fn to_owned(&self) -> Source {
match self {
SourceRef::ObjectId(id) => Source::ObjectId(*id),
SourceRef::FullName(name) => Source::FullName((*name).to_owned()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Source {
FullName(BString),
ObjectId(git_hash::ObjectId),
}
impl std::fmt::Display for Source {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Source::FullName(name) => name.fmt(f),
Source::ObjectId(id) => id.fmt(f),
}
}
}
#[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);
}
}