-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Cache commit verification #33616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache commit verification #33616
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ package git | |
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| asymkey_model "code.gitea.io/gitea/models/asymkey" | ||
| "code.gitea.io/gitea/models/db" | ||
|
|
@@ -18,9 +19,6 @@ import ( | |
|
|
||
| // ParseCommitsWithSignature checks if signaute of commits are corresponding to users gpg keys. | ||
| func ParseCommitsWithSignature(ctx context.Context, oldCommits []*user_model.UserCommit, repoTrustModel repo_model.TrustModelType, isOwnerMemberCollaborator func(*user_model.User) (bool, error)) ([]*asymkey_model.SignCommit, error) { | ||
| newCommits := make([]*asymkey_model.SignCommit, 0, len(oldCommits)) | ||
| keyMap := map[string]bool{} | ||
|
|
||
| emails := make(container.Set[string]) | ||
| for _, c := range oldCommits { | ||
| if c.Committer != nil { | ||
|
|
@@ -33,6 +31,9 @@ func ParseCommitsWithSignature(ctx context.Context, oldCommits []*user_model.Use | |
| return nil, err | ||
| } | ||
|
|
||
| newCommits := make([]*asymkey_model.SignCommit, 0, len(oldCommits)) | ||
| keyMap := map[string]bool{} | ||
| cachedVerifications := make(map[string]*asymkey_model.CommitVerification) | ||
| for _, c := range oldCommits { | ||
| committer, ok := emailUsers[c.Committer.Email] | ||
| if !ok && c.Committer != nil { | ||
|
|
@@ -42,9 +43,19 @@ func ParseCommitsWithSignature(ctx context.Context, oldCommits []*user_model.Use | |
| } | ||
| } | ||
|
|
||
| key := committer.Email | ||
| if c.Signature != nil { | ||
| key += fmt.Sprintf("-%s", c.Signature.Signature) | ||
| } | ||
| verification, ok := cachedVerifications[key] | ||
| if !ok { | ||
| verification = asymkey_service.ParseCommitWithSignatureCommitter(ctx, c.Commit, committer) | ||
| cachedVerifications[key] = verification | ||
| } | ||
|
Comment on lines
+46
to
+54
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How could it be right? Each commit's
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Then this pointer is reused for different commits? |
||
|
|
||
| signCommit := &asymkey_model.SignCommit{ | ||
| UserCommit: c, | ||
| Verification: asymkey_service.ParseCommitWithSignatureCommitter(ctx, c.Commit, committer), | ||
| Verification: verification, | ||
| } | ||
|
|
||
| _ = asymkey_model.CalculateTrustStatus(signCommit.Verification, repoTrustModel, isOwnerMemberCollaborator, &keyMap) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why it would happen?