From d643cea1e8a6d618b2eddfdbed086c7bdf208658 Mon Sep 17 00:00:00 2001 From: Alberto Cortés Date: Mon, 16 Nov 2015 03:20:01 +0100 Subject: Blame support for files This also includes a diff package and revlist package (needed by blame) Some extra packfiles (<1MB) are also included, to be used as fixtures in the tests. --- commit.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'commit.go') diff --git a/commit.go b/commit.go index 1440403..afd67ab 100644 --- a/commit.go +++ b/commit.go @@ -45,6 +45,11 @@ 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) +} + // Decode transform an core.Object into a Blob struct func (c *Commit) Decode(o core.Object) error { c.Hash = o.Hash() -- cgit From 48bf5bdeb9092ee5004014c0bf7a21f0e2fbf6fc Mon Sep 17 00:00:00 2001 From: Alberto Cortés Date: Fri, 27 Nov 2015 12:39:34 +0100 Subject: fix PR#7 comments --- commit.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'commit.go') diff --git a/commit.go b/commit.go index afd67ab..99dbf37 100644 --- a/commit.go +++ b/commit.go @@ -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 @@ -50,6 +54,18 @@ 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() -- cgit