diff options
author | Metalrom <romain.magny@gmail.com> | 2013-01-18 18:48:10 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2013-01-18 23:07:05 +0400 |
commit | 4e73ab988de6f6442eb5906416d6a6526530cb8a (patch) | |
tree | ae8716240ca7c27decd63f56d9a9d5cb533653da | |
parent | 5d7887e71b3ad9567e66c6269928688202050a3c (diff) |
Bind git_graph_ahead_behind native method
Replace current implementation of Branch.AheadBy and Branch.BehindBy with git_graph_ahead_behind call
-rw-r--r-- | LibGit2Sharp/Branch.cs | 4 | ||||
-rw-r--r-- | LibGit2Sharp/Core/NativeMethods.cs | 3 | ||||
-rw-r--r-- | LibGit2Sharp/Core/Proxy.cs | 22 |
3 files changed, 27 insertions, 2 deletions
diff --git a/LibGit2Sharp/Branch.cs b/LibGit2Sharp/Branch.cs index 932dcbab..8744b2ff 100644 --- a/LibGit2Sharp/Branch.cs +++ b/LibGit2Sharp/Branch.cs @@ -120,7 +120,7 @@ namespace LibGit2Sharp /// </summary> public virtual int? AheadBy { - get { return ExistsPathToTrackedBranch() ? repo.Commits.QueryBy(new Filter { Since = Tip, Until = TrackedBranch }).Count() : (int?)null; } + get { return ExistsPathToTrackedBranch() ? Proxy.git_graph_ahead_behind(repo.Handle, TrackedBranch.Tip.Id, Tip.Id).Item1 : (int?)null; } } /// <summary> @@ -132,7 +132,7 @@ namespace LibGit2Sharp /// </summary> public virtual int? BehindBy { - get { return ExistsPathToTrackedBranch() ? repo.Commits.QueryBy(new Filter { Since = TrackedBranch, Until = Tip }).Count() : (int?)null; } + get { return ExistsPathToTrackedBranch() ? Proxy.git_graph_ahead_behind(repo.Handle, TrackedBranch.Tip.Id, Tip.Id).Item2 : (int?)null; } } /// <summary> diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index 491cc47f..31b2a763 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -392,6 +392,9 @@ namespace LibGit2Sharp.Core IntPtr payload); [DllImport(libgit2)] + internal static extern int git_graph_ahead_behind(out UIntPtr ahead, out UIntPtr behind, RepositorySafeHandle repo, ref GitOid one, ref GitOid two); + + [DllImport(libgit2)] internal static extern int git_index_add_from_workdir( IndexSafeHandle index, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath path); diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs index fd0ee3f4..e704a856 100644 --- a/LibGit2Sharp/Core/Proxy.cs +++ b/LibGit2Sharp/Core/Proxy.cs @@ -5,6 +5,7 @@ using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Threading; +using LibGit2Sharp.Core.Compat; using LibGit2Sharp.Core.Handles; using LibGit2Sharp.Handlers; @@ -614,6 +615,27 @@ namespace LibGit2Sharp.Core #endregion + #region git_graph_ + + public static Tuple<int, int> git_graph_ahead_behind(RepositorySafeHandle repo, ObjectId firstId, ObjectId secondId) + { + GitOid oid1 = firstId.Oid; + GitOid oid2 = secondId.Oid; + + using (ThreadAffinity()) + { + UIntPtr ahead; + UIntPtr behind; + + int res = NativeMethods.git_graph_ahead_behind(out ahead, out behind, repo, ref oid1, ref oid2); + + Ensure.Success(res); + + return new Tuple<int, int>((int)ahead, (int)behind); + } + } + #endregion + #region git_index_ public static void git_index_add(IndexSafeHandle index, GitIndexEntry entry) |