Skip to content

Commit 798d994

Browse files
committed
plumbing: format/gitattributes, close file in ReadAttributesFile
Fixes #1017
1 parent 03a57f8 commit 798d994

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

plumbing/format/gitattributes/attributes.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gitattributes
22

33
import (
4+
"bufio"
45
"errors"
56
"io"
67
"strings"
@@ -88,13 +89,10 @@ func (a attribute) String() string {
8889

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

96-
for _, line := range strings.Split(string(data), eol) {
97-
attribute, err := ParseAttributesLine(line, domain, allowMacro)
94+
for scanner.Scan() {
95+
attribute, err := ParseAttributesLine(scanner.Text(), domain, allowMacro)
9896
if err != nil {
9997
return attributes, err
10098
}
@@ -105,6 +103,10 @@ func ReadAttributes(r io.Reader, domain []string, allowMacro bool) (attributes [
105103
attributes = append(attributes, attribute)
106104
}
107105

106+
if err := scanner.Err(); err != nil {
107+
return attributes, err
108+
}
109+
108110
return attributes, nil
109111
}
110112

plumbing/format/gitattributes/dir.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"os"
55

66
"github.com/go-git/go-billy/v5"
7+
78
"github.com/go-git/go-git/v5/plumbing/format/config"
89
gioutil "github.com/go-git/go-git/v5/utils/ioutil"
910
)
@@ -26,6 +27,8 @@ func ReadAttributesFile(fs billy.Filesystem, path []string, attributesFile strin
2627
return nil, err
2728
}
2829

30+
defer gioutil.CheckClose(f, &err)
31+
2932
return ReadAttributes(f, path, allowMacro)
3033
}
3134

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy