Release validation source bytes after checks
This commit is contained in:
@@ -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"})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user