aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format
diff options
context:
space:
mode:
authorPaulo Gomes <pjbgf@linux.com>2024-02-05 10:08:37 +0000
committerGitHub <noreply@github.com>2024-02-05 10:08:37 +0000
commitd9b0a0dd2f4f03e82bcd7f7dad1f7b5eb42713c6 (patch)
treebb7e56c4cdd8748ec3dd12d6ec4cfb08482e46e4 /plumbing/format
parent730ae4d7856f3fad3dea52467458abc03dc48cd6 (diff)
parent798d9942c3625d88146d5e1c026afe6192acc98d (diff)
downloadgo-git-d9b0a0dd2f4f03e82bcd7f7dad1f7b5eb42713c6.tar.gz
Merge pull request #1018 from prskr/1017-readattributes-does-not-close-file
plumbing: format/gitattributes, close file in ReadAttributesFile
Diffstat (limited to 'plumbing/format')
-rw-r--r--plumbing/format/gitattributes/attributes.go14
-rw-r--r--plumbing/format/gitattributes/dir.go3
2 files changed, 11 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
}
diff --git a/plumbing/format/gitattributes/dir.go b/plumbing/format/gitattributes/dir.go
index 123fe25..d3b0dbe 100644
--- a/plumbing/format/gitattributes/dir.go
+++ b/plumbing/format/gitattributes/dir.go
@@ -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"
)
@@ -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)
}