File tree Expand file tree Collapse file tree 4 files changed +9
-7
lines changed
git-repository/src/reference Expand file tree Collapse file tree 4 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -109,8 +109,8 @@ impl FullName {
109
109
/// Strip well-known prefixes from the name and return it.
110
110
///
111
111
/// If there is no such prefix, the original name is returned.
112
- pub fn strip_prefix ( & self ) -> & BStr {
113
- self . to_ref ( ) . strip_prefix ( )
112
+ pub fn shorten ( & self ) -> & BStr {
113
+ self . to_ref ( ) . shorten ( )
114
114
}
115
115
116
116
/// Classify this name, or return `None` if it's unclassified.
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ impl<'a> FullNameRef<'a> {
37
37
/// Strip well-known prefixes from the name and return it.
38
38
///
39
39
/// If there is no such prefix, the original name is returned.
40
- pub fn strip_prefix ( & self ) -> & ' a BStr {
40
+ pub fn shorten ( & self ) -> & ' a BStr {
41
41
let n = self . as_bstr ( ) ;
42
42
n. strip_prefix ( b"refs/tags/" )
43
43
. or_else ( || n. strip_prefix ( b"refs/heads/" ) )
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ fn file_name() {
7
7
assert_eq ! ( name. to_ref( ) . file_name( ) , "main" ) ;
8
8
}
9
9
#[ test]
10
- fn strip_prefix ( ) {
10
+ fn shorten_and_category ( ) {
11
11
for ( input, expected, category) in [
12
12
( "refs/tags/tag-name" , "tag-name" , Category :: Tag ) ,
13
13
( "refs/heads/main" , "main" , Category :: LocalBranch ) ,
@@ -16,16 +16,16 @@ fn strip_prefix() {
16
16
] {
17
17
let name: git_ref:: FullName = input. try_into ( ) . unwrap ( ) ;
18
18
let category = Some ( category) ;
19
- assert_eq ! ( name. to_ref( ) . strip_prefix ( ) , expected) ;
20
- assert_eq ! ( name. strip_prefix ( ) , expected) ;
19
+ assert_eq ! ( name. to_ref( ) . shorten ( ) , expected) ;
20
+ assert_eq ! ( name. shorten ( ) , expected) ;
21
21
assert_eq ! ( name. category( ) , category) ;
22
22
assert_eq ! ( name. to_ref( ) . category( ) , category) ;
23
23
}
24
24
25
25
let special = "HEAD" ;
26
26
let name: git_ref:: FullName = special. try_into ( ) . unwrap ( ) ;
27
27
assert_eq ! (
28
- name. strip_prefix ( ) ,
28
+ name. shorten ( ) ,
29
29
special,
30
30
"the whole name is returned if there is no prefix"
31
31
) ;
Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ use crate::ext::ObjectIdExt;
15
15
16
16
pub mod log;
17
17
18
+ pub use git_ref:: { Category , Kind } ;
19
+
18
20
/// Access
19
21
impl < ' repo > Reference < ' repo > {
20
22
/// Return the target to which this reference points to.
You can’t perform that action at this time.
0 commit comments