File tree Expand file tree Collapse file tree 1 file changed +13
-13
lines changed
src/NerdBank.GitVersioning/ManagedGit Expand file tree Collapse file tree 1 file changed +13
-13
lines changed Original file line number Diff line number Diff line change @@ -11,28 +11,28 @@ internal class GitReferenceReader
1111
1212 public static object ReadReference ( Stream stream )
1313 {
14- if ( stream . Length == 41 )
15- {
16- Span < byte > objectId = stackalloc byte [ 40 ] ;
17- stream . Read ( objectId ) ;
14+ Span < byte > reference = stackalloc byte [ ( int ) stream . Length ] ;
15+ stream . ReadAll ( reference ) ;
16+
17+ return ReadReference ( reference ) ;
18+ }
1819
19- return GitObjectId . ParseHex ( objectId ) ;
20+ public static object ReadReference ( Span < byte > value )
21+ {
22+ if ( value . Length == 41 && ! value . StartsWith ( RefPrefix ) )
23+ {
24+ // Skip the trailing \n
25+ return GitObjectId . ParseHex ( value . Slice ( 0 , 40 ) ) ;
2026 }
2127 else
2228 {
23- Span < byte > prefix = stackalloc byte [ RefPrefix . Length ] ;
24- stream . Read ( prefix ) ;
25-
26- if ( ! prefix . SequenceEqual ( RefPrefix ) )
29+ if ( ! value . StartsWith ( RefPrefix ) )
2730 {
2831 throw new GitException ( ) ;
2932 }
3033
3134 // Skip the terminating \n character
32- Span < byte > reference = stackalloc byte [ ( int ) stream . Length - RefPrefix . Length - 1 ] ;
33- stream . Read ( reference ) ;
34-
35- return GitRepository . GetString ( reference ) ;
35+ return GitRepository . GetString ( value . Slice ( RefPrefix . Length , value . Length - RefPrefix . Length - 1 ) ) ;
3636 }
3737 }
3838 }
You can’t perform that action at this time.
0 commit comments