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:
authornulltoken <emeric.fermas@gmail.com>2012-05-15 14:54:00 +0400
committernulltoken <emeric.fermas@gmail.com>2012-05-20 13:00:12 +0400
commite8fe68a894d62fe6a6f790a2f2ce2dc0e1270366 (patch)
tree97e39795b8e6ca265983b7c6d625877f69be8281
parent6aac12a992d37cb02e9bfd0153e61cd33838c341 (diff)
Delegate the enumerating of branches to libgit2 native methods
-rw-r--r--LibGit2Sharp/BranchCollection.cs4
-rw-r--r--LibGit2Sharp/Core/Libgit2UnsafeHelper.cs9
-rw-r--r--LibGit2Sharp/Core/UnSafeNativeMethods.cs3
3 files changed, 14 insertions, 2 deletions
diff --git a/LibGit2Sharp/BranchCollection.cs b/LibGit2Sharp/BranchCollection.cs
index 6ffc0707..f3248d9f 100644
--- a/LibGit2Sharp/BranchCollection.cs
+++ b/LibGit2Sharp/BranchCollection.cs
@@ -45,8 +45,8 @@ namespace LibGit2Sharp
/// <returns>An <see cref = "IEnumerator{T}" /> object that can be used to iterate through the collection.</returns>
public IEnumerator<Branch> GetEnumerator()
{
- return Libgit2UnsafeHelper.ListAllReferenceNames(repo.Handle, GitReferenceType.ListAll)
- .Where(LooksLikeABranchName)
+ return Libgit2UnsafeHelper
+ .ListAllBranchNames(repo.Handle, GitBranchType.GIT_BRANCH_LOCAL | GitBranchType.GIT_BRANCH_REMOTE)
.Select(n => this[n])
.GetEnumerator();
}
diff --git a/LibGit2Sharp/Core/Libgit2UnsafeHelper.cs b/LibGit2Sharp/Core/Libgit2UnsafeHelper.cs
index 0099e9c6..e87cb921 100644
--- a/LibGit2Sharp/Core/Libgit2UnsafeHelper.cs
+++ b/LibGit2Sharp/Core/Libgit2UnsafeHelper.cs
@@ -8,6 +8,15 @@ namespace LibGit2Sharp.Core
{
private static readonly Utf8Marshaler marshaler = (Utf8Marshaler)Utf8Marshaler.GetInstance(string.Empty);
+ public static IList<string> ListAllBranchNames(RepositorySafeHandle repo, GitBranchType types)
+ {
+ UnSafeNativeMethods.git_strarray strArray;
+ int res = UnSafeNativeMethods.git_branch_list(out strArray, repo, types);
+ Ensure.Success(res);
+
+ return BuildListOf(strArray);
+ }
+
public static IList<string> ListAllReferenceNames(RepositorySafeHandle repo, GitReferenceType types)
{
UnSafeNativeMethods.git_strarray strArray;
diff --git a/LibGit2Sharp/Core/UnSafeNativeMethods.cs b/LibGit2Sharp/Core/UnSafeNativeMethods.cs
index fe1fef2d..fe35e2f9 100644
--- a/LibGit2Sharp/Core/UnSafeNativeMethods.cs
+++ b/LibGit2Sharp/Core/UnSafeNativeMethods.cs
@@ -9,6 +9,9 @@ namespace LibGit2Sharp.Core
private const string libgit2 = "git2";
[DllImport(libgit2)]
+ public static extern int git_branch_list(out git_strarray array, RepositorySafeHandle repo, GitBranchType flags);
+
+ [DllImport(libgit2)]
public static extern int git_reference_list(out git_strarray array, RepositorySafeHandle repo, GitReferenceType flags);
[DllImport(libgit2)]