@@ -400,19 +400,29 @@ struct for_each_ref_filter {
400400 void * cb_data ;
401401};
402402
403- int read_ref_full (const char * refname , int resolve_flags , struct object_id * oid , int * flags )
403+ int refs_read_ref_full (struct ref_store * refs , const char * refname ,
404+ int resolve_flags , struct object_id * oid , int * flags )
404405{
405- struct ref_store * refs = get_main_ref_store (the_repository );
406-
407406 if (refs_resolve_ref_unsafe (refs , refname , resolve_flags ,
408407 oid , flags ))
409408 return 0 ;
410409 return -1 ;
411410}
412411
412+ int read_ref_full (const char * refname , int resolve_flags , struct object_id * oid , int * flags )
413+ {
414+ return refs_read_ref_full (get_main_ref_store (the_repository ), refname ,
415+ resolve_flags , oid , flags );
416+ }
417+
418+ int refs_read_ref (struct ref_store * refs , const char * refname , struct object_id * oid )
419+ {
420+ return refs_read_ref_full (refs , refname , RESOLVE_REF_READING , oid , NULL );
421+ }
422+
413423int read_ref (const char * refname , struct object_id * oid )
414424{
415- return read_ref_full ( refname , RESOLVE_REF_READING , oid , NULL );
425+ return refs_read_ref ( get_main_ref_store ( the_repository ), refname , oid );
416426}
417427
418428int refs_ref_exists (struct ref_store * refs , const char * refname )
@@ -542,21 +552,27 @@ int for_each_remote_ref(each_ref_fn fn, void *cb_data)
542552 return refs_for_each_remote_ref (get_main_ref_store (the_repository ), fn , cb_data );
543553}
544554
545- int head_ref_namespaced ( each_ref_fn fn , void * cb_data )
555+ int refs_head_ref_namespaced ( struct ref_store * refs , each_ref_fn fn , void * cb_data )
546556{
547557 struct strbuf buf = STRBUF_INIT ;
548558 int ret = 0 ;
549559 struct object_id oid ;
550560 int flag ;
551561
552562 strbuf_addf (& buf , "%sHEAD" , get_git_namespace ());
553- if (!read_ref_full ( buf .buf , RESOLVE_REF_READING , & oid , & flag ))
563+ if (!refs_read_ref_full ( refs , buf .buf , RESOLVE_REF_READING , & oid , & flag ))
554564 ret = fn (buf .buf , & oid , flag , cb_data );
555565 strbuf_release (& buf );
556566
557567 return ret ;
558568}
559569
570+ int head_ref_namespaced (each_ref_fn fn , void * cb_data )
571+ {
572+ return refs_head_ref_namespaced (get_main_ref_store (the_repository ),
573+ fn , cb_data );
574+ }
575+
560576void normalize_glob_ref (struct string_list_item * item , const char * prefix ,
561577 const char * pattern )
562578{
@@ -583,8 +599,8 @@ void normalize_glob_ref(struct string_list_item *item, const char *prefix,
583599 strbuf_release (& normalized_pattern );
584600}
585601
586- int for_each_glob_ref_in ( each_ref_fn fn , const char * pattern ,
587- const char * prefix , void * cb_data )
602+ int refs_for_each_glob_ref_in ( struct ref_store * refs , each_ref_fn fn ,
603+ const char * pattern , const char * prefix , void * cb_data )
588604{
589605 struct strbuf real_pattern = STRBUF_INIT ;
590606 struct for_each_ref_filter filter ;
@@ -607,15 +623,29 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
607623 filter .prefix = prefix ;
608624 filter .fn = fn ;
609625 filter .cb_data = cb_data ;
610- ret = for_each_ref ( for_each_filter_refs , & filter );
626+ ret = refs_for_each_ref ( refs , for_each_filter_refs , & filter );
611627
612628 strbuf_release (& real_pattern );
613629 return ret ;
614630}
615631
632+ int for_each_glob_ref_in (each_ref_fn fn , const char * pattern ,
633+ const char * prefix , void * cb_data )
634+ {
635+ return refs_for_each_glob_ref_in (get_main_ref_store (the_repository ),
636+ fn , pattern , prefix , cb_data );
637+ }
638+
639+ int refs_for_each_glob_ref (struct ref_store * refs , each_ref_fn fn ,
640+ const char * pattern , void * cb_data )
641+ {
642+ return refs_for_each_glob_ref_in (refs , fn , pattern , NULL , cb_data );
643+ }
644+
616645int for_each_glob_ref (each_ref_fn fn , const char * pattern , void * cb_data )
617646{
618- return for_each_glob_ref_in (fn , pattern , NULL , cb_data );
647+ return refs_for_each_glob_ref (get_main_ref_store (the_repository ),
648+ fn , pattern , cb_data );
619649}
620650
621651const char * prettify_refname (const char * name )
@@ -1733,18 +1763,25 @@ int for_each_replace_ref(struct repository *r, each_repo_ref_fn fn, void *cb_dat
17331763 DO_FOR_EACH_INCLUDE_BROKEN , cb_data );
17341764}
17351765
1736- int for_each_namespaced_ref (const char * * exclude_patterns ,
1737- each_ref_fn fn , void * cb_data )
1766+ int refs_for_each_namespaced_ref (struct ref_store * refs ,
1767+ const char * * exclude_patterns ,
1768+ each_ref_fn fn , void * cb_data )
17381769{
17391770 struct strbuf buf = STRBUF_INIT ;
17401771 int ret ;
17411772 strbuf_addf (& buf , "%srefs/" , get_git_namespace ());
1742- ret = do_for_each_ref (get_main_ref_store (the_repository ),
1743- buf .buf , exclude_patterns , fn , 0 , 0 , cb_data );
1773+ ret = do_for_each_ref (refs , buf .buf , exclude_patterns , fn , 0 , 0 , cb_data );
17441774 strbuf_release (& buf );
17451775 return ret ;
17461776}
17471777
1778+ int for_each_namespaced_ref (const char * * exclude_patterns ,
1779+ each_ref_fn fn , void * cb_data )
1780+ {
1781+ return refs_for_each_namespaced_ref (get_main_ref_store (the_repository ),
1782+ exclude_patterns , fn , cb_data );
1783+ }
1784+
17481785int refs_for_each_rawref (struct ref_store * refs , each_ref_fn fn , void * cb_data )
17491786{
17501787 return do_for_each_ref (refs , "" , NULL , fn , 0 ,
0 commit comments