Skip to content

Added libgit2 features to Repository.Version #694

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
Apr 25, 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
8 changes: 8 additions & 0 deletions LibGit2Sharp.Tests/RepositoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ public void CanCreateStandardRepo()
}
}

[Fact]
public void CanRetrieveValidVersionString()
{
string versionInfo = Repository.Version;

Assert.NotNull(versionInfo);
Copy link
Member

Choose a reason for hiding this comment

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

Too late for this pass, but I wonder if we should at least check versionInfo against a regex?

Copy link
Member

Choose a reason for hiding this comment

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

@dahlbyk Could you log an up-for-grab issue with what you've got in mind?

Copy link
Member

Choose a reason for hiding this comment

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

Done: #696

Copy link
Member

Choose a reason for hiding this comment

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

😍

}

[Fact]
public void CanCreateStandardRepoAndSpecifyAFolderWhichWillContainTheNewlyCreatedGitDirectory()
{
Expand Down
18 changes: 18 additions & 0 deletions LibGit2Sharp/Core/GitBuiltInFeatures.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LibGit2Sharp.Core
{
/// <summary>
/// Flags to indentify libgit compiled features.
/// </summary>
[Flags]
internal enum GitBuiltInFeatures
Copy link
Member

Choose a reason for hiding this comment

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

Missing [Flags] here maybe?

{
Threads = (1 << 0),
Https = (1 << 1),
Ssh = (1 << 2),
}
}
3 changes: 3 additions & 0 deletions LibGit2Sharp/Core/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,9 @@ internal static extern int git_diff_find_similar(
[DllImport(libgit2)]
internal static extern IntPtr git_diff_get_delta(DiffSafeHandle diff, UIntPtr idx);

[DllImport(libgit2)]
internal static extern int git_libgit2_features();

[DllImport(libgit2)]
internal static extern int git_graph_ahead_behind(out UIntPtr ahead, out UIntPtr behind, RepositorySafeHandle repo, ref GitOid one, ref GitOid two);

Expand Down
18 changes: 18 additions & 0 deletions LibGit2Sharp/Core/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2721,6 +2721,24 @@ public static ObjectId git_treebuilder_write(RepositorySafeHandle repo, TreeBuil

#endregion

#region git_libgit2_

/// <summary>
/// Returns the features with which libgit2 was compiled.
/// </summary>
public static string git_libgit2_features()
{
GitBuiltInFeatures features;

int flags = NativeMethods.git_libgit2_features();

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

return features.ToString();
}

#endregion

private static ICollection<TResult> git_foreach<T, TResult>(
Func<T, TResult> resultSelector,
Func<Func<T, IntPtr, int>, int> iterator,
Expand Down
1 change: 1 addition & 0 deletions LibGit2Sharp/LibGit2Sharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<Compile Include="CommitSortStrategies.cs" />
<Compile Include="CompareOptions.cs" />
<Compile Include="ContentChangeStats.cs" />
<Compile Include="Core\GitBuiltInFeatures.cs" />
<Compile Include="Core\GitCredentialType.cs" />
<Compile Include="Core\Handles\PatchSafeHandle.cs" />
<Compile Include="Core\IntPtrExtensions.cs" />
Expand Down
7 changes: 4 additions & 3 deletions LibGit2Sharp/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ internal T RegisterForCleanup<T>(T disposable) where T : IDisposable
/// 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>Major.Minor.Patch-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64 - capabilities)</para>
/// </para>
/// </summary>
public static string Version
Expand All @@ -1030,11 +1030,12 @@ private static string RetrieveVersion()

return string.Format(
CultureInfo.InvariantCulture,
"{0}-{1}-{2} ({3})",
"{0}-{1}-{2} ({3} - {4})",
version.ToString(3),
libgit2sharpHash.Substring(0, 7),
libgit2Hash.Substring(0, 7),
NativeMethods.ProcessorArchitecture
NativeMethods.ProcessorArchitecture,
Proxy.git_libgit2_features()
);
}

Expand Down