@@ -156,6 +156,35 @@ impl FullNameRef {
156
156
}
157
157
}
158
158
159
+ /// Conversion
160
+ impl Category < ' _ > {
161
+ /// As the inverse of [`FullNameRef::category_and_short_name()`], use the prefix of this category alongside
162
+ /// the `short_name` to create a valid fully qualified [reference name](FullName).
163
+ pub fn to_full_name < ' a > ( & self , short_name : impl Into < & ' a BStr > ) -> Result < FullName , crate :: name:: Error > {
164
+ let mut out: BString = self . prefix ( ) . into ( ) ;
165
+ let short_name = short_name. into ( ) ;
166
+ let partial_name = match self {
167
+ Category :: Note => short_name. strip_prefix ( "notes/" . as_bytes ( ) ) . unwrap_or ( short_name) ,
168
+ Category :: MainRef => short_name. strip_prefix ( "refs/" . as_bytes ( ) ) . unwrap_or ( short_name) ,
169
+ Category :: LinkedPseudoRef { name } | Category :: LinkedRef { name } => {
170
+ out. extend_from_slice ( name) ;
171
+ out. push ( b'/' ) ;
172
+ short_name
173
+ }
174
+ Category :: Bisect => short_name. strip_prefix ( "bisect/" . as_bytes ( ) ) . unwrap_or ( short_name) ,
175
+ Category :: Rewritten => short_name. strip_prefix ( "rewritten/" . as_bytes ( ) ) . unwrap_or ( short_name) ,
176
+ Category :: WorktreePrivate => short_name. strip_prefix ( "worktree/" . as_bytes ( ) ) . unwrap_or ( short_name) ,
177
+ Category :: Tag
178
+ | Category :: LocalBranch
179
+ | Category :: RemoteBranch
180
+ | Category :: PseudoRef
181
+ | Category :: MainPseudoRef => short_name,
182
+ } ;
183
+ out. extend_from_slice ( partial_name) ;
184
+ FullName :: try_from ( out)
185
+ }
186
+ }
187
+
159
188
impl FullName {
160
189
/// Convert this name into the relative path, lossily, identifying the reference location relative to a repository
161
190
pub fn to_path ( & self ) -> & Path {
0 commit comments