Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2012-03-31 20:25:19 +0400
committernulltoken <emeric.fermas@gmail.com>2012-04-01 01:01:10 +0400
commit2ca19130998281001615901598cc600e5d6dbbcd (patch)
tree0ee4ce0eee5dacbf4afee2972ef454283e1d486e /LibGit2Sharp
parent412010c9316301bb3f7b588bf61018141bd41d9f (diff)
Add Repository.Version static property
This property returns a string containing the LibGit2Sharp version number, the commit hash it's been built against (if available), the libgit2 commit hash and the processor architecture.
Diffstat (limited to 'LibGit2Sharp')
-rw-r--r--LibGit2Sharp/Core/NativeMethods.cs16
-rw-r--r--LibGit2Sharp/LibGit2Sharp.csproj6
-rw-r--r--LibGit2Sharp/Repository.cs40
-rw-r--r--LibGit2Sharp/libgit2_hash.txt1
-rw-r--r--LibGit2Sharp/libgit2sharp_hash.txt1
5 files changed, 62 insertions, 2 deletions
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index a9864750..9778d306 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -18,8 +18,7 @@ namespace LibGit2Sharp.Core
{
string originalAssemblypath = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath;
- //TODO: When amd64 version of libgit2.dll is available, value this depending of the size of an IntPtr
- const string currentArchSubPath = "NativeBinaries/x86";
+ string currentArchSubPath = "NativeBinaries/" + ProcessorArchitecture;
string path = Path.Combine(Path.GetDirectoryName(originalAssemblypath), currentArchSubPath);
@@ -37,6 +36,19 @@ namespace LibGit2Sharp.Core
git_threads_shutdown();
}
+ public static string ProcessorArchitecture
+ {
+ get
+ {
+ //TODO: When amd64 version of libgit2.dll is available, uncomment the following lines
+ //if (IntPtr.Size == 8)
+ //{
+ // return "amd64";
+ //}
+
+ return "x86";
+ }
+ }
private static bool IsRunningOnLinux()
{
// see http://mono-project.com/FAQ%3a_Technical#Mono_Platforms
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 3f3b2a23..042125cc 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -132,6 +132,12 @@
<ItemGroup>
<CodeAnalysisDictionary Include="CustomDictionary.xml" />
</ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="libgit2_hash.txt" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="libgit2sharp_hash.txt" />
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>
diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs
index b2c35db3..e44f1d06 100644
--- a/LibGit2Sharp/Repository.cs
+++ b/LibGit2Sharp/Repository.cs
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
+using System.IO;
+using System.Reflection;
using LibGit2Sharp.Core;
using LibGit2Sharp.Core.Compat;
using LibGit2Sharp.Core.Handles;
@@ -22,6 +24,7 @@ namespace LibGit2Sharp
private readonly Lazy<RepositoryInformation> info;
private readonly bool isBare;
private readonly List<SafeHandleBase> handlesToCleanup = new List<SafeHandleBase>();
+ private static readonly Lazy<string> versionRetriever = new Lazy<string>(RetrieveVersion);
/// <summary>
/// Initializes a new instance of the <see cref = "Repository" /> class.
@@ -356,5 +359,42 @@ namespace LibGit2Sharp
{
handlesToCleanup.Add(handleToCleanup);
}
+
+ /// <summary>
+ /// Gets the current LibGit2Sharp version.
+ /// <para>
+ /// The format of the version number is as follows:
+ /// <para>Major.Minor.Patch-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64)</para>
+ /// </para>
+ /// </summary>
+ public static string Version
+ {
+ get { return versionRetriever.Value; }
+ }
+
+ private static string RetrieveVersion()
+ {
+ Assembly assembly = typeof(Repository).Assembly;
+
+ Version version = assembly.GetName().Version;
+
+ string libgit2Hash = ReadContentFromResource(assembly, "libgit2_hash.txt");
+ string libgit2sharpHash = ReadContentFromResource(assembly, "libgit2sharp_hash.txt");
+
+ return string.Format("{0}-{1}-{2} ({3})",
+ version.ToString(3),
+ libgit2sharpHash.Substring(0, 7),
+ libgit2Hash.Substring(0,7),
+ NativeMethods.ProcessorArchitecture
+ );
+ }
+
+ private static string ReadContentFromResource(Assembly assembly, string partialResourceName)
+ {
+ using (var sr = new StreamReader(assembly.GetManifestResourceStream(string.Format("LibGit2Sharp.{0}", partialResourceName))))
+ {
+ return sr.ReadLine();
+ }
+ }
}
}
diff --git a/LibGit2Sharp/libgit2_hash.txt b/LibGit2Sharp/libgit2_hash.txt
new file mode 100644
index 00000000..dab8956f
--- /dev/null
+++ b/LibGit2Sharp/libgit2_hash.txt
@@ -0,0 +1 @@
+a17e882fab4e190d5a052cbc9cf6a238a9166a7c
diff --git a/LibGit2Sharp/libgit2sharp_hash.txt b/LibGit2Sharp/libgit2sharp_hash.txt
new file mode 100644
index 00000000..0faec602
--- /dev/null
+++ b/LibGit2Sharp/libgit2sharp_hash.txt
@@ -0,0 +1 @@
+unknown