@@ -209,22 +209,33 @@ public static unsafe void git_branch_delete(GitReferenceHandle reference)
209209Ensure . ZeroResult ( res ) ;
210210}
211211
212- public static unsafe IEnumerable < Branch > git_branch_iterator ( Repository repo , GitBranchType branchType )
213- {
214- return git_iterator ( ( out BranchIteratorSafeHandle iter_out ) =>
215- NativeMethods . git_branch_iterator_new ( out iter_out , repo . Handle , branchType ) ,
216- ( BranchIteratorSafeHandle iter , out IntPtr refPtr , out int res ) =>
217- {
218- GitBranchType type_out ;
219- res = NativeMethods . git_branch_next ( out refPtr , out type_out , iter ) ;
220- return new { BranchType = type_out } ;
221- } ,
222- ( handle , payload ) =>
223- {
224- git_reference * refPtr = ( git_reference * ) handle . ToPointer ( ) ;
225- var reference = Reference . BuildFromPtr < Reference > ( refPtr , repo ) ;
226- return new Branch ( repo , reference , reference . CanonicalName ) ;
227- } ) ;
212+ public static IEnumerable < Branch > git_branch_iterator ( Repository repo , GitBranchType branchType )
213+ {
214+ BranchIteratorSafeHandle iter ;
215+ var res = NativeMethods . git_branch_iterator_new ( out iter , repo . Handle , branchType ) ;
216+ Ensure . ZeroResult ( res ) ;
217+
218+ using ( iter )
219+ {
220+ while ( true )
221+ {
222+ IntPtr refPtr = IntPtr . Zero ;
223+ GitBranchType _branchType ;
224+ res = NativeMethods . git_branch_next ( out refPtr , out _branchType , iter ) ;
225+ if ( res == ( int ) GitErrorCode . IterOver )
226+ {
227+ yield break ;
228+ }
229+ Ensure . ZeroResult ( res ) ;
230+
231+ Reference reference ;
232+ using ( var refHandle = new GitReferenceHandle ( refPtr ) )
233+ {
234+ reference = Reference . BuildFromPtr < Reference > ( refHandle , repo ) ;
235+ }
236+ yield return new Branch ( repo , reference , reference . CanonicalName ) ;
237+ }
238+ }
228239}
229240
230241public static void git_branch_iterator_free ( IntPtr iter )
@@ -583,22 +594,28 @@ public static ICollection<TResult> git_config_foreach<TResult>(
583594return git_foreach ( resultSelector , c=> NativeMethods . git_config_foreach ( config , ( e , p ) => c ( e , p ) , IntPtr . Zero ) ) ;
584595}
585596
586- public static unsafe IEnumerable < ConfigurationEntry < string > > git_config_iterator_glob (
597+ public static IEnumerable < ConfigurationEntry < string > > git_config_iterator_glob (
587598ConfigurationSafeHandle config ,
588- string regexp ,
589- Func < IntPtr , ConfigurationEntry < string > > resultSelector )
590- {
591- return git_iterator ( ( out ConfigurationIteratorSafeHandle iter ) =>
592- NativeMethods . git_config_iterator_glob_new ( out iter , config , regexp ) ,
593- ( ConfigurationIteratorSafeHandle iter , out IntPtr handle , out int res ) =>
594- {
595- handle = IntPtr . Zero ;
596- IntPtr entry ;
597- res = NativeMethods . git_config_next ( out entry , iter ) ;
598- return new { EntryPtr = entry } ;
599- } ,
600- ( handle , payload ) =>
601- resultSelector ( payload . EntryPtr ) ) ;
599+ string regexp )
600+ {
601+ ConfigurationIteratorSafeHandle iter ;
602+ var res = NativeMethods . git_config_iterator_glob_new ( out iter , config , regexp ) ;
603+ Ensure . ZeroResult ( res ) ;
604+ using ( iter )
605+ {
606+ while ( true )
607+ {
608+ IntPtr entry ;
609+ res = NativeMethods . git_config_next ( out entry , iter ) ;
610+ if ( res == ( int ) GitErrorCode . IterOver )
611+ {
612+ yield break ;
613+ }
614+ Ensure . ZeroResult ( res ) ;
615+
616+ yield return Configuration . BuildConfigEntry ( entry ) ;
617+ }
618+ }
602619}
603620
604621public static void git_config_iterator_free ( IntPtr iter )
@@ -1809,11 +1826,6 @@ public static ICollection<TResult> git_reference_foreach_glob<TResult>(
18091826return git_foreach ( resultSelector , c=> NativeMethods . git_reference_foreach_glob ( repo , glob , ( x , p ) => c ( x , p ) , IntPtr . Zero ) ) ;
18101827}
18111828
1812- public static void git_reference_free ( IntPtr reference )
1813- {
1814- NativeMethods . git_reference_free ( reference ) ;
1815- }
1816-
18171829public static bool git_reference_is_valid_name ( string refname )
18181830{
18191831int res = NativeMethods . git_reference_is_valid_name ( refname ) ;
@@ -3380,62 +3392,6 @@ private static ICollection<TResult> git_foreach<T1, T2, T3, T4, TResult>(
33803392return result ;
33813393}
33823394
3383- private delegate int IteratorNew < THandle > ( out THandle iter ) ;
3384-
3385- private delegate TPayload IteratorNext < in TIterator , THandle , out TPayload > ( TIterator iter , out THandle next , out int res ) ;
3386-
3387- private static THandle git_iterator_new < THandle > ( IteratorNew < THandle > newFunc )
3388- where THandle : SafeHandleBase
3389- {
3390- THandle iter ;
3391- Ensure . ZeroResult ( newFunc ( out iter ) ) ;
3392- return iter ;
3393- }
3394-
3395- private static IEnumerable < TResult > git_iterator_next < TIterator , TPayload , TResult > (
3396- TIterator iter ,
3397- IteratorNext < TIterator , IntPtr , TPayload > nextFunc ,
3398- Func < IntPtr , TPayload , TResult > resultSelector )
3399- {
3400- while ( true )
3401- {
3402- var next = IntPtr . Zero ;
3403- try
3404- {
3405- int res ;
3406- var payload = nextFunc ( iter , out next , out res ) ;
3407-
3408- if ( res == ( int ) GitErrorCode . IterOver )
3409- {
3410- yield break ;
3411- }
3412-
3413- Ensure . ZeroResult ( res ) ;
3414- yield return resultSelector ( next , payload ) ;
3415- }
3416- finally
3417- {
3418- NativeMethods . git_reference_free ( next ) ;
3419- }
3420- }
3421- }
3422-
3423- private static IEnumerable < TResult > git_iterator < TIterator , TPayload , TResult > (
3424- IteratorNew < TIterator > newFunc ,
3425- IteratorNext < TIterator , IntPtr , TPayload > nextFunc ,
3426- Func < IntPtr , TPayload , TResult > resultSelector
3427- )
3428- where TIterator : SafeHandleBase
3429- {
3430- using ( var iter = git_iterator_new ( newFunc ) )
3431- {
3432- foreach ( var next in git_iterator_next ( iter , nextFunc , resultSelector ) )
3433- {
3434- yield return next ;
3435- }
3436- }
3437- }
3438-
34393395private static bool RepositoryStateChecker ( RepositorySafeHandle repo , Func < RepositorySafeHandle , int > checker )
34403396{
34413397int res = checker ( repo ) ;