@@ -267,7 +267,7 @@ type gitRepository struct {
267267 // through all the refs each time
268268 deletionProposedCache map [BranchName ]bool
269269
270- mutex sync.Mutex
270+ mutex sync.RWMutex
271271
272272 // caBundle to use for TLS communication towards git
273273 caBundle []byte
@@ -298,13 +298,17 @@ func (r *gitRepository) Close(context.Context) error {
298298func (r * gitRepository ) Version (ctx context.Context ) (string , error ) {
299299 _ , span := tracer .Start (ctx , "gitRepository::Version" , trace .WithAttributes ())
300300 defer span .End ()
301- r .mutex .Lock ()
302- defer r .mutex .Unlock ()
303301
304- if err := r .fetchRemoteRepositoryWithRetry (ctx ); err != nil {
302+ r .mutex .Lock ()
303+ err := r .fetchRemoteRepositoryWithRetry (ctx )
304+ r .mutex .Unlock ()
305+ if err != nil {
305306 return "" , err
306307 }
307308
309+ r .mutex .RLock ()
310+ defer r .mutex .RUnlock ()
311+
308312 refs , err := r .repo .References ()
309313 if err != nil {
310314 return "" , err
@@ -444,10 +448,13 @@ func (r *gitRepository) listPackageRevisions(ctx context.Context, filter reposit
444448}
445449
446450func (r * gitRepository ) CreatePackageRevisionDraft (ctx context.Context , obj * porchapi.PackageRevision ) (repository.PackageRevisionDraft , error ) {
447- _ , span := tracer .Start (ctx , "gitRepository::CreatePackageRevision " , trace .WithAttributes ())
451+ _ , span := tracer .Start (ctx , "gitRepository::CreatePackageRevisionDraft " , trace .WithAttributes ())
448452 defer span .End ()
449- r .mutex .Lock ()
450- defer r .mutex .Unlock ()
453+
454+ _ , mutexSpan := tracer .Start (ctx , "gitRepository::CreatePackageRevisionDraft::acquire_mutex" )
455+ r .mutex .RLock ()
456+ mutexSpan .End ()
457+ defer r .mutex .RUnlock ()
451458
452459 var base plumbing.Hash
453460 refName := r .branch .RefInLocal ()
@@ -696,8 +703,8 @@ func (r *gitRepository) fetchRemoteRepositoryWithRetry(ctx context.Context) erro
696703func (r * gitRepository ) GetPackageRevision (ctx context.Context , version , path string ) (repository.PackageRevision , kptfilev1.GitLock , error ) {
697704 ctx , span := tracer .Start (ctx , "gitRepository::GetPackageRevision" , trace .WithAttributes ())
698705 defer span .End ()
699- r .mutex .Lock ()
700- defer r .mutex .Unlock ()
706+ r .mutex .RLock ()
707+ defer r .mutex .RUnlock ()
701708
702709 var hash plumbing.Hash
703710
@@ -1049,8 +1056,6 @@ func (r *gitRepository) getAuthMethod(ctx context.Context, forceRefresh bool) (t
10491056}
10501057
10511058func (r * gitRepository ) GetRepo () (string , error ) {
1052- r .mutex .Lock ()
1053- defer r .mutex .Unlock ()
10541059
10551060 origin , err := r .repo .Remote ("origin" )
10561061 if err != nil {
@@ -1341,8 +1346,8 @@ func visitCommitsCollectErrors(iterator object.CommitIter, callback commitCallba
13411346}
13421347
13431348func (r * gitRepository ) GetResources (hash plumbing.Hash ) (map [string ]string , error ) {
1344- r .mutex .Lock ()
1345- defer r .mutex .Unlock ()
1349+ r .mutex .RLock ()
1350+ defer r .mutex .RUnlock ()
13461351
13471352 resources := map [string ]string {}
13481353
@@ -1407,8 +1412,8 @@ type commitCallback func(*object.Commit) error
14071412func (r * gitRepository ) GetLifecycle (ctx context.Context , pkgRev * gitPackageRevision ) porchapi.PackageRevisionLifecycle {
14081413 _ , span := tracer .Start (ctx , "gitRepository::GetLifecycle" , trace .WithAttributes ())
14091414 defer span .End ()
1410- r .mutex .Lock ()
1411- defer r .mutex .Unlock ()
1415+ r .mutex .RLock ()
1416+ defer r .mutex .RUnlock ()
14121417
14131418 return r .getLifecycle (pkgRev )
14141419}
@@ -1487,7 +1492,10 @@ func (r *gitRepository) UpdateLifecycle(ctx context.Context, pkgRev *gitPackageR
14871492func (r * gitRepository ) UpdateDraftResources (ctx context.Context , draft * gitPackageRevisionDraft , new * porchapi.PackageRevisionResources , change * porchapi.Task ) error {
14881493 ctx , span := tracer .Start (ctx , "gitRepository::UpdateResources" , trace .WithAttributes ())
14891494 defer span .End ()
1495+
1496+ _ , mutexSpan := tracer .Start (ctx , "gitRepository::UpdateDraftResources::acquire_mutex" )
14901497 r .mutex .Lock ()
1498+ mutexSpan .End ()
14911499 defer r .mutex .Unlock ()
14921500
14931501 ch , err := newCommitHelper (r .repo , r .userInfoProvider , draft .commit , draft .Key ().PkgKey .ToFullPathname (), plumbing .ZeroHash )
@@ -1548,7 +1556,9 @@ func (r *gitRepository) ClosePackageRevisionDraft(ctx context.Context, prd repos
15481556 ctx , span := tracer .Start (ctx , "gitRepository::ClosePackageRevisionDraft" , trace .WithAttributes ())
15491557 defer span .End ()
15501558
1559+ _ , mutexSpan := tracer .Start (ctx , "gitRepository::ClosePackageRevisionDraft::acquire_mutex" )
15511560 r .mutex .Lock ()
1561+ mutexSpan .End ()
15521562 defer r .mutex .Unlock ()
15531563
15541564 d := prd .(* gitPackageRevisionDraft )
0 commit comments