8000 plumbing: format/gitattributes, close file in ReadAttributesFile by prskr · Pull Request #1018 · go-git/go-git · GitHub
[go: up one dir, main page]

Skip to content

plumbing: format/gitattributes, close file in ReadAttributesFile #1018

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

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions plumbing/format/gitattributes/attributes.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gitattributes

import (
"bufio"
"errors"
"io"
"strings"
Expand Down Expand Up @@ -88,13 +89,10 @@ func (a attribute) String() string {

// ReadAttributes reads patterns and attributes from the gitattributes format.
func ReadAttributes(r io.Reader, domain []string, allowMacro bool) (attributes []MatchAttribute, err error) {
data, err := io.ReadAll(r)
if err != nil {
return nil, err
}
scanner := bufio.NewScanner(r)

for _, line := range strings.Split(string(data), eol) {
attribute, err := ParseAttributesLine(line, domain, allowMacro)
for scanner.Scan() {
attribute, err := ParseAttributesLine(scanner.Text(), domain, allowMacro)
if err != nil {
return attributes, err
}
Expand All @@ -105,6 +103,10 @@ func ReadAttributes(r io.Reader, domain []string, allowMacro bool) (attributes [
attributes = append(attributes, attribute)
}

if err := scanner.Err(); err != nil {
return attributes, err
}

return attributes, nil
}

Expand Down
3 changes: 3 additions & 0 deletions plumbing/format/gitattributes/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"os"

"github.com/go-git/go-billy/v5"

"github.com/go-git/go-git/v5/plumbing/format/config"
gioutil "github.com/go-git/go-git/v5/utils/ioutil"
)
Expand All @@ -26,6 +27,8 @@ func ReadAttributesFile(fs billy.Filesystem, path []string, attributesFile strin
return nil, err
}

defer gioutil.CheckClose(f, &err)

return ReadAttributes(f, path, allowMacro)
}

3F98 Expand Down
0