Skip to content

Commit a889aa9

Browse files
committed
Added libgit2 features to Repository.Version
Introduced NativeMethods.Capabilities . Added CanCreateValidVersionString() test . Displaced NativeMethods CompiledFeatures to Proxy Remove irrelevant region on Proxy Make Proxy.get_compiled_features match get_libgit2_features . Add mising [Flags] tag on GitBuiltInFeatures . Remote trailling whitespace in Proxy Resolves #676
1 parent d4a7489 commit a889aa9

File tree

6 files changed

+52
-3
lines changed

6 files changed

+52
-3
lines changed

LibGit2Sharp.Tests/RepositoryFixture.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ public void CanCreateStandardRepo()
8585
}
8686
}
8787

88+
[Fact]
89+
public void CanRetrieveValidVersionString()
90+
{
91+
string versionInfo = Repository.Version;
92+
93+
Assert.NotNull(versionInfo);
94+
}
95+
8896
[Fact]
8997
public void CanCreateStandardRepoAndSpecifyAFolderWhichWillContainTheNewlyCreatedGitDirectory()
9098
{
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace LibGit2Sharp.Core
7+
{
8+
/// <summary>
9+
/// Flags to indentify libgit compiled features.
10+
/// </summary>
11+
[Flags]
12+
internal enum GitBuiltInFeatures
13+
{
14+
Threads = (1 << 0),
15+
Https = (1 << 1),
16+
Ssh = (1 << 2),
17+
}
18+
}

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,9 @@ internal static extern int git_diff_find_similar(
486486
[DllImport(libgit2)]
487487
internal static extern IntPtr git_diff_get_delta(DiffSafeHandle diff, UIntPtr idx);
488488

489+
[DllImport(libgit2)]
490+
internal static extern int git_libgit2_features();
491+
489492
[DllImport(libgit2)]
490493
internal static extern int git_graph_ahead_behind(out UIntPtr ahead, out UIntPtr behind, RepositorySafeHandle repo, ref GitOid one, ref GitOid two);
491494

LibGit2Sharp/Core/Proxy.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2721,6 +2721,24 @@ public static ObjectId git_treebuilder_write(RepositorySafeHandle repo, TreeBuil
27212721

27222722
#endregion
27232723

2724+
#region git_libgit2_
2725+
2726+
/// <summary>
2727+
/// Returns the features with which libgit2 was compiled.
2728+
/// </summary>
2729+
public static string git_libgit2_features()
2730+
{
2731+
GitBuiltInFeatures features;
2732+
2733+
int flags = NativeMethods.git_libgit2_features();
2734+
2735+
features = (GitBuiltInFeatures)Enum.ToObject(typeof(GitBuiltInFeatures), flags);
2736+
2737+
return features.ToString();
2738+
}
2739+
2740+
#endregion
2741+
27242742
private static ICollection<TResult> git_foreach<T, TResult>(
27252743
Func<T, TResult> resultSelector,
27262744
Func<Func<T, IntPtr, int>, int> iterator,

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
<Compile Include="CommitSortStrategies.cs" />
7979
<Compile Include="CompareOptions.cs" />
8080
<Compile Include="ContentChangeStats.cs" />
81+
<Compile Include="Core\GitBuiltInFeatures.cs" />
8182
<Compile Include="Core\GitCredentialType.cs" />
8283
<Compile Include="Core\Handles\PatchSafeHandle.cs" />
8384
<Compile Include="Core\IntPtrExtensions.cs" />

LibGit2Sharp/Repository.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ internal T RegisterForCleanup<T>(T disposable) where T : IDisposable
10111011
/// Gets the current LibGit2Sharp version.
10121012
/// <para>
10131013
/// The format of the version number is as follows:
1014-
/// <para>Major.Minor.Patch-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64)</para>
1014+
/// <para>Major.Minor.Patch-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64 - capabilities)</para>
10151015
/// </para>
10161016
/// </summary>
10171017
public static string Version
@@ -1030,11 +1030,12 @@ private static string RetrieveVersion()
10301030

10311031
return string.Format(
10321032
CultureInfo.InvariantCulture,
1033-
"{0}-{1}-{2} ({3})",
1033+
"{0}-{1}-{2} ({3} - {4})",
10341034
version.ToString(3),
10351035
libgit2sharpHash.Substring(0, 7),
10361036
libgit2Hash.Substring(0, 7),
1037-
NativeMethods.ProcessorArchitecture
1037+
NativeMethods.ProcessorArchitecture,
1038+
Proxy.git_libgit2_features()
10381039
);
10391040
}
10401041

0 commit comments

Comments
 (0)