1+ use crate :: { bstr:: ByteVec , name:: is_pseudo_ref, Category , FullName , FullNameRef , Namespace , PartialNameRef } ;
12use gix_object:: bstr:: { BStr , BString , ByteSlice } ;
23use std:: { borrow:: Borrow , path:: Path } ;
34
4- use crate :: { bstr:: ByteVec , name:: is_pseudo_ref, Category , FullName , FullNameRef , Namespace , PartialNameRef } ;
5-
65impl TryFrom < & str > for FullName {
76 type Error = gix_validate:: reference:: name:: Error ;
87
@@ -165,6 +164,8 @@ impl FullNameRef {
165164impl Category < ' _ > {
166165 /// As the inverse of [`FullNameRef::category_and_short_name()`], use the prefix of this category alongside
167166 /// the `short_name` to create a valid fully qualified [reference name](FullName).
167+ ///
168+ /// If `short_name` already contains the prefix that it would receive (and is thus a full name), no duplication will occur.
168169 pub fn to_full_name < ' a > ( & self , short_name : impl Into < & ' a BStr > ) -> Result < FullName , crate :: name:: Error > {
169170 let mut out: BString = self . prefix ( ) . into ( ) ;
170171 let short_name = short_name. into ( ) ;
@@ -185,8 +186,12 @@ impl Category<'_> {
185186 | Category :: PseudoRef
186187 | Category :: MainPseudoRef => short_name,
187188 } ;
188- out. extend_from_slice ( partial_name) ;
189- FullName :: try_from ( out)
189+ if out. is_empty ( ) || !partial_name. starts_with ( & out) {
190+ out. extend_from_slice ( partial_name) ;
191+ FullName :: try_from ( out)
192+ } else {
193+ FullName :: try_from ( partial_name. as_bstr ( ) )
194+ }
190195 }
191196}
192197
0 commit comments