Release validation source bytes after checks

This commit is contained in:
2026-10-09 01:33:21 +00:00
parent a3e993d95a
commit 182da397e3
8 changed files with 169 additions and 32 deletions

View File

@@ -199,6 +199,7 @@ func checkWorkspaceFiles(tree *CandidateTree) error {
func checkGoFormat(ctx context.Context, tree *CandidateTree) error {
var findings []Finding
formattedByObjectID := make(map[string]bool)
for _, entry := range tree.Entries() {
if entry.Type != "blob" || (entry.Mode != "100644" && entry.Mode != "100755") || !strings.HasSuffix(entry.Path, ".go") {
continue
@@ -206,6 +207,12 @@ func checkGoFormat(ctx context.Context, tree *CandidateTree) error {
if err := ctx.Err(); err != nil {
return &Failure{Check: GoFormat, Cause: err}
}
if formatted, ok := formattedByObjectID[entry.ObjectID]; ok {
if !formatted {
findings = append(findings, Finding{Path: entry.Path, Message: "file is not gofmt-formatted"})
}
continue
}
contents, err := tree.ReadFile(ctx, entry.Path)
if err != nil {
return &Failure{
@@ -228,7 +235,11 @@ func checkGoFormat(ctx context.Context, tree *CandidateTree) error {
Cause: fmt.Errorf("format committed Go file %q: %w", entry.Path, err),
}
}
if !bytes.Equal(contents, formatted) {
isFormatted := bytes.Equal(contents, formatted)
formattedByObjectID[entry.ObjectID] = isFormatted
contents = nil
formatted = nil
if !isFormatted {
findings = append(findings, Finding{Path: entry.Path, Message: "file is not gofmt-formatted"})
}
}