diff options
author | nulltoken <emeric.fermas@gmail.com> | 2012-07-23 15:54:15 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2012-07-23 19:25:17 +0400 |
commit | e99d81993d32855176fd1fef36c14a937ac5db27 (patch) | |
tree | 67b4d956e6fbd997c7592a1c391722b8542660d2 /LibGit2Sharp/BranchCollection.cs | |
parent | fa5e0fbc1f97b32fd98b82f1a5f2d37e3b831e66 (diff) |
Upgrade libgit2 binaries to 14e1bc1
Fix #193
Diffstat (limited to 'LibGit2Sharp/BranchCollection.cs')
-rw-r--r-- | LibGit2Sharp/BranchCollection.cs | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/LibGit2Sharp/BranchCollection.cs b/LibGit2Sharp/BranchCollection.cs index 636ca0dc..4146c023 100644 --- a/LibGit2Sharp/BranchCollection.cs +++ b/LibGit2Sharp/BranchCollection.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using LibGit2Sharp.Core; +using LibGit2Sharp.Core.Handles; namespace LibGit2Sharp { @@ -88,13 +89,39 @@ namespace LibGit2Sharp /// <returns>An <see cref = "IEnumerator{T}" /> object that can be used to iterate through the collection.</returns> public virtual IEnumerator<Branch> GetEnumerator() { - return Libgit2UnsafeHelper - .ListAllBranchNames(repo.Handle, GitBranchType.GIT_BRANCH_LOCAL | GitBranchType.GIT_BRANCH_REMOTE) + return new BranchNameEnumerable(repo.Handle, GitBranchType.GIT_BRANCH_LOCAL | GitBranchType.GIT_BRANCH_REMOTE) .Select(n => this[n]) .OrderBy(b => b.CanonicalName, StringComparer.Ordinal) .GetEnumerator(); } + private class BranchNameEnumerable : IEnumerable<string> + { + private readonly List<string> list = new List<string>(); + + public BranchNameEnumerable(RepositorySafeHandle handle, GitBranchType gitBranchType) + { + Ensure.Success(NativeMethods.git_branch_foreach(handle, gitBranchType, Callback, IntPtr.Zero)); + } + + private int Callback(IntPtr branchName, GitBranchType branchType, IntPtr payload) + { + string name = Utf8Marshaler.FromNative(branchName); + list.Add(name); + return 0; + } + + public IEnumerator<string> GetEnumerator() + { + return list.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + /// <summary> /// Returns an enumerator that iterates through the collection. /// </summary> |