@@ -531,8 +531,7 @@ void git_note_free(git_note *note)
531
531
532
532
static int process_entry_path (
533
533
const char * entry_path ,
534
- git_oid * annotated_object_id
535
- )
534
+ git_oid * annotated_object_id )
536
535
{
537
536
int error = -1 ;
538
537
size_t i = 0 , j = 0 , len ;
@@ -569,49 +568,41 @@ static int process_entry_path(
569
568
goto cleanup ;
570
569
}
571
570
572
- if ((error = git_oid_fromstr (annotated_object_id , buf .ptr )) < 0 )
573
- goto cleanup ;
571
+ error = git_oid_fromstr (annotated_object_id , buf .ptr );
574
572
575
573
cleanup :
576
574
git_buf_free (& buf );
577
575
return error ;
578
576
}
579
577
580
578
int git_note_foreach (
581
- git_repository * repo ,
582
- const char * notes_ref ,
583
- git_note_foreach_cb note_cb ,
584
- void * payload )
579
+ git_repository * repo ,
580
+ const char * notes_ref ,
581
+ git_note_foreach_cb note_cb ,
582
+ void * payload )
585
583
{
586
- int error ;
587
- git_note_iterator * iter = NULL ;
588
- git_tree * tree = NULL ;
589
- git_commit * commit = NULL ;
590
- git_oid annotated_object_id ;
591
- const git_index_entry * item ;
592
-
593
- if (!(error = retrieve_note_tree_and_commit (
594
- & tree , & commit , repo , & notes_ref )) &&
595
- !(error = git_iterator_for_tree (& iter , tree )))
596
- error = git_iterator_current (iter , & item );
597
-
598
- while (!error && item ) {
599
- error = process_entry_path (item -> path , & annotated_object_id );
584
+ int error ;
585
+ git_note_iterator * iter = NULL ;
586
+ git_oid note_id , annotated_id ;
600
587
601
- if (note_cb ( & item -> oid , & annotated_object_id , payload ) )
602
- error = GIT_EUSER ;
588
+ if (( error = git_note_iterator_new ( & iter , repo , notes_ref )) < 0 )
589
+ return error ;
603
590
604
- if (!error )
605
- error = git_iterator_advance (iter , & item );
606
- }
591
+ while (!(error = git_note_next (& note_id , & annotated_id , iter ))) {
592
+ if (note_cb (& note_id , & annotated_id , payload )) {
593
+ error = GIT_EUSER ;
594
+ break ;
595
+ }
596
+ }
607
597
608
- git_iterator_free (iter );
609
- git_tree_free (tree );
610
- git_commit_free (commit );
598
+ if (error == GIT_ITEROVER )
599
+ error = 0 ;
611
600
612
- return error ;
601
+ git_note_iterator_free (iter );
602
+ return error ;
613
603
}
614
604
605
+
615
606
void git_note_iterator_free (git_note_iterator * it )
616
607
{
617
608
if (it == NULL )
@@ -624,23 +615,20 @@ void git_note_iterator_free(git_note_iterator *it)
624
615
int git_note_iterator_new (
625
616
git_note_iterator * * it ,
626
617
git_repository * repo ,
627
- const char * notes_ref
628
- )
618
+ const char * notes_ref )
629
619
{
630
620
int error ;
631
621
git_commit * commit = NULL ;
632
622
git_tree * tree = NULL ;
633
623
634
624
error = retrieve_note_tree_and_commit (& tree , & commit , repo , & notes_ref );
635
- if (!error ) {
636
- * it = (git_note_iterator * )git__malloc (sizeof (git_iterator ));
637
- GITERR_CHECK_ALLOC (* it );
625
+ if (error < 0 )
626
+ goto cleanup ;
638
627
639
- error = git_iterator_for_tree (it , tree );
640
- if (error )
641
- git_iterator_free (* it );
642
- }
628
+ if ((error = git_iterator_for_tree (it , tree )) < 0 )
629
+ git_iterator_free (* it );
643
630
631
+ cleanup :
644
632
git_tree_free (tree );
645
633
git_commit_free (commit );
646
634
@@ -650,24 +638,24 @@ int git_note_iterator_new(
650
638
int git_note_next (
651
639
git_oid * note_id ,
652
640
git_oid * annotated_id ,
653
- git_note_iterator * it
654
- )
641
+ git_note_iterator * it )
655
642
{
656
643
int error ;
657
644
const git_index_entry * item ;
658
645
659
- error = git_iterator_current (it , & item );
660
- if (!error && item ) {
661
- git_oid_cpy (note_id , & item -> oid );
646
+ if (error = git_iterator_current (it , & item ) < 0 )
647
+ goto exit ;
662
648
649
+ if (item != NULL ) {
650
+ git_oid_cpy (note_id , & item -> oid );
663
651
error = process_entry_path (item -> path , annotated_id );
664
652
665
- if (! error )
653
+ if (error >= 0 )
666
654
error = git_iterator_advance (it , NULL );
667
- }
668
-
669
- if (!error && !item )
655
+ } else {
670
656
error = GIT_ITEROVER ;
657
+ }
671
658
659
+ exit :
672
660
return error ;
673
661
}
0 commit comments