git-ref-format: add QualifiedPattern and NamespacedPattern

There was no mechanism for building refspec patterns that included
namespaces.

To get around this limitation, QualifiedPattern and NamespacedPattern
are added to the refspec module.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny
2022-11-18 10:49:22 +00:00
parent b98c9aac03
commit 6479ba091f
4 changed files with 366 additions and 3 deletions
+15 -1
View File
@@ -9,7 +9,14 @@ use std::{
ops::Deref,
};
use crate::{lit, name, Component, RefStr, RefString};
use crate::{
lit,
name,
refspec::{PatternStr, QualifiedPattern},
Component,
RefStr,
RefString,
};
/// A fully-qualified refname.
///
@@ -74,6 +81,13 @@ impl<'a> Qualified<'a> {
Qualified(self.0.join(other).into())
}
pub fn to_pattern<P>(&self, pattern: P) -> QualifiedPattern
where
P: AsRef<PatternStr>,
{
QualifiedPattern(Cow::Owned(RefStr::to_pattern(self, pattern.as_ref())))
}
#[inline]
pub fn to_namespaced(&self) -> Option<Namespaced> {
self.0.as_ref().into()