diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-11-08 12:43:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-08 12:43:36 +0100 |
commit | e2791ac8605432dbdc5085fc165ace2c9e487f23 (patch) | |
tree | 70d50e19ed4652265175a09d0a5a0f12d2195cfe /plumbing/object/commit.go | |
parent | 8ab19f6f035b0f85cd70fa6e8ca9e93d02656cf7 (diff) | |
parent | 11162e11c830fec51517d86835a884a5547a4f16 (diff) | |
download | go-git-e2791ac8605432dbdc5085fc165ace2c9e487f23.tar.gz |
Merge pull request #613 from darkowlzz/482-commit-stats
Add Stats() to Commit
Diffstat (limited to 'plumbing/object/commit.go')
-rw-r--r-- | plumbing/object/commit.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/plumbing/object/commit.go b/plumbing/object/commit.go index b70128c..fad3dac 100644 --- a/plumbing/object/commit.go +++ b/plumbing/object/commit.go @@ -265,6 +265,32 @@ func (b *Commit) Encode(o plumbing.EncodedObject) error { return err } +// Stats shows the status of commit. +func (c *Commit) Stats() (FileStats, error) { + // Get the previous commit. + ci := c.Parents() + parentCommit, err := ci.Next() + if err != nil { + if err == io.EOF { + emptyNoder := treeNoder{} + parentCommit = &Commit{ + Hash: emptyNoder.hash, + // TreeHash: emptyNoder.parent.Hash, + s: c.s, + } + } else { + return nil, err + } + } + + patch, err := parentCommit.Patch(c) + if err != nil { + return nil, err + } + + return getFileStatsFromFilePatches(patch.FilePatches()), nil +} + func (c *Commit) String() string { return fmt.Sprintf( "%s %s\nAuthor: %s\nDate: %s\n\n%s\n", |