@@ -407,20 +407,28 @@ void test_fetchhead_nonetwork__create_when_refpecs_given(void)
407407 git_buf_free (& path );
408408}
409409
410- static int nrefs_found ;
411410static bool count_refs_called ;
411+ struct prefix_count {
412+ const char * prefix ;
413+ int count ;
414+ int expected ;
415+ };
412416
413417int count_refs (const char * ref_name , const char * remote_url , const git_oid * oid , unsigned int is_merge , void * payload )
414418{
415- const char * pfix = (const char * ) payload ;
419+ int i ;
420+ struct prefix_count * prefix_counts = (struct prefix_count * ) payload ;
416421
417422 GIT_UNUSED (remote_url );
418423 GIT_UNUSED (oid );
419424 GIT_UNUSED (is_merge );
420425
421426 count_refs_called = true;
422- if (!git__prefixcmp (ref_name , pfix ))
423- nrefs_found ++ ;
427+
428+ for (i = 0 ; prefix_counts [i ].prefix ; i ++ ) {
429+ if (!git__prefixcmp (ref_name , prefix_counts [i ].prefix ))
430+ prefix_counts [i ].count ++ ;
431+ }
424432
425433 return 0 ;
426434}
@@ -444,23 +452,20 @@ void test_fetchhead_nonetwork__create_with_multiple_refspecs(void)
444452 cl_git_pass (git_remote_fetch (remote , NULL , NULL , NULL ));
445453 cl_assert (git_path_exists (path .ptr ));
446454
447- count_refs_called = 0 ;
448- nrefs_found = 0 ;
449- cl_git_pass (git_repository_fetchhead_foreach (g_repo , count_refs , "refs/notes/" ));
450- cl_assert (count_refs_called );
451- cl_assert_equal_i (1 , nrefs_found );
452-
453- count_refs_called = 0 ;
454- nrefs_found = 0 ;
455- cl_git_pass (git_repository_fetchhead_foreach (g_repo , count_refs , "refs/heads/" ));
456- cl_assert (count_refs_called );
457- cl_assert_equal_i (12 , nrefs_found );
458-
459- count_refs_called = 0 ;
460- nrefs_found = 0 ;
461- cl_git_pass (git_repository_fetchhead_foreach (g_repo , count_refs , "refs/tags/" ));
462- cl_assert (count_refs_called );
463- cl_assert_equal_i (7 , nrefs_found );
455+ {
456+ int i ;
457+ struct prefix_count prefix_counts [] = {
458+ {"refs/notes/" , 0 , 1 },
459+ {"refs/heads/" , 0 , 12 },
460+ {"refs/tags/" , 0 , 7 },
461+ {NULL , 0 , 0 },
462+ };
463+
464+ cl_git_pass (git_repository_fetchhead_foreach (g_repo , count_refs , & prefix_counts ));
465+ cl_assert (count_refs_called );
466+ for (i = 0 ; prefix_counts [i ].prefix ; i ++ )
467+ cl_assert_equal_i (prefix_counts [i ].expected , prefix_counts [i ].count );
468+ }
464469
465470 git_remote_free (remote );
466471 git_buf_free (& path );
0 commit comments