aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/gitattributes/attributes.go
diff options
context:
space:
mode:
authorPeter Kurfer <peter@icb4dc0.de>2024-02-02 13:55:42 +0100
committerPeter Kurfer <peter@icb4dc0.de>2024-02-05 10:28:25 +0100
commit798d9942c3625d88146d5e1c026afe6192acc98d (patch)
treec29b740c9e2b9fce207c8997b4bb271d9e591c5a /plumbing/format/gitattributes/attributes.go
parent03a57f8f5179a990083e8b9c2c9e40854ae402ea (diff)
downloadgo-git-798d9942c3625d88146d5e1c026afe6192acc98d.tar.gz
plumbing: format/gitattributes, close file in ReadAttributesFile
Fixes #1017
Diffstat (limited to 'plumbing/format/gitattributes/attributes.go')
-rw-r--r--plumbing/format/gitattributes/attributes.go14
1 files changed, 8 insertions, 6 deletions
diff --git a/plumbing/format/gitattributes/attributes.go b/plumbing/format/gitattributes/attributes.go
index d36ec1b..026d221 100644
--- a/plumbing/format/gitattributes/attributes.go
+++ b/plumbing/format/gitattributes/attributes.go
@@ -1,6 +1,7 @@
package gitattributes
import (
+ "bufio"
"errors"
"io"
"strings"
@@ -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
}
@@ -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
}