aboutsummaryrefslogtreecommitdiffstats
path: root/references.go
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2017-04-20 11:35:41 +0200
committerGitHub <noreply@github.com>2017-04-20 11:35:41 +0200
commita41491f0e0ebdebdc793b1e42283c64e17d2d161 (patch)
treee07aac5391c14f8e119bd2aae961e8b41eea83ac /references.go
parentc68ac9efc98e11b88f143e0e083403624a794baf (diff)
parentbc4bbeebdee57685033c6d39b6eb1c858d06b25c (diff)
downloadgo-git-a41491f0e0ebdebdc793b1e42283c64e17d2d161.tar.gz
Merge pull request #319 from ajnavarro/fix/parents-with-path
references.go: fix Parents from commit iterator
Diffstat (limited to 'references.go')
-rw-r--r--references.go16
1 files changed, 9 insertions, 7 deletions
diff --git a/references.go b/references.go
index fc81103..ff2c1d3 100644
--- a/references.go
+++ b/references.go
@@ -76,8 +76,10 @@ func walkGraph(result *[]*object.Commit, seen *map[plumbing.Hash]struct{}, curre
// optimization: don't traverse branches that does not
// contain the path.
- parents := parentsContainingPath(path, current)
-
+ parents, err := parentsContainingPath(path, current)
+ if err != nil {
+ return err
+ }
switch len(parents) {
// if the path is not found in any of its parents, the path was
// created by this commit; we must add it to the revisions list and
@@ -110,18 +112,18 @@ func walkGraph(result *[]*object.Commit, seen *map[plumbing.Hash]struct{}, curre
return nil
}
-func parentsContainingPath(path string, c *object.Commit) []*object.Commit {
+func parentsContainingPath(path string, c *object.Commit) ([]*object.Commit, error) {
// TODO: benchmark this method making git.object.Commit.parent public instead of using
// an iterator
var result []*object.Commit
iter := c.Parents()
for {
parent, err := iter.Next()
+ if err == io.EOF {
+ return result, nil
+ }
if err != nil {
- if err == io.EOF {
- return result
- }
- panic("unreachable")
+ return nil, err
}
if _, err := parent.File(path); err == nil {
result = append(result, parent)