aboutsummaryrefslogtreecommitdiffstats
path: root/commit.go
diff options
context:
space:
mode:
authorAlberto Cortés <alberto@sourced.tech>2016-01-21 03:00:41 +0100
committerAlberto Cortés <alberto@sourced.tech>2016-01-21 03:00:41 +0100
commit07e4c4368921f73048578f22a14a1c671ec3ba46 (patch)
tree3aad7ae994a71880f8f1e900dcb60ea15d702d04 /commit.go
parent37cc5cf842c3c0fb989bcf7525cc8f826d96b295 (diff)
downloadgo-git-07e4c4368921f73048578f22a14a1c671ec3ba46.tar.gz
Fix commit.File() gorutine leak
Commit.File() was leaking a goroutine because it was looping over an iterator without closing its channel. Now commit.File() calls the new Tree.File() method that searches the file in the repository by trasversing the dir tree instead of using the tree.Files() iterator. This not only prevent the goroutine leak, but also speeds up file searching.
Diffstat (limited to 'commit.go')
-rw-r--r--commit.go11
1 files changed, 1 insertions, 10 deletions
diff --git a/commit.go b/commit.go
index 1dd09ab..ea6419f 100644
--- a/commit.go
+++ b/commit.go
@@ -3,7 +3,6 @@ package git
import (
"bufio"
"bytes"
- "errors"
"fmt"
"io"
"sort"
@@ -11,9 +10,6 @@ import (
"gopkg.in/src-d/go-git.v2/core"
)
-// New errors defined by this package.
-var ErrFileNotFound = errors.New("file not found")
-
type Hash core.Hash
// Commit points to a single tree, marking it as what the project looked like
@@ -59,12 +55,7 @@ func (c *Commit) NumParents() int {
// nil error if the file exists. If the file does not exists, it returns
// a nil file and the ErrFileNotFound error.
func (c *Commit) File(path string) (file *File, err error) {
- for file := range c.Tree().Files() {
- if file.Name == path {
- return file, nil
- }
- }
- return nil, ErrFileNotFound
+ return c.Tree().File(path)
}
// Decode transform an core.Object into a Blob struct