diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2015-12-11 23:58:00 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2015-12-11 23:58:00 +0100 |
commit | c22c181f70e0afb294513315e9975b9f3f4c1d39 (patch) | |
tree | 8377ae4645c58454d0f2a61631a4a81d2d7d5faf /commit.go | |
parent | 5c8fff7e9e614d9f463d964699539fe71509ba39 (diff) | |
parent | c347e978b52212b5aa968a14d81c8fff47ab24d7 (diff) | |
download | go-git-c22c181f70e0afb294513315e9975b9f3f4c1d39.tar.gz |
Merge pull request #7 from alcortesm/blame
Blame
Diffstat (limited to 'commit.go')
-rw-r--r-- | commit.go | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -3,12 +3,16 @@ package git import ( "bufio" "bytes" + "errors" "fmt" "io" "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 @@ -45,6 +49,23 @@ func (c *Commit) Parents() *CommitIter { return i } +// NumParents returns the number of parents in a commit. +func (c *Commit) NumParents() int { + return len(c.parents) +} + +// File returns the file with the specified "path" in the commit and a +// 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 +} + // Decode transform an core.Object into a Blob struct func (c *Commit) Decode(o core.Object) error { c.Hash = o.Hash() |