8000 Delegate the enumerating of branches to libgit2 native methods · mm201/libgit2sharp@e8fe68a · GitHub
[go: up one dir, main page]

Skip to content

Commit e8fe68a

Browse files
committed
Delegate the enumerating of branches to libgit2 native methods
1 parent 6aac12a commit e8fe68a

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

LibGit2Sharp/BranchCollection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public Branch this[string name]
4545
/// <returns>An <see cref = "IEnumerator{T}" /> object that can be used to iterate through the collection.</returns>
4646
public IEnumerator<Branch> GetEnumerator()
4747
{
48-
return Libgit2UnsafeHelper.ListAllReferenceNames(repo.Handle, GitReferenceType.ListAll)
49-
.Where(LooksLikeABranchName)
48+
return Libgit2UnsafeHelper
49+
.ListAllBranchNames(repo.Handle, GitBranchType.GIT_BRANCH_LOCAL | GitBranchType.GIT_BRANCH_REMOTE)
5050
.Select(n => this[n])
5151
.GetEnumerator();
5252
}

LibGit2Sharp/Core/Libgit2UnsafeHelper.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ internal static unsafe class Libgit2UnsafeHelper
88
{
99
private static readonly Utf8Marshaler marshaler = (Utf8Marshaler)Utf8Marshaler.GetInstance(string.Empty);
1010

11+
public static IList<string> ListAllBranchNames(RepositorySafeHandle repo, GitBranchType types)
12+
{
13+
UnSafeNativeMethods.git_strarray strArray;
14+
int res = UnSafeNativeMethods.git_branch_list(out strArray, repo, types);
15+
Ensure.Success(res);
16+
17+
return BuildListOf(strArray);
18+
}
19+
1120
public static IList<string> ListAllReferenceNames(RepositorySafeHandle repo, GitReferenceType types)
1221
{
1322
UnSafeNativeMethods.git_strarray strArray;

LibGit2Sharp/Core/UnSafeNativeMethods.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ internal static unsafe class UnSafeNativeMethods
88
{
99
private const string libgit2 = "git2";
1010

11+
[DllImport(libgit2)]
12+
public static extern int git_branch_list(out git_strarray array, RepositorySafeHandle repo, GitBranchType flags);
13+
1114
[DllImport(libgit2)]
1215
public static extern int git_reference_list(out git_strarray array, RepositorySafeHandle repo, GitReferenceType flags);
1316

0 commit comments

Comments
 (0)
0