11using System . Globalization ;
2- using System . IO ;
3- using System . Linq ;
4- using System . Reflection ;
52using LibGit2Sharp . Core ;
63
74namespace LibGit2Sharp
@@ -11,8 +8,6 @@ namespace LibGit2Sharp
118 /// </summary>
129 public class Version
1310 {
14- private readonly Assembly assembly = typeof ( Repository ) . Assembly ;
15-
1611 /// <summary>
1712 /// Needed for mocking purposes.
1813 /// </summary>
@@ -42,23 +37,15 @@ public virtual BuiltInFeatures Features
4237 /// <summary>
4338 /// Returns the SHA hash for the libgit2 library.
4439 /// </summary>
45- public virtual string LibGit2CommitSha
46- {
47- get { return RetrieveAbbrevShaFrom ( "libgit2_hash.txt" ) ; }
48- }
40+ public virtual string LibGit2CommitSha => RetrieveAbbrevShaFrom ( AssemblyCommitIds . LibGit2CommitSha ) ;
4941
5042 /// <summary>
5143 /// Returns the SHA hash for the LibGit2Sharp library.
5244 /// </summary>
53- public virtual string LibGit2SharpCommitSha
54- {
55- get { return RetrieveAbbrevShaFrom ( "libgit2sharp_hash.txt" ) ; }
56- }
45+ public virtual string LibGit2SharpCommitSha => RetrieveAbbrevShaFrom ( AssemblyCommitIds . LibGit2SharpCommitSha ) ;
5746
58- private string RetrieveAbbrevShaFrom ( string name )
47+ private string RetrieveAbbrevShaFrom ( string sha )
5948 {
60- string sha = ReadContentFromResource ( assembly , name ) ?? "unknown" ;
61-
6249 var index = sha . Length > 7 ? 7 : sha . Length ;
6350 return sha . Substring ( 0 , index ) ;
6451 }
@@ -68,7 +55,7 @@ private string RetrieveAbbrevShaFrom(string name)
6855 /// </summary>
6956 /// <para>
7057 /// The format of the version number is as follows:
71- /// <para>Major.Minor.Patch- LibGit2Sharp_abbrev_hash- libgit2_abbrev_hash (x86|x64 - features)</para>
58+ /// <para>Major.Minor.Patch+g{ LibGit2Sharp_abbrev_hash}.libgit2-{ libgit2_abbrev_hash} (x86|x64 - features)</para>
7259 /// </para>
7360 /// <returns></returns>
7461 public override string ToString ( )
@@ -86,14 +73,5 @@ private string RetrieveVersion()
8673 Platform . ProcessorArchitecture ,
8774 features ) ;
8875 }
89-
90- private string ReadContentFromResource ( Assembly assembly , string partialResourceName )
91- {
92- string name = string . Format ( CultureInfo . InvariantCulture , "LibGit2Sharp.{0}" , partialResourceName ) ;
93- using ( var sr = new StreamReader ( assembly . GetManifestResourceStream ( name ) ) )
94- {
95- return sr . ReadLine ( ) ;
96- }
97- }
9876 }
9977}
0 commit comments