@@ -5,6 +5,7 @@ package git
55
66import (
77 "context"
8+ "fmt"
89
910 asymkey_model "code.gitea.io/gitea/models/asymkey"
1011 "code.gitea.io/gitea/models/db"
@@ -18,9 +19,6 @@ import (
1819
1920// ParseCommitsWithSignature checks if signaute of commits are corresponding to users gpg keys.
2021func ParseCommitsWithSignature (ctx context.Context , oldCommits []* user_model.UserCommit , repoTrustModel repo_model.TrustModelType , isOwnerMemberCollaborator func (* user_model.User ) (bool , error )) ([]* asymkey_model.SignCommit , error ) {
21- newCommits := make ([]* asymkey_model.SignCommit , 0 , len (oldCommits ))
22- keyMap := map [string ]bool {}
23-
2422 emails := make (container.Set [string ])
2523 for _ , c := range oldCommits {
2624 if c .Committer != nil {
@@ -33,6 +31,9 @@ func ParseCommitsWithSignature(ctx context.Context, oldCommits []*user_model.Use
3331 return nil , err
3432 }
3533
34+ newCommits := make ([]* asymkey_model.SignCommit , 0 , len (oldCommits ))
35+ keyMap := map [string ]bool {}
36+ cachedVerifications := make (map [string ]* asymkey_model.CommitVerification )
3637 for _ , c := range oldCommits {
3738 committer , ok := emailUsers [c .Committer .Email ]
3839 if ! ok && c .Committer != nil {
@@ -42,9 +43,19 @@ func ParseCommitsWithSignature(ctx context.Context, oldCommits []*user_model.Use
4243 }
4344 }
4445
46+ key := committer .Email
47+ if c .Signature != nil {
48+ key += fmt .Sprintf ("-%s" , c .Signature .Signature )
49+ }
50+ verification , ok := cachedVerifications [key ]
51+ if ! ok {
52+ verification = asymkey_service .ParseCommitWithSignatureCommitter (ctx , c .Commit , committer )
53+ cachedVerifications [key ] = verification
54+ }
55+
4556 signCommit := & asymkey_model.SignCommit {
4657 UserCommit : c ,
47- Verification : asymkey_service . ParseCommitWithSignatureCommitter ( ctx , c . Commit , committer ) ,
58+ Verification : verification ,
4859 }
4960
5061 _ = asymkey_model .CalculateTrustStatus (signCommit .Verification , repoTrustModel , isOwnerMemberCollaborator , & keyMap )
0 commit comments