Skip to content

Commit 4516af5

Browse files
author
Edward Thomson
committed
Introduce GlobalSettings.Features()
1 parent 40ac869 commit 4516af5

File tree

8 files changed

+80
-30
lines changed

8 files changed

+80
-30
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using LibGit2Sharp;
3+
using LibGit2Sharp.Tests.TestHelpers;
4+
using Xunit;
5+
6+
namespace LibGit2Sharp.Tests
7+
{
8+
public class GlobalSettingsFixture : BaseFixture
9+
{
10+
[Fact]
11+
public void CanGetMinimumCompiledInFeatures()
12+
{
13+
BuiltInFeatures features = GlobalSettings.Features();
14+
15+
Assert.True(features.HasFlag(BuiltInFeatures.Threads));
16+
Assert.True(features.HasFlag(BuiltInFeatures.Https));
17+
}
18+
}
19+
}

LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<Compile Include="BlameFixture.cs" />
6363
<Compile Include="ArchiveTarFixture.cs" />
6464
<Compile Include="CheckoutFixture.cs" />
65+
<Compile Include="GlobalSettingsFixture.cs" />
6566
<Compile Include="PatchStatsFixture.cs" />
6667
<Compile Include="RefSpecFixture.cs" />
6768
<Compile Include="EqualityFixture.cs" />
@@ -147,4 +148,4 @@
147148
<Target Name="AfterBuild">
148149
</Target>
149150
-->
150-
</Project>
151+
</Project>

LibGit2Sharp/BuiltInFeatures.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
3+
namespace LibGit2Sharp
4+
{
5+
/// <summary>
6+
/// Flags to identify libgit2 compiled features.
7+
/// </summary>
8+
[Flags]
9+
public enum BuiltInFeatures
10+
{
11+
/// <summary>
12+
/// No optional features are compiled into libgit2.
13+
/// </summary>
14+
None = 0,
15+
16+
/// <summary>
17+
/// Threading support is compiled into libgit2.
18+
/// </summary>
19+
Threads = (1 << 0),
20+
21+
/// <summary>
22+
/// Support for remotes over the HTTPS protocol is compiled into
23+
/// libgit2.
24+
/// </summary>
25+
Https = (1 << 1),
26+
27+
/// <summary>
28+
/// Support for remotes over the SSH protocol is compiled into
29+
/// libgit2.
30+
/// </summary>
31+
Ssh = (1 << 2),
32+
}
33+
}

LibGit2Sharp/Core/GitBuiltInFeatures.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.

LibGit2Sharp/Core/Proxy.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2754,15 +2754,9 @@ public static ObjectId git_treebuilder_write(RepositorySafeHandle repo, TreeBuil
27542754
/// <summary>
27552755
/// Returns the features with which libgit2 was compiled.
27562756
/// </summary>
2757-
public static string git_libgit2_features()
2757+
public static BuiltInFeatures git_libgit2_features()
27582758
{
2759-
GitBuiltInFeatures features;
2760-
2761-
int flags = NativeMethods.git_libgit2_features();
2762-
2763-
features = (GitBuiltInFeatures)Enum.ToObject(typeof(GitBuiltInFeatures), flags);
2764-
2765-
return features.ToString();
2759+
return (BuiltInFeatures)NativeMethods.git_libgit2_features();
27662760
}
27672761

27682762
#endregion

LibGit2Sharp/GlobalSettings.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using LibGit2Sharp.Core;
2+
3+
namespace LibGit2Sharp
4+
{
5+
/// <summary>
6+
/// Global settings for libgit2 and LibGit2Sharp.
7+
/// </summary>
8+
public static class GlobalSettings
9+
{
10+
/// <summary>
11+
/// Returns all the optional features that were compiled into
12+
/// libgit2.
13+
/// </summary>
14+
/// <returns>A <see cref="BuiltInFeatures"/> enumeration.</returns>
15+
public static BuiltInFeatures Features()
16+
{
17+
return Proxy.git_libgit2_features();
18+
}
19+
}
20+
}

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
<Compile Include="CommitSortStrategies.cs" />
8080
<Compile Include="CompareOptions.cs" />
8181
<Compile Include="ContentChangeStats.cs" />
82-
<Compile Include="Core\GitBuiltInFeatures.cs" />
82+
<Compile Include="BuiltInFeatures.cs" />
8383
<Compile Include="Core\GitCheckoutOptsWrapper.cs" />
8484
<Compile Include="Core\GitCredentialType.cs" />
8585
<Compile Include="Core\GitRevertOpts.cs" />
@@ -88,6 +88,7 @@
8888
<Compile Include="DefaultCredentials.cs" />
8989
<Compile Include="EmptyCommitException.cs" />
9090
<Compile Include="FetchOptions.cs" />
91+
<Compile Include="GlobalSettings.cs" />
9192
<Compile Include="MergeOptions.cs" />
9293
<Compile Include="MergeResult.cs" />
9394
<Compile Include="PatchStats.cs" />

LibGit2Sharp/Repository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,7 @@ private static string RetrieveVersion()
10671067

10681068
string libgit2Hash = ReadContentFromResource(assembly, "libgit2_hash.txt");
10691069
string libgit2sharpHash = ReadContentFromResource(assembly, "libgit2sharp_hash.txt");
1070+
string features = GlobalSettings.Features().ToString();
10701071

10711072
return string.Format(
10721073
CultureInfo.InvariantCulture,
@@ -1075,8 +1076,7 @@ private static string RetrieveVersion()
10751076
libgit2sharpHash.Substring(0, 7),
10761077
libgit2Hash.Substring(0, 7),
10771078
NativeMethods.ProcessorArchitecture,
1078-
Proxy.git_libgit2_features()
1079-
);
1079+
features);
10801080
}
10811081

10821082
private static string ReadContentFromResource(Assembly assembly, string partialResourceName)

0 commit comments

Comments
 (0)