Skip to content

Introduce GlobalSettings.Features() #717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions LibGit2Sharp.Tests/GlobalSettingsFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using LibGit2Sharp;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;

namespace LibGit2Sharp.Tests
{
public class GlobalSettingsFixture : BaseFixture
{
[Fact]
public void CanGetMinimumCompiledInFeatures()
{
BuiltInFeatures features = GlobalSettings.Features();

Assert.True(features.HasFlag(BuiltInFeatures.Threads));
Assert.True(features.HasFlag(BuiltInFeatures.Https));
}
}
}
3 changes: 2 additions & 1 deletion LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<Compile Include="BlameFixture.cs" />
<Compile Include="ArchiveTarFixture.cs" />
<Compile Include="CheckoutFixture.cs" />
<Compile Include="GlobalSettingsFixture.cs" />
<Compile Include="PatchStatsFixture.cs" />
<Compile Include="RefSpecFixture.cs" />
<Compile Include="EqualityFixture.cs" />
Expand Down Expand Up @@ -147,4 +148,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
33 changes: 33 additions & 0 deletions LibGit2Sharp/BuiltInFeatures.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;

namespace LibGit2Sharp
{
/// <summary>
/// Flags to identify libgit2 compiled features.
/// </summary>
[Flags]
public enum BuiltInFeatures
{
/// <summary>
/// No optional features are compiled into libgit2.
/// </summary>
None = 0,

/// <summary>
/// Threading support is compiled into libgit2.
/// </summary>
Threads = (1 << 0),

/// <summary>
/// Support for remotes over the HTTPS protocol is compiled into
/// libgit2.
/// </summary>
Https = (1 << 1),

/// <summary>
/// Support for remotes over the SSH protocol is compiled into
/// libgit2.
/// </summary>
Ssh = (1 << 2),
}
}
18 changes: 0 additions & 18 deletions LibGit2Sharp/Core/GitBuiltInFeatures.cs

This file was deleted.

10 changes: 2 additions & 8 deletions LibGit2Sharp/Core/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2754,15 +2754,9 @@ public static ObjectId git_treebuilder_write(RepositorySafeHandle repo, TreeBuil
/// <summary>
/// Returns the features with which libgit2 was compiled.
/// </summary>
public static string git_libgit2_features()
public static BuiltInFeatures git_libgit2_features()
{
GitBuiltInFeatures features;

int flags = NativeMethods.git_libgit2_features();

features = (GitBuiltInFeatures)Enum.ToObject(typeof(GitBuiltInFeatures), flags);

return features.ToString();
return (BuiltInFeatures)NativeMethods.git_libgit2_features();
}

#endregion
Expand Down
20 changes: 20 additions & 0 deletions LibGit2Sharp/GlobalSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using LibGit2Sharp.Core;

namespace LibGit2Sharp
{
/// <summary>
/// Global settings for libgit2 and LibGit2Sharp.
/// </summary>
public static class GlobalSettings
{
/// <summary>
/// Returns all the optional features that were compiled into
/// libgit2.
/// </summary>
/// <returns>A <see cref="BuiltInFeatures"/> enumeration.</returns>
public static BuiltInFeatures Features()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a small test exercising this and ensuring that at least Threads and Https are supported?

This should help us quickly ensure that each PR upgrading the libgit2 binaries embeds dlls that have been compiled with the correct flags.

{
return Proxy.git_libgit2_features();
}
}
}
3 changes: 2 additions & 1 deletion LibGit2Sharp/LibGit2Sharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<Compile Include="CommitSortStrategies.cs" />
<Compile Include="CompareOptions.cs" />
<Compile Include="ContentChangeStats.cs" />
<Compile Include="Core\GitBuiltInFeatures.cs" />
<Compile Include="BuiltInFeatures.cs" />
<Compile Include="Core\GitCheckoutOptsWrapper.cs" />
<Compile Include="Core\GitCredentialType.cs" />
<Compile Include="Core\GitRevertOpts.cs" />
Expand All @@ -88,6 +88,7 @@
<Compile Include="DefaultCredentials.cs" />
<Compile Include="EmptyCommitException.cs" />
<Compile Include="FetchOptions.cs" />
<Compile Include="GlobalSettings.cs" />
<Compile Include="MergeOptions.cs" />
<Compile Include="MergeResult.cs" />
<Compile Include="PatchStats.cs" />
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,7 @@ private static string RetrieveVersion()

string libgit2Hash = ReadContentFromResource(assembly, "libgit2_hash.txt");
string libgit2sharpHash = ReadContentFromResource(assembly, "libgit2sharp_hash.txt");
string features = GlobalSettings.Features().ToString();

return string.Format(
CultureInfo.InvariantCulture,
Expand All @@ -1075,8 +1076,7 @@ private static string RetrieveVersion()
libgit2sharpHash.Substring(0, 7),
libgit2Hash.Substring(0, 7),
NativeMethods.ProcessorArchitecture,
Proxy.git_libgit2_features()
);
features);
}

private static string ReadContentFromResource(Assembly assembly, string partialResourceName)
Expand Down