Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMetalrom <romain.magny@gmail.com>2013-01-18 18:48:10 +0400
committernulltoken <emeric.fermas@gmail.com>2013-01-18 23:07:05 +0400
commit4e73ab988de6f6442eb5906416d6a6526530cb8a (patch)
treeae8716240ca7c27decd63f56d9a9d5cb533653da
parent5d7887e71b3ad9567e66c6269928688202050a3c (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.cs4
-rw-r--r--LibGit2Sharp/Core/NativeMethods.cs3
-rw-r--r--LibGit2Sharp/Core/Proxy.cs22
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)